#include <metal_stdlib>

using namespace metal;
uint2 tint_first_leading_bit(uint2 v) {
  uint2 x = v;
  uint2 const b16 = select(uint2(0u), uint2(16u), bool2((x & uint2(4294901760u))));
  x = (x >> b16);
  uint2 const b8 = select(uint2(0u), uint2(8u), bool2((x & uint2(65280u))));
  x = (x >> b8);
  uint2 const b4 = select(uint2(0u), uint2(4u), bool2((x & uint2(240u))));
  x = (x >> b4);
  uint2 const b2 = select(uint2(0u), uint2(2u), bool2((x & uint2(12u))));
  x = (x >> b2);
  uint2 const b1 = select(uint2(0u), uint2(1u), bool2((x & uint2(2u))));
  uint2 const is_zero = select(uint2(0u), uint2(4294967295u), (x == uint2(0u)));
  return uint2((((((b16 | b8) | b4) | b2) | b1) | is_zero));
}

uint2 firstLeadingBit_6fe804() {
  uint2 arg_0 = uint2(1u);
  uint2 res = tint_first_leading_bit(arg_0);
  return res;
}

fragment void fragment_main(device uint2* tint_symbol_1 [[buffer(0)]]) {
  *(tint_symbol_1) = firstLeadingBit_6fe804();
  return;
}

kernel void compute_main(device uint2* tint_symbol_2 [[buffer(0)]]) {
  *(tint_symbol_2) = firstLeadingBit_6fe804();
  return;
}

struct VertexOutput {
  float4 pos;
  uint2 prevent_dce;
};

struct tint_symbol {
  uint2 prevent_dce [[user(locn0)]] [[flat]];
  float4 pos [[position]];
};

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

vertex tint_symbol vertex_main() {
  VertexOutput const inner_result = vertex_main_inner();
  tint_symbol wrapper_result = {};
  wrapper_result.pos = inner_result.pos;
  wrapper_result.prevent_dce = inner_result.prevent_dce;
  return wrapper_result;
}

