#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 */ float el;
  /* 0x0004 */ tint_array<int8_t, 4> tint_pad;
};

struct strided_arr_1 {
  /* 0x0000 */ tint_array<tint_array<strided_arr, 2>, 3> el;
  /* 0x0030 */ tint_array<int8_t, 80> tint_pad_1;
};

struct S {
  /* 0x0000 */ tint_array<strided_arr_1, 4> a;
};

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

void assign_and_preserve_padding_3(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_4(&((*(dest))[i]), value[i]);
  }
}

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

void assign_and_preserve_padding_1(device strided_arr_1* const dest, strided_arr_1 value) {
  assign_and_preserve_padding_2(&((*(dest)).el), value.el);
}

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

void f_1(device S* const tint_symbol_1) {
  tint_array<strided_arr_1, 4> const x_19 = (*(tint_symbol_1)).a;
  tint_array<tint_array<strided_arr, 2>, 3> const x_24 = (*(tint_symbol_1)).a[3].el;
  tint_array<strided_arr, 2> const x_28 = (*(tint_symbol_1)).a[3].el[2];
  float const x_32 = (*(tint_symbol_1)).a[3].el[2][1].el;
  tint_array<strided_arr_1, 4> const tint_symbol = tint_array<strided_arr_1, 4>{};
  assign_and_preserve_padding(&((*(tint_symbol_1)).a), tint_symbol);
  (*(tint_symbol_1)).a[3].el[2][1].el = 5.0f;
  return;
}

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

