#include <metal_stdlib>
using namespace metal;

struct tint_module_vars_struct {
  device int* prevent_dce;
};

struct VertexOutput {
  float4 pos;
  int prevent_dce;
};

struct vertex_main_outputs {
  float4 VertexOutput_pos [[position]];
  int VertexOutput_prevent_dce [[user(locn0)]] [[flat]];
};

int firstTrailingBit_3a2acc() {
  int arg_0 = 1;
  uint const v = as_type<uint>(arg_0);
  int res = as_type<int>(select((select(0u, 16u, ((v & 65535u) == 0u)) | (select(0u, 8u, (((v >> select(0u, 16u, ((v & 65535u) == 0u))) & 255u) == 0u)) | (select(0u, 4u, ((((v >> select(0u, 16u, ((v & 65535u) == 0u))) >> select(0u, 8u, (((v >> select(0u, 16u, ((v & 65535u) == 0u))) & 255u) == 0u))) & 15u) == 0u)) | (select(0u, 2u, (((((v >> select(0u, 16u, ((v & 65535u) == 0u))) >> select(0u, 8u, (((v >> select(0u, 16u, ((v & 65535u) == 0u))) & 255u) == 0u))) >> select(0u, 4u, ((((v >> select(0u, 16u, ((v & 65535u) == 0u))) >> select(0u, 8u, (((v >> select(0u, 16u, ((v & 65535u) == 0u))) & 255u) == 0u))) & 15u) == 0u))) & 3u) == 0u)) | select(0u, 1u, ((((((v >> select(0u, 16u, ((v & 65535u) == 0u))) >> select(0u, 8u, (((v >> select(0u, 16u, ((v & 65535u) == 0u))) & 255u) == 0u))) >> select(0u, 4u, ((((v >> select(0u, 16u, ((v & 65535u) == 0u))) >> select(0u, 8u, (((v >> select(0u, 16u, ((v & 65535u) == 0u))) & 255u) == 0u))) & 15u) == 0u))) >> select(0u, 2u, (((((v >> select(0u, 16u, ((v & 65535u) == 0u))) >> select(0u, 8u, (((v >> select(0u, 16u, ((v & 65535u) == 0u))) & 255u) == 0u))) >> select(0u, 4u, ((((v >> select(0u, 16u, ((v & 65535u) == 0u))) >> select(0u, 8u, (((v >> select(0u, 16u, ((v & 65535u) == 0u))) & 255u) == 0u))) & 15u) == 0u))) & 3u) == 0u))) & 1u) == 0u)))))), 4294967295u, (((((v >> select(0u, 16u, ((v & 65535u) == 0u))) >> select(0u, 8u, (((v >> select(0u, 16u, ((v & 65535u) == 0u))) & 255u) == 0u))) >> select(0u, 4u, ((((v >> select(0u, 16u, ((v & 65535u) == 0u))) >> select(0u, 8u, (((v >> select(0u, 16u, ((v & 65535u) == 0u))) & 255u) == 0u))) & 15u) == 0u))) >> select(0u, 2u, (((((v >> select(0u, 16u, ((v & 65535u) == 0u))) >> select(0u, 8u, (((v >> select(0u, 16u, ((v & 65535u) == 0u))) & 255u) == 0u))) >> select(0u, 4u, ((((v >> select(0u, 16u, ((v & 65535u) == 0u))) >> select(0u, 8u, (((v >> select(0u, 16u, ((v & 65535u) == 0u))) & 255u) == 0u))) & 15u) == 0u))) & 3u) == 0u))) == 0u)));
  return res;
}

fragment void fragment_main(device int* prevent_dce [[buffer(0)]]) {
  tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.prevent_dce=prevent_dce};
  (*tint_module_vars.prevent_dce) = firstTrailingBit_3a2acc();
}

kernel void compute_main(device int* prevent_dce [[buffer(0)]]) {
  tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.prevent_dce=prevent_dce};
  (*tint_module_vars.prevent_dce) = firstTrailingBit_3a2acc();
}

VertexOutput vertex_main_inner() {
  VertexOutput out = {};
  out.pos = float4(0.0f);
  out.prevent_dce = firstTrailingBit_3a2acc();
  return out;
}

vertex vertex_main_outputs vertex_main() {
  VertexOutput const v_1 = vertex_main_inner();
  vertex_main_outputs tint_wrapper_result = {};
  tint_wrapper_result.VertexOutput_pos = v_1.pos;
  tint_wrapper_result.VertexOutput_prevent_dce = v_1.prevent_dce;
  return tint_wrapper_result;
}
