#include <metal_stdlib>
using namespace metal;

struct tint_module_vars_struct {
  device int3* prevent_dce;
};

struct VertexOutput {
  float4 pos;
  int3 prevent_dce;
};

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

int3 firstLeadingBit_35053e() {
  int3 arg_0 = int3(1);
  uint3 const v = as_type<uint3>(arg_0);
  uint3 const v_1 = select(~(v), v, (v < uint3(2147483648u)));
  uint3 const v_2 = select(uint3(16u), uint3(0u), ((v_1 & uint3(4294901760u)) == uint3(0u)));
  uint3 const v_3 = select(uint3(8u), uint3(0u), (((v_1 >> v_2) & uint3(65280u)) == uint3(0u)));
  uint3 const v_4 = select(uint3(4u), uint3(0u), ((((v_1 >> v_2) >> v_3) & uint3(240u)) == uint3(0u)));
  uint3 const v_5 = select(uint3(2u), uint3(0u), (((((v_1 >> v_2) >> v_3) >> v_4) & uint3(12u)) == uint3(0u)));
  int3 res = as_type<int3>(select((v_2 | (v_3 | (v_4 | (v_5 | select(uint3(1u), uint3(0u), ((((((v_1 >> v_2) >> v_3) >> v_4) >> v_5) & uint3(2u)) == uint3(0u))))))), uint3(4294967295u), (((((v_1 >> v_2) >> v_3) >> v_4) >> v_5) == uint3(0u))));
  return res;
}

fragment void fragment_main(device int3* 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_35053e();
}

kernel void compute_main(device int3* 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_35053e();
}

VertexOutput vertex_main_inner() {
  VertexOutput out = {};
  out.pos = float4(0.0f);
  out.prevent_dce = firstLeadingBit_35053e();
  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};
}
