#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];
};

#define TINT_ISOLATE_UB(VOLATILE_NAME) \
  {volatile bool VOLATILE_NAME = false; if (VOLATILE_NAME) break;}

struct strided_arr {
  /* 0x0000 */ float2 el;
  /* 0x0008 */ tint_array<int8_t, 8> tint_pad;
};

struct SSBO {
  /* 0x0000 */ tint_array<strided_arr, 2> m;
};

tint_array<strided_arr, 2> mat2x2_stride_16_to_arr(float2x2 m) {
  strided_arr const tint_symbol_2 = {.el=m[0u]};
  strided_arr const tint_symbol_3 = {.el=m[1u]};
  tint_array<strided_arr, 2> const tint_symbol_4 = tint_array<strided_arr, 2>{tint_symbol_2, tint_symbol_3};
  return tint_symbol_4;
}

float2x2 arr_to_mat2x2_stride_16(tint_array<strided_arr, 2> arr) {
  return float2x2(arr[0u].el, arr[1u].el);
}

void assign_and_preserve_padding_1(device strided_arr* const dest, strided_arr value) {
  (*(dest)).el = value.el;
}

void assign_and_preserve_padding(device tint_array<strided_arr, 2>* const dest, tint_array<strided_arr, 2> value) {
  for(uint i = 0u; (i < 2u); i = (i + 1u)) {
    TINT_ISOLATE_UB(tint_volatile_false);
    assign_and_preserve_padding_1(&((*(dest))[i]), value[i]);
  }
}

void f_1(device SSBO* const tint_symbol_5) {
  float2x2 const tint_symbol = arr_to_mat2x2_stride_16((*(tint_symbol_5)).m);
  tint_array<strided_arr, 2> const tint_symbol_1 = mat2x2_stride_16_to_arr(tint_symbol);
  assign_and_preserve_padding(&((*(tint_symbol_5)).m), tint_symbol_1);
  return;
}

kernel void f(device SSBO* tint_symbol_6 [[buffer(0)]]) {
  f_1(tint_symbol_6);
  return;
}

