#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_packed_vec3_f32_array_element {
  packed_float3 packed;
};

struct tint_module_vars_struct {
  threadgroup tint_array<tint_packed_vec3_f32_array_element, 2>* v;
};

struct tint_symbol_2 {
  tint_array<tint_packed_vec3_f32_array_element, 2> tint_symbol_1;
};

void tint_symbol_inner(uint tint_local_index, tint_module_vars_struct tint_module_vars) {
  if ((tint_local_index == 0u)) {
    (*tint_module_vars.v)[0u].packed = packed_float3(float2x3(float3(0.0f), float3(0.0f))[0u]);
    (*tint_module_vars.v)[1u].packed = packed_float3(float2x3(float3(0.0f), float3(0.0f))[1u]);
  }
  threadgroup_barrier(mem_flags::mem_threadgroup);
  tint_array<tint_packed_vec3_f32_array_element, 2> const v_1 = (*tint_module_vars.v);
  float3 const v_2 = float3(v_1[0u].packed);
  float2x3 const v_3 = float2x3(v_2, float3(v_1[1u].packed));
}

kernel void tint_symbol(uint tint_local_index [[thread_index_in_threadgroup]], threadgroup tint_symbol_2* v_4 [[threadgroup(0)]]) {
  tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.v=(&(*v_4).tint_symbol_1)};
  tint_symbol_inner(tint_local_index, tint_module_vars);
}
