#include <metal_stdlib>

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

uint3 firstLeadingBit_3fd7d0() {
  uint3 arg_0 = uint3(1u);
  uint3 res = tint_first_leading_bit(arg_0);
  return res;
}

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

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

struct VertexOutput {
  float4 pos;
  uint3 prevent_dce;
};

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

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

