#include <metal_stdlib>

using namespace metal;
void textureGather_d1f187(texture2d_array<uint, access::sample> tint_symbol_1, sampler tint_symbol_2, device uint4* const tint_symbol_3) {
  float2 arg_3 = float2(1.0f);
  int arg_4 = 1;
  uint4 res = tint_symbol_1.gather(tint_symbol_2, arg_3, arg_4, int2(1), component::y);
  *(tint_symbol_3) = res;
}

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

float4 vertex_main_inner(texture2d_array<uint, access::sample> tint_symbol_4, sampler tint_symbol_5, device uint4* const tint_symbol_6) {
  textureGather_d1f187(tint_symbol_4, tint_symbol_5, tint_symbol_6);
  return float4(0.0f);
}

vertex tint_symbol vertex_main(texture2d_array<uint, access::sample> tint_symbol_7 [[texture(0)]], sampler tint_symbol_8 [[sampler(0)]], device uint4* 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(texture2d_array<uint, access::sample> tint_symbol_10 [[texture(0)]], sampler tint_symbol_11 [[sampler(0)]], device uint4* tint_symbol_12 [[buffer(0)]]) {
  textureGather_d1f187(tint_symbol_10, tint_symbol_11, tint_symbol_12);
  return;
}

kernel void compute_main(texture2d_array<uint, access::sample> tint_symbol_13 [[texture(0)]], sampler tint_symbol_14 [[sampler(0)]], device uint4* tint_symbol_15 [[buffer(0)]]) {
  textureGather_d1f187(tint_symbol_13, tint_symbol_14, tint_symbol_15);
  return;
}

