#include <metal_stdlib>

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

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

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

