#include <metal_stdlib>

using namespace metal;
uint3 tint_first_trailing_bit(uint3 v) {
  uint3 x = uint3(v);
  uint3 const b16 = select(uint3(16u), uint3(0u), bool3((x & uint3(65535u))));
  x = (x >> b16);
  uint3 const b8 = select(uint3(8u), uint3(0u), bool3((x & uint3(255u))));
  x = (x >> b8);
  uint3 const b4 = select(uint3(4u), uint3(0u), bool3((x & uint3(15u))));
  x = (x >> b4);
  uint3 const b2 = select(uint3(2u), uint3(0u), bool3((x & uint3(3u))));
  x = (x >> b2);
  uint3 const b1 = select(uint3(1u), uint3(0u), bool3((x & uint3(1u))));
  uint3 const is_zero = select(uint3(0u), uint3(4294967295u), (x == uint3(0u)));
  return uint3((((((b16 | b8) | b4) | b2) | b1) | is_zero));
}

uint3 firstTrailingBit_cb51ce() {
  uint3 arg_0 = uint3(1u);
  uint3 res = tint_first_trailing_bit(arg_0);
  return res;
}

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

kernel void compute_main(device packed_uint3* tint_symbol_2 [[buffer(0)]]) {
  *(tint_symbol_2) = packed_uint3(firstTrailingBit_cb51ce());
  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 = firstTrailingBit_cb51ce();
  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;
}

