#include <metal_stdlib>

using namespace metal;
void textureLoad_c9f310(texture1d<int, access::read_write> tint_symbol_1, device int4* const tint_symbol_2) {
  int arg_1 = 1;
  int4 res = tint_symbol_1.read(uint(arg_1));
  *(tint_symbol_2) = res;
}

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

float4 vertex_main_inner(texture1d<int, access::read_write> tint_symbol_3, device int4* const tint_symbol_4) {
  textureLoad_c9f310(tint_symbol_3, tint_symbol_4);
  return float4(0.0f);
}

vertex tint_symbol vertex_main(texture1d<int, access::read_write> tint_symbol_5 [[texture(0)]], device int4* tint_symbol_6 [[buffer(0)]]) {
  float4 const inner_result = vertex_main_inner(tint_symbol_5, tint_symbol_6);
  tint_symbol wrapper_result = {};
  wrapper_result.value = inner_result;
  return wrapper_result;
}

fragment void fragment_main(texture1d<int, access::read_write> tint_symbol_7 [[texture(0)]], device int4* tint_symbol_8 [[buffer(0)]]) {
  textureLoad_c9f310(tint_symbol_7, tint_symbol_8);
  return;
}

kernel void compute_main(texture1d<int, access::read_write> tint_symbol_9 [[texture(0)]], device int4* tint_symbol_10 [[buffer(0)]]) {
  textureLoad_c9f310(tint_symbol_9, tint_symbol_10);
  return;
}

