#include <metal_stdlib>

using namespace metal;
void textureLoad_4acb64(texture2d_array<float, access::sample> tint_symbol_1, device float4* const tint_symbol_2) {
  float4 res = tint_symbol_1.read(uint2(int2(1)), 1u, 1);
  *(tint_symbol_2) = res;
}

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

float4 vertex_main_inner(texture2d_array<float, access::sample> tint_symbol_3, device float4* const tint_symbol_4) {
  textureLoad_4acb64(tint_symbol_3, tint_symbol_4);
  return float4(0.0f);
}

vertex tint_symbol vertex_main(texture2d_array<float, access::sample> tint_symbol_5 [[texture(0)]], device float4* 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<float, access::sample> tint_symbol_7 [[texture(0)]], device float4* tint_symbol_8 [[buffer(0)]]) {
  textureLoad_4acb64(tint_symbol_7, tint_symbol_8);
  return;
}

kernel void compute_main(texture2d_array<float, access::sample> tint_symbol_9 [[texture(0)]], device float4* tint_symbol_10 [[buffer(0)]]) {
  textureLoad_4acb64(tint_symbol_9, tint_symbol_10);
  return;
}

