#include <metal_stdlib>

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

uint firstTrailingBit_47d475() {
  uint arg_0 = 1u;
  uint res = tint_first_trailing_bit(arg_0);
  return res;
}

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

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

struct VertexOutput {
  float4 pos;
  uint prevent_dce;
};

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

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

