#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 SB_RW {
  tint_array<half, 1> arg_0;
};
struct tint_module_vars_struct {
  device SB_RW* sb_rw;
  device uint* prevent_dce;
  const constant tint_array<uint4, 1>* tint_storage_buffer_sizes;
};
struct vertex_main_outputs {
  float4 tint_symbol [[position]];
};

void arrayLength_cbd6b5(tint_module_vars_struct tint_module_vars) {
  uint res = (((*tint_module_vars.tint_storage_buffer_sizes)[0u][0u] - 0u) / 2u);
  (*tint_module_vars.prevent_dce) = res;
}
float4 vertex_main_inner(tint_module_vars_struct tint_module_vars) {
  arrayLength_cbd6b5(tint_module_vars);
  return float4(0.0f);
}
fragment void fragment_main(device SB_RW* sb_rw [[buffer(0)]], device uint* prevent_dce [[buffer(1)]], const constant tint_array<uint4, 1>* tint_storage_buffer_sizes) {
  tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.sb_rw=sb_rw, .prevent_dce=prevent_dce, .tint_storage_buffer_sizes=tint_storage_buffer_sizes};
  arrayLength_cbd6b5(tint_module_vars);
}
kernel void compute_main(device SB_RW* sb_rw [[buffer(0)]], device uint* prevent_dce [[buffer(1)]], const constant tint_array<uint4, 1>* tint_storage_buffer_sizes) {
  tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.sb_rw=sb_rw, .prevent_dce=prevent_dce, .tint_storage_buffer_sizes=tint_storage_buffer_sizes};
  arrayLength_cbd6b5(tint_module_vars);
}
vertex vertex_main_outputs vertex_main(device SB_RW* sb_rw [[buffer(0)]], device uint* prevent_dce [[buffer(1)]], const constant tint_array<uint4, 1>* tint_storage_buffer_sizes) {
  tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.sb_rw=sb_rw, .prevent_dce=prevent_dce, .tint_storage_buffer_sizes=tint_storage_buffer_sizes};
  return vertex_main_outputs{.tint_symbol=vertex_main_inner(tint_module_vars)};
}
