#include <metal_stdlib>

using namespace metal;
uint4 tint_unpack_4xu8(uint a) {
  uint4 const a_vec4u = (uint4(a) >> uint4(0u, 8u, 16u, 24u));
  return (a_vec4u & uint4(255u));
}

void unpack4xU8_a5ea55(device uint4* const tint_symbol_1) {
  uint arg_0 = 1u;
  uint4 res = tint_unpack_4xu8(arg_0);
  *(tint_symbol_1) = res;
}

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

float4 vertex_main_inner(device uint4* const tint_symbol_2) {
  unpack4xU8_a5ea55(tint_symbol_2);
  return float4(0.0f);
}

vertex tint_symbol vertex_main(device uint4* 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 uint4* tint_symbol_4 [[buffer(0)]]) {
  unpack4xU8_a5ea55(tint_symbol_4);
  return;
}

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

