#include <metal_stdlib>

using namespace metal;
void textureStore_bd6602(texture2d_array<uint, access::read_write> tint_symbol_1) {
  uint2 arg_1 = uint2(1u);
  int arg_2 = 1;
  uint4 arg_3 = uint4(1u);
  tint_symbol_1.write(arg_3, uint2(arg_1), arg_2); tint_symbol_1.fence();
}

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

float4 vertex_main_inner(texture2d_array<uint, access::read_write> tint_symbol_2) {
  textureStore_bd6602(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_bd6602(tint_symbol_4);
  return;
}

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

