#include <metal_stdlib>

using namespace metal;
float4 textureLoad_e57e92(texture2d_array<float, access::read> tint_symbol_1) {
  float4 res = tint_symbol_1.read(uint2(uint2(1u)), 1);
  return res;
}

fragment void fragment_main(device float4* tint_symbol_2 [[buffer(0)]], texture2d_array<float, access::read> tint_symbol_3 [[texture(0)]]) {
  *(tint_symbol_2) = textureLoad_e57e92(tint_symbol_3);
  return;
}

kernel void compute_main(device float4* tint_symbol_4 [[buffer(0)]], texture2d_array<float, access::read> tint_symbol_5 [[texture(0)]]) {
  *(tint_symbol_4) = textureLoad_e57e92(tint_symbol_5);
  return;
}

struct VertexOutput {
  float4 pos;
  float4 prevent_dce;
};

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

VertexOutput vertex_main_inner(texture2d_array<float, access::read> tint_symbol_6) {
  VertexOutput out = {};
  out.pos = float4(0.0f);
  out.prevent_dce = textureLoad_e57e92(tint_symbol_6);
  return out;
}

vertex tint_symbol vertex_main(texture2d_array<float, access::read> tint_symbol_7 [[texture(0)]]) {
  VertexOutput const inner_result = vertex_main_inner(tint_symbol_7);
  tint_symbol wrapper_result = {};
  wrapper_result.pos = inner_result.pos;
  wrapper_result.prevent_dce = inner_result.prevent_dce;
  return wrapper_result;
}

