#include <metal_stdlib>

using namespace metal;

template<typename T>
T tint_dot4(vec<T,4> a, vec<T,4> b) {
  return a[0]*b[0] + a[1]*b[1] + a[2]*b[2] + a[3]*b[3];
}
uint tint_dot4_u8_packed(uint a, uint b) {
  uint4 const a_u8 = ((uint4(a) >> uint4(24u, 16u, 8u, 0u)) & uint4(255u));
  uint4 const b_u8 = ((uint4(b) >> uint4(24u, 16u, 8u, 0u)) & uint4(255u));
  return tint_dot4(a_u8, b_u8);
}

uint dot4U8Packed_fbed7b() {
  uint arg_0 = 1u;
  uint arg_1 = 1u;
  uint res = tint_dot4_u8_packed(arg_0, arg_1);
  return res;
}

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

kernel void compute_main(device uint* tint_symbol_2 [[buffer(0)]]) {
  *(tint_symbol_2) = dot4U8Packed_fbed7b();
  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 = dot4U8Packed_fbed7b();
  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;
}

