#include <metal_stdlib>
using namespace metal;

struct tint_module_vars_struct {
  device uint* prevent_dce;
};

struct VertexOutput {
  float4 pos;
  uint prevent_dce;
};

struct vertex_main_outputs {
  float4 VertexOutput_pos [[position]];
  uint VertexOutput_prevent_dce [[user(locn0)]] [[flat]];
};

uint firstLeadingBit_f0779d() {
  uint arg_0 = 1u;
  uint const v = arg_0;
  uint res = select((select(16u, 0u, ((v & 4294901760u) == 0u)) | (select(8u, 0u, (((v >> select(16u, 0u, ((v & 4294901760u) == 0u))) & 65280u) == 0u)) | (select(4u, 0u, ((((v >> select(16u, 0u, ((v & 4294901760u) == 0u))) >> select(8u, 0u, (((v >> select(16u, 0u, ((v & 4294901760u) == 0u))) & 65280u) == 0u))) & 240u) == 0u)) | (select(2u, 0u, (((((v >> select(16u, 0u, ((v & 4294901760u) == 0u))) >> select(8u, 0u, (((v >> select(16u, 0u, ((v & 4294901760u) == 0u))) & 65280u) == 0u))) >> select(4u, 0u, ((((v >> select(16u, 0u, ((v & 4294901760u) == 0u))) >> select(8u, 0u, (((v >> select(16u, 0u, ((v & 4294901760u) == 0u))) & 65280u) == 0u))) & 240u) == 0u))) & 12u) == 0u)) | select(1u, 0u, ((((((v >> select(16u, 0u, ((v & 4294901760u) == 0u))) >> select(8u, 0u, (((v >> select(16u, 0u, ((v & 4294901760u) == 0u))) & 65280u) == 0u))) >> select(4u, 0u, ((((v >> select(16u, 0u, ((v & 4294901760u) == 0u))) >> select(8u, 0u, (((v >> select(16u, 0u, ((v & 4294901760u) == 0u))) & 65280u) == 0u))) & 240u) == 0u))) >> select(2u, 0u, (((((v >> select(16u, 0u, ((v & 4294901760u) == 0u))) >> select(8u, 0u, (((v >> select(16u, 0u, ((v & 4294901760u) == 0u))) & 65280u) == 0u))) >> select(4u, 0u, ((((v >> select(16u, 0u, ((v & 4294901760u) == 0u))) >> select(8u, 0u, (((v >> select(16u, 0u, ((v & 4294901760u) == 0u))) & 65280u) == 0u))) & 240u) == 0u))) & 12u) == 0u))) & 2u) == 0u)))))), 4294967295u, (((((v >> select(16u, 0u, ((v & 4294901760u) == 0u))) >> select(8u, 0u, (((v >> select(16u, 0u, ((v & 4294901760u) == 0u))) & 65280u) == 0u))) >> select(4u, 0u, ((((v >> select(16u, 0u, ((v & 4294901760u) == 0u))) >> select(8u, 0u, (((v >> select(16u, 0u, ((v & 4294901760u) == 0u))) & 65280u) == 0u))) & 240u) == 0u))) >> select(2u, 0u, (((((v >> select(16u, 0u, ((v & 4294901760u) == 0u))) >> select(8u, 0u, (((v >> select(16u, 0u, ((v & 4294901760u) == 0u))) & 65280u) == 0u))) >> select(4u, 0u, ((((v >> select(16u, 0u, ((v & 4294901760u) == 0u))) >> select(8u, 0u, (((v >> select(16u, 0u, ((v & 4294901760u) == 0u))) & 65280u) == 0u))) & 240u) == 0u))) & 12u) == 0u))) == 0u));
  return res;
}

fragment void fragment_main(device uint* prevent_dce [[buffer(0)]]) {
  tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.prevent_dce=prevent_dce};
  (*tint_module_vars.prevent_dce) = firstLeadingBit_f0779d();
}

kernel void compute_main(device uint* prevent_dce [[buffer(0)]]) {
  tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.prevent_dce=prevent_dce};
  (*tint_module_vars.prevent_dce) = firstLeadingBit_f0779d();
}

VertexOutput vertex_main_inner() {
  VertexOutput out = {};
  out.pos = float4(0.0f);
  out.prevent_dce = firstLeadingBit_f0779d();
  return out;
}

vertex vertex_main_outputs vertex_main() {
  VertexOutput const v_1 = vertex_main_inner();
  vertex_main_outputs tint_wrapper_result = {};
  tint_wrapper_result.VertexOutput_pos = v_1.pos;
  tint_wrapper_result.VertexOutput_prevent_dce = v_1.prevent_dce;
  return tint_wrapper_result;
}
