#include <metal_stdlib>
using namespace metal;

struct tint_module_vars_struct {
  device uint4* prevent_dce;
};

struct VertexOutput {
  float4 pos;
  uint4 prevent_dce;
};

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

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

fragment void fragment_main(device uint4* 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_110f2c();
}

kernel void compute_main(device uint4* 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_110f2c();
}

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