#include <metal_stdlib>

using namespace metal;
void textureLoad_ed55a8(texture2d_array<int, access::read_write> tint_symbol_1, device int4* const tint_symbol_2) {
  int2 arg_1 = int2(1);
  uint arg_2 = 1u;
  int4 res = tint_symbol_1.read(uint2(arg_1), arg_2);
  *(tint_symbol_2) = res;
}

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

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

vertex tint_symbol vertex_main(texture2d_array<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(texture2d_array<int, access::read_write> tint_symbol_7 [[texture(0)]], device int4* tint_symbol_8 [[buffer(0)]]) {
  textureLoad_ed55a8(tint_symbol_7, tint_symbol_8);
  return;
}

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

