#include <metal_stdlib>

using namespace metal;
void textureStore_2f29ea(texture2d<int, access::read_write> tint_symbol_1) {
  tint_symbol_1.write(int4(1), uint2(int2(1))); tint_symbol_1.fence();
}

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

float4 vertex_main_inner(texture2d<int, access::read_write> tint_symbol_2) {
  textureStore_2f29ea(tint_symbol_2);
  return float4(0.0f);
}

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

kernel void compute_main(texture2d<int, access::read_write> tint_symbol_5 [[texture(0)]]) {
  textureStore_2f29ea(tint_symbol_5);
  return;
}

