#include <metal_stdlib>

using namespace metal;
void textureLoad_46a93f(texture2d_array<float, access::sample> tint_symbol_1, device float4* const tint_symbol_2) {
  float4 res = tint_symbol_1.read(uint2(uint2(1u)), 1, 1u);
  *(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_46a93f(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_46a93f(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_46a93f(tint_symbol_9, tint_symbol_10);
  return;
}

