#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) {
  float3 arg_2 = float3(1.0f);
  uint arg_3 = 1u;
  float4 res = tint_symbol_1.gather(tint_symbol_2, arg_2, arg_3);
  *(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;
}

