#include <metal_stdlib>

using namespace metal;
uint textureNumLevels_181090(texture2d_array<uint, access::sample> tint_symbol_1) {
  uint res = tint_symbol_1.get_num_mip_levels();
  return res;
}

fragment void fragment_main(device uint* tint_symbol_2 [[buffer(0)]], texture2d_array<uint, access::sample> tint_symbol_3 [[texture(0)]]) {
  *(tint_symbol_2) = textureNumLevels_181090(tint_symbol_3);
  return;
}

kernel void compute_main(device uint* tint_symbol_4 [[buffer(0)]], texture2d_array<uint, access::sample> tint_symbol_5 [[texture(0)]]) {
  *(tint_symbol_4) = textureNumLevels_181090(tint_symbol_5);
  return;
}

struct VertexOutput {
  float4 pos;
  uint prevent_dce;
};

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

VertexOutput vertex_main_inner(texture2d_array<uint, access::sample> tint_symbol_6) {
  VertexOutput out = {};
  out.pos = float4(0.0f);
  out.prevent_dce = textureNumLevels_181090(tint_symbol_6);
  return out;
}

vertex tint_symbol vertex_main(texture2d_array<uint, access::sample> 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;
}

