#include <metal_stdlib>

using namespace metal;
void textureDimensions_db7131(texture3d<int, access::read> 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<int, access::read> tint_symbol_3, device packed_uint3* const tint_symbol_4) {
  textureDimensions_db7131(tint_symbol_3, tint_symbol_4);
  return float4(0.0f);
}

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

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

