#include <metal_stdlib>

using namespace metal;
void textureNumLayers_7895f4(texture2d_array<float, access::read> tint_symbol_1, device uint* const tint_symbol_2) {
  uint res = tint_symbol_1.get_array_size();
  *(tint_symbol_2) = res;
}

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

float4 vertex_main_inner(texture2d_array<float, access::read> tint_symbol_3, device uint* const tint_symbol_4) {
  textureNumLayers_7895f4(tint_symbol_3, tint_symbol_4);
  return float4(0.0f);
}

vertex tint_symbol vertex_main(texture2d_array<float, access::read> tint_symbol_5 [[texture(0)]], device uint* tint_symbol_6 [[buffer(0)]]) {
  float4 const inner_result = vertex_main_inner(tint_symbol_5, tint_symbol_6);
  tint_symbol wrapper_result = {};
  wrapper_result.value = inner_result;
  return wrapper_result;
}

fragment void fragment_main(texture2d_array<float, access::read> tint_symbol_7 [[texture(0)]], device uint* tint_symbol_8 [[buffer(0)]]) {
  textureNumLayers_7895f4(tint_symbol_7, tint_symbol_8);
  return;
}

kernel void compute_main(texture2d_array<float, access::read> tint_symbol_9 [[texture(0)]], device uint* tint_symbol_10 [[buffer(0)]]) {
  textureNumLayers_7895f4(tint_symbol_9, tint_symbol_10);
  return;
}

