#include <metal_stdlib>

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

uint firstLeadingBit_f0779d() {
  uint arg_0 = 1u;
  uint res = tint_first_leading_bit(arg_0);
  return res;
}

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

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

struct VertexOutput {
  float4 pos;
  uint prevent_dce;
};

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

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

