#include <metal_stdlib>

using namespace metal;
void textureStore_ac0a55(texture2d_array<uint, access::read_write> tint_symbol_1) {
  tint_symbol_1.write(uint4(1u), uint2(uint2(1u)), 1u); tint_symbol_1.fence();
}

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

float4 vertex_main_inner(texture2d_array<uint, access::read_write> tint_symbol_2) {
  textureStore_ac0a55(tint_symbol_2);
  return float4(0.0f);
}

vertex tint_symbol vertex_main(texture2d_array<uint, access::read_write> tint_symbol_3 [[texture(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(texture2d_array<uint, access::read_write> tint_symbol_4 [[texture(0)]]) {
  textureStore_ac0a55(tint_symbol_4);
  return;
}

kernel void compute_main(texture2d_array<uint, access::read_write> tint_symbol_5 [[texture(0)]]) {
  textureStore_ac0a55(tint_symbol_5);
  return;
}

