#include <metal_stdlib>

using namespace metal;
void textureGather_8578bc(texturecube_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, component::y);
  *(tint_symbol_3) = res;
}

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

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

vertex tint_symbol vertex_main(texturecube_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(texturecube_array<float, access::sample> tint_symbol_10 [[texture(0)]], sampler tint_symbol_11 [[sampler(0)]], device float4* tint_symbol_12 [[buffer(0)]]) {
  textureGather_8578bc(tint_symbol_10, tint_symbol_11, tint_symbol_12);
  return;
}

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

