#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_f16_array_element {
  /* 0x0000 */ packed_half3 packed;
  /* 0x0006 */ tint_array<int8_t, 2> tint_pad;
};

struct S_packed_vec3 {
  /* 0x0000 */ tint_array<tint_packed_vec3_f16_array_element, 3> tint_symbol;
  /* 0x0018 */ packed_half3 vector;
  /* 0x001e */ tint_array<int8_t, 2> tint_pad_1;
};

struct tint_module_vars_struct {
  const constant S_packed_vec3* data;
};

fragment void tint_symbol_1(const constant S_packed_vec3* data [[buffer(0)]]) {
  tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.data=data};
  half3 const v = half3((*tint_module_vars.data).vector);
  tint_array<tint_packed_vec3_f16_array_element, 3> const v_1 = (*tint_module_vars.data).tint_symbol;
  half3 const v_2 = half3(v_1[0u].packed);
  half3 const v_3 = half3(v_1[1u].packed);
  half3 const x = (v * half3x3(v_2, v_3, half3(v_1[2u].packed)));
}
