#include <metal_stdlib>

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

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

kernel void compute_main(device uint2* tint_symbol_4 [[buffer(0)]], texture2d<float, access::sample> tint_symbol_5 [[texture(0)]]) {
  *(tint_symbol_4) = textureDimensions_13f8db(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(texture2d<float, access::sample> tint_symbol_6) {
  VertexOutput out = {};
  out.pos = float4(0.0f);
  out.prevent_dce = textureDimensions_13f8db(tint_symbol_6);
  return out;
}

vertex tint_symbol vertex_main(texture2d<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;
}

