#include <metal_stdlib>

using namespace metal;
void textureDimensions_eb9f4d(texture2d_array<int, access::read_write> tint_symbol_1, device uint2* const tint_symbol_2) {
  uint2 res = uint2(tint_symbol_1.get_width(), tint_symbol_1.get_height());
  *(tint_symbol_2) = res;
}

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

float4 vertex_main_inner(texture2d_array<int, access::read_write> tint_symbol_3, device uint2* const tint_symbol_4) {
  textureDimensions_eb9f4d(tint_symbol_3, tint_symbol_4);
  return float4(0.0f);
}

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

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

