#include <metal_stdlib>

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

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

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

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

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

