#include <metal_stdlib>

using namespace metal;
float4 textureGather_829357(texturecube_array<float, access::sample> tint_symbol_1, sampler tint_symbol_2) {
  float3 arg_3 = float3(1.0f);
  uint arg_4 = 1u;
  float4 res = tint_symbol_1.gather(tint_symbol_2, arg_3, arg_4, component::y);
  return res;
}

fragment void fragment_main(device float4* tint_symbol_3 [[buffer(0)]], texturecube_array<float, access::sample> tint_symbol_4 [[texture(0)]], sampler tint_symbol_5 [[sampler(0)]]) {
  *(tint_symbol_3) = textureGather_829357(tint_symbol_4, tint_symbol_5);
  return;
}

kernel void compute_main(device float4* tint_symbol_6 [[buffer(0)]], texturecube_array<float, access::sample> tint_symbol_7 [[texture(0)]], sampler tint_symbol_8 [[sampler(0)]]) {
  *(tint_symbol_6) = textureGather_829357(tint_symbol_7, tint_symbol_8);
  return;
}

struct VertexOutput {
  float4 pos;
  float4 prevent_dce;
};

struct tint_symbol {
  float4 prevent_dce [[user(locn0)]] [[flat]];
  float4 pos [[position]];
};

VertexOutput vertex_main_inner(texturecube_array<float, access::sample> tint_symbol_9, sampler tint_symbol_10) {
  VertexOutput out = {};
  out.pos = float4(0.0f);
  out.prevent_dce = textureGather_829357(tint_symbol_9, tint_symbol_10);
  return out;
}

vertex tint_symbol vertex_main(texturecube_array<float, access::sample> tint_symbol_11 [[texture(0)]], sampler tint_symbol_12 [[sampler(0)]]) {
  VertexOutput const inner_result = vertex_main_inner(tint_symbol_11, tint_symbol_12);
  tint_symbol wrapper_result = {};
  wrapper_result.pos = inner_result.pos;
  wrapper_result.prevent_dce = inner_result.prevent_dce;
  return wrapper_result;
}

