#include <metal_stdlib>

using namespace metal;

uint tint_dot4U8Packed(uint param_0, uint param_1) {
  uchar4 vec1 = as_type<uchar4>(param_0);
  uchar4 vec2 = as_type<uchar4>(param_1);
  return vec1[0] * vec2[0] + vec1[1] * vec2[1] + vec1[2] * vec2[2] + vec1[3] * vec2[3];
}

void dot4U8Packed_fbed7b(device uint* const tint_symbol_1) {
  uint res = tint_dot4U8Packed(1u, 1u);
  *(tint_symbol_1) = res;
}

struct tint_symbol {
  float4 value [[position]];
};

float4 vertex_main_inner(device uint* const tint_symbol_2) {
  dot4U8Packed_fbed7b(tint_symbol_2);
  return float4(0.0f);
}

vertex tint_symbol vertex_main(device uint* tint_symbol_3 [[buffer(0)]]) {
  float4 const inner_result = vertex_main_inner(tint_symbol_3);
  tint_symbol wrapper_result = {};
  wrapper_result.value = inner_result;
  return wrapper_result;
}

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

kernel void compute_main(device uint* tint_symbol_5 [[buffer(0)]]) {
  dot4U8Packed_fbed7b(tint_symbol_5);
  return;
}

