#include <metal_stdlib>

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

int2 firstTrailingBit_50c072() {
  int2 arg_0 = int2(1);
  int2 res = tint_first_trailing_bit(arg_0);
  return res;
}

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

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

struct VertexOutput {
  float4 pos;
  int2 prevent_dce;
};

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

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

