#include <metal_stdlib>

using namespace metal;
void textureDimensions_a105a5(texture3d<uint, access::read_write> tint_symbol_1, device packed_uint3* const tint_symbol_2) {
  uint3 res = uint3(tint_symbol_1.get_width(), tint_symbol_1.get_height(), tint_symbol_1.get_depth());
  *(tint_symbol_2) = packed_uint3(res);
}

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

float4 vertex_main_inner(texture3d<uint, access::read_write> tint_symbol_3, device packed_uint3* const tint_symbol_4) {
  textureDimensions_a105a5(tint_symbol_3, tint_symbol_4);
  return float4(0.0f);
}

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

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

