#include <metal_stdlib>

using namespace metal;
void textureStore_a14041(texture1d<int, access::read_write> tint_symbol_1) {
  int arg_1 = 1;
  int4 arg_2 = int4(1);
  tint_symbol_1.write(arg_2, uint(arg_1)); tint_symbol_1.fence();
}

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

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

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

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

