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

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