// #target: macos-x64
module test;

import std;

struct Foo
{
	int[5] a;
}
fn int Foo.get(self, usz i) @operator([]) => self.a[i];
fn void Foo.set(&self, usz i, int j) @operator([]=) { self.a[i] = j; }

Foo m;
fn void main() {

	m.a[3] = 100;
	int x = m[3]--;
}

/* #expect: test.ll

define i32 @test.Foo.get(ptr byval(%Foo) align 8 %0, i64 %1) #0 {
entry:
  %ptroffset = getelementptr inbounds [4 x i8], ptr %0, i64 %1
  %2 = load i32, ptr %ptroffset, align 4
  ret i32 %2
}

define void @test.Foo.set(ptr %0, i64 %1, i32 %2) #0 {
entry:
  %ptroffset = getelementptr inbounds [4 x i8], ptr %0, i64 %1
  store i32 %2, ptr %ptroffset, align 4
  ret void
}

define void @test.main() #0 {
entry:
  %x = alloca i32, align 4
  %.anon = alloca i32, align 4
  %indirectarg = alloca %Foo, align 8
  store i32 100, ptr getelementptr inbounds (i8, ptr @test.m, i64 12), align 4
  call void @llvm.memcpy.p0.p0.i32(ptr align 8 %indirectarg, ptr align 4 @test.m, i32 20, i1 false)
  %0 = call i32 @test.Foo.get(ptr byval(%Foo) align 8 %indirectarg, i64 3)
  store i32 %0, ptr %.anon, align 4
  %1 = load i32, ptr %.anon, align 4
  %sub = sub i32 %1, 1
  store i32 %sub, ptr %.anon, align 4
  %2 = load i32, ptr %.anon, align 4
  call void @test.Foo.set(ptr @test.m, i64 3, i32 %2)
  store i32 %1, ptr %x, align 4
  ret void
}
