#include <metal_stdlib>

using namespace metal;
uint2 textureDimensions_382b16(texturecube<float, access::sample> tint_symbol_1) {
  uint2 res = uint2(tint_symbol_1.get_width(1u), tint_symbol_1.get_height(1u));
  return res;
}

fragment void fragment_main(device uint2* tint_symbol_2 [[buffer(0)]], texturecube<float, access::sample> tint_symbol_3 [[texture(0)]]) {
  *(tint_symbol_2) = textureDimensions_382b16(tint_symbol_3);
  return;
}

kernel void compute_main(device uint2* tint_symbol_4 [[buffer(0)]], texturecube<float, access::sample> tint_symbol_5 [[texture(0)]]) {
  *(tint_symbol_4) = textureDimensions_382b16(tint_symbol_5);
  return;
}

struct VertexOutput {
  float4 pos;
  uint2 prevent_dce;
};

struct tint_symbol {
  uint2 prevent_dce [[user(locn0)]] [[flat]];
  float4 pos [[position]];
};

VertexOutput vertex_main_inner(texturecube<float, access::sample> tint_symbol_6) {
  VertexOutput out = {};
  out.pos = float4(0.0f);
  out.prevent_dce = textureDimensions_382b16(tint_symbol_6);
  return out;
}

vertex tint_symbol vertex_main(texturecube<float, access::sample> tint_symbol_7 [[texture(0)]]) {
  VertexOutput const inner_result = vertex_main_inner(tint_symbol_7);
  tint_symbol wrapper_result = {};
  wrapper_result.pos = inner_result.pos;
  wrapper_result.prevent_dce = inner_result.prevent_dce;
  return wrapper_result;
}

