#include <metal_stdlib>

using namespace metal;
int3 tint_first_trailing_bit(int3 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 int3((((((b16 | b8) | b4) | b2) | b1) | is_zero));
}

int3 firstTrailingBit_7496d6() {
  int3 arg_0 = int3(1);
  int3 res = tint_first_trailing_bit(arg_0);
  return res;
}

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

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

struct VertexOutput {
  float4 pos;
  int3 prevent_dce;
};

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

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

