#include <metal_stdlib>

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

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

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

