#include <metal_stdlib>

using namespace metal;
int countTrailingZeros_42fed6() {
  int arg_0 = 1;
  int res = ctz(arg_0);
  return res;
}

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

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

struct VertexOutput {
  float4 pos;
  int prevent_dce;
};

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

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

