#include <metal_stdlib>

using namespace metal;
uint textureDimensions_f17acd(texture1d<float, access::sample> tint_symbol_1) {
  int arg_1 = 1;
  uint res = tint_symbol_1.get_width(0);
  return res;
}

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

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

struct VertexOutput {
  float4 pos;
  uint prevent_dce;
};

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

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

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

