#include <metal_stdlib>

using namespace metal;
void textureNumLayers_327d70(texture2d_array<uint, access::read_write> 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<uint, access::read_write> tint_symbol_3, device uint* const tint_symbol_4) {
  textureNumLayers_327d70(tint_symbol_3, tint_symbol_4);
  return float4(0.0f);
}

vertex tint_symbol vertex_main(texture2d_array<uint, access::read_write> 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<uint, access::read_write> tint_symbol_7 [[texture(0)]], device uint* tint_symbol_8 [[buffer(0)]]) {
  textureNumLayers_327d70(tint_symbol_7, tint_symbol_8);
  return;
}

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

