#include <metal_stdlib>

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

int4 firstTrailingBit_86551b() {
  int4 arg_0 = int4(1);
  int4 res = tint_first_trailing_bit(arg_0);
  return res;
}

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

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

struct VertexOutput {
  float4 pos;
  int4 prevent_dce;
};

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

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

