#include <metal_stdlib>

using namespace metal;
void textureStore_27063a(texture2d_array<float, access::write> tint_symbol_1) {
  uint2 arg_1 = uint2(1u);
  int arg_2 = 1;
  float4 arg_3 = float4(1.0f);
  tint_symbol_1.write(arg_3, uint2(arg_1), arg_2);
}

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

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

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

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

