// #target: macos-x64
module test;

struct Foo
{
  float[4] a;
}

fn void test()
{
	int b = 123;
	int[100] g;
	mem::store(&b, 342, $align: 2, $volatile: true);
	int z = mem::load(&b, $align: 2, $volatile: true);
	int[100] gg = mem::load(&g, $align: 4, $volatile: true);
	mem::store(&g, gg, $align: 4, $volatile: true);
}

fn void main()
{
  Foo* foo;
  float[<4>] a @align(1) @noinit;
  float[<4>] b @align(1) @noinit;

  a = *(float[<4>]*)&foo.a;
  *(float[<4>]*)&foo.a = a;

  a = $$unaligned_load((float[<4>]*)&foo.a, 1, false);
  $$unaligned_store((float[<4>]*)&foo.a, a, 1, false);

  b = @unaligned_load(*(float[<4>]*)&foo.a, 1);
  @unaligned_store(*(float[<4>]*)&foo.a, b, 1);
}

/* #expect: test.ll

define void @test.test() #0 {
entry:
  %b = alloca i32, align 4
  %g = alloca [100 x i32], align 16
  %z = alloca i32, align 4
  %gg = alloca [100 x i32], align 16
  %value = alloca [100 x i32], align 16
  store i32 123, ptr %b, align 4
  call void @llvm.memset.p0.i64(ptr align 16 %g, i8 0, i64 400, i1 false)
  store volatile i32 342, ptr %b, align 4
  %0 = load volatile i32, ptr %b, align 2
  store i32 %0, ptr %z, align 4
  %1 = load volatile [100 x i32], ptr %g, align 4
  store [100 x i32] %1, ptr %gg, align 16
  call void @llvm.memcpy.p0.p0.i32(ptr align 16 %value, ptr align 16 %gg, i32 400, i1 false)
  call void @llvm.memcpy.p0.p0.i32(ptr align 4 %g, ptr align 16 %value, i32 400, i1 true)
  ret void
}

define void @test.main() #0 {
entry:
  %foo = alloca ptr, align 8
  %a = alloca <4 x float>, align 1
  %b = alloca <4 x float>, align 1
  %value = alloca <4 x float>, align 16
  store ptr null, ptr %foo, align 8
  %0 = load ptr, ptr %foo, align 8
  %1 = load <4 x float>, ptr %0, align 4
  store <4 x float> %1, ptr %a, align 1
  %2 = load ptr, ptr %foo, align 8
  %3 = load <4 x float>, ptr %a, align 1
  store <4 x float> %3, ptr %2, align 4
  %4 = load ptr, ptr %foo, align 8
  %5 = load <4 x float>, ptr %4, align 1
  store <4 x float> %5, ptr %a, align 1
  %6 = load ptr, ptr %foo, align 8
  %7 = load <4 x float>, ptr %a, align 1
  store <4 x float> %7, ptr %6, align 1
  %8 = load ptr, ptr %foo, align 8
  %9 = load <4 x float>, ptr %8, align 1
  store <4 x float> %9, ptr %b, align 1
  %10 = load <4 x float>, ptr %b, align 1
  store <4 x float> %10, ptr %value, align 16
  %11 = load ptr, ptr %foo, align 8
  %12 = load <4 x float>, ptr %value, align 16
  store <4 x float> %12, ptr %11, align 1
  ret void
}