#include <metal_stdlib>

using namespace metal;

template<typename T, size_t N>
struct tint_array {
    const constant T& operator[](size_t i) const constant { return elements[i]; }
    device T& operator[](size_t i) device { return elements[i]; }
    const device T& operator[](size_t i) const device { return elements[i]; }
    thread T& operator[](size_t i) thread { return elements[i]; }
    const thread T& operator[](size_t i) const thread { return elements[i]; }
    threadgroup T& operator[](size_t i) threadgroup { return elements[i]; }
    const threadgroup T& operator[](size_t i) const threadgroup { return elements[i]; }
    T elements[N];
};

struct TintArrayLengths {
  /* 0x0000 */ tint_array<uint4, 1> array_lengths;
};

struct SB_RO {
  tint_array<int, 1> arg_0;
};

void arrayLength_1588cd(const constant TintArrayLengths* const tint_symbol_1, device uint* const tint_symbol_2) {
  uint res = (((*(tint_symbol_1)).array_lengths[0u][0u] - 0u) / 4u);
  *(tint_symbol_2) = res;
}

struct tint_symbol {
  float4 value [[position]];
};

float4 vertex_main_inner(const constant TintArrayLengths* const tint_symbol_3, device uint* const tint_symbol_4) {
  arrayLength_1588cd(tint_symbol_3, tint_symbol_4);
  return float4(0.0f);
}

vertex tint_symbol vertex_main(const constant TintArrayLengths* tint_symbol_5 [[buffer(30)]], device uint* 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(const constant TintArrayLengths* tint_symbol_7 [[buffer(30)]], device uint* tint_symbol_8 [[buffer(0)]]) {
  arrayLength_1588cd(tint_symbol_7, tint_symbol_8);
  return;
}

kernel void compute_main(const constant TintArrayLengths* tint_symbol_9 [[buffer(30)]], device uint* tint_symbol_10 [[buffer(0)]]) {
  arrayLength_1588cd(tint_symbol_9, tint_symbol_10);
  return;
}

