#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};
}
