#include <metal_stdlib>

using namespace metal;
void textureStore_0ff97a(texture2d_array<float, access::read_write> tint_symbol_1) {
  tint_symbol_1.write(float4(1.0f), uint2(uint2(1u)), 1u); tint_symbol_1.fence();
}

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

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

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

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

