#include <metal_stdlib>
using namespace metal;

struct tint_module_vars_struct {
  device uint* prevent_dce;
};

struct VertexOutput {
  float4 pos;
  uint prevent_dce;
};

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

uint tint_dot(uint4 lhs, uint4 rhs) {
  return ((((lhs * rhs)[0u] + (lhs * rhs)[1u]) + (lhs * rhs)[2u]) + (lhs * rhs)[3u]);
}

uint pack4xI8Clamp_e42b2a() {
  int4 arg_0 = int4(1);
  int4 const v = arg_0;
  uint4 const v_1 = uint4(0u, 8u, 16u, 24u);
  int4 const v_2 = int4(-128);
  uint4 const v_3 = as_type<uint4>(clamp(v, v_2, int4(127)));
  uint4 const v_4 = ((v_3 & uint4(255u)) << v_1);
  uint res = tint_dot(v_4, uint4(1u));
  return res;
}

fragment void fragment_main(device uint* 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) = pack4xI8Clamp_e42b2a();
}

kernel void compute_main(device uint* 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) = pack4xI8Clamp_e42b2a();
}

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

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