#include <metal_stdlib>
using namespace metal;
struct tint_module_vars_struct {
  device int2* prevent_dce;
};
struct VertexOutput {
  float4 pos;
  int2 prevent_dce;
};
struct vertex_main_outputs {
  float4 VertexOutput_pos [[position]];
  int2 VertexOutput_prevent_dce [[user(locn0)]] [[flat]];
};

int2 firstLeadingBit_a622c2() {
  int2 arg_0 = int2(1);
  uint2 const v = as_type<uint2>(arg_0);
  uint2 const v_1 = select(~(v), v, (v < uint2(2147483648u)));
  uint2 const v_2 = select(uint2(16u), uint2(0u), ((v_1 & uint2(4294901760u)) == uint2(0u)));
  uint2 const v_3 = select(uint2(8u), uint2(0u), (((v_1 >> v_2) & uint2(65280u)) == uint2(0u)));
  uint2 const v_4 = select(uint2(4u), uint2(0u), ((((v_1 >> v_2) >> v_3) & uint2(240u)) == uint2(0u)));
  uint2 const v_5 = select(uint2(2u), uint2(0u), (((((v_1 >> v_2) >> v_3) >> v_4) & uint2(12u)) == uint2(0u)));
  int2 res = as_type<int2>(select((v_2 | (v_3 | (v_4 | (v_5 | select(uint2(1u), uint2(0u), ((((((v_1 >> v_2) >> v_3) >> v_4) >> v_5) & uint2(2u)) == uint2(0u))))))), uint2(4294967295u), (((((v_1 >> v_2) >> v_3) >> v_4) >> v_5) == uint2(0u))));
  return res;
}
fragment void fragment_main(device int2* 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_a622c2();
}
kernel void compute_main(device int2* 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_a622c2();
}
VertexOutput vertex_main_inner() {
  VertexOutput out = {};
  out.pos = float4(0.0f);
  out.prevent_dce = firstLeadingBit_a622c2();
  return out;
}
vertex vertex_main_outputs vertex_main() {
  VertexOutput const v_6 = vertex_main_inner();
  return vertex_main_outputs{.VertexOutput_pos=v_6.pos, .VertexOutput_prevent_dce=v_6.prevent_dce};
}
