#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 tint_module_vars_struct {
  device tint_array<int, 4>* tint_symbol;
};

void foo(device tint_array<int, 4>* const arg) {
  {
    int i = 0;
    while(true) {
      if ((i < 4)) {
      } else {
        break;
      }
      switch((*arg)[i]) {
        case 1:
        {
          {
            i = (i + 1);
          }
          continue;
        }
        default:
        {
          (*arg)[i] = 2;
          break;
        }
      }
      {
        i = (i + 1);
      }
      continue;
    }
  }
}

fragment void tint_symbol_1(device tint_array<int, 4>* tint_symbol [[buffer(0)]]) {
  tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.tint_symbol=tint_symbol};
  foo(tint_module_vars.tint_symbol);
}
