#include <metal_stdlib>

using namespace metal;
void textureGather_7dd226(depthcube_array<float, access::sample> tint_symbol_1, sampler tint_symbol_2, device float4* const tint_symbol_3) {
  float4 res = tint_symbol_1.gather(tint_symbol_2, float3(1.0f), 1u);
  *(tint_symbol_3) = res;
}

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

float4 vertex_main_inner(depthcube_array<float, access::sample> tint_symbol_4, sampler tint_symbol_5, device float4* const tint_symbol_6) {
  textureGather_7dd226(tint_symbol_4, tint_symbol_5, tint_symbol_6);
  return float4(0.0f);
}

vertex tint_symbol vertex_main(depthcube_array<float, access::sample> tint_symbol_7 [[texture(0)]], sampler tint_symbol_8 [[sampler(0)]], device float4* tint_symbol_9 [[buffer(0)]]) {
  float4 const inner_result = vertex_main_inner(tint_symbol_7, tint_symbol_8, tint_symbol_9);
  tint_symbol wrapper_result = {};
  wrapper_result.value = inner_result;
  return wrapper_result;
}

fragment void fragment_main(depthcube_array<float, access::sample> tint_symbol_10 [[texture(0)]], sampler tint_symbol_11 [[sampler(0)]], device float4* tint_symbol_12 [[buffer(0)]]) {
  textureGather_7dd226(tint_symbol_10, tint_symbol_11, tint_symbol_12);
  return;
}

kernel void compute_main(depthcube_array<float, access::sample> tint_symbol_13 [[texture(0)]], sampler tint_symbol_14 [[sampler(0)]], device float4* tint_symbol_15 [[buffer(0)]]) {
  textureGather_7dd226(tint_symbol_13, tint_symbol_14, tint_symbol_15);
  return;
}

