// #target: macos-x64
module pointer_index;

fn void test1(int* x)
{
    int a = x[0];
    int b = *x;
    int c = x[1];
    int d = x[-1];
}

fn void test2(char* x)
{
    char a = x[0];
    char b = *x;
    char c = x[1];
}

fn void test3(long* x)
{
    long a = x[0];
    long b = *x;
    long c = x[1];
}

/* #expect: pointer_index.ll

define void @pointer_index.test1(ptr %0) #0 {
entry:
  %a = alloca i32, align 4
  %b = alloca i32, align 4
  %c = alloca i32, align 4
  %d = alloca i32, align 4
  %1 = load i32, ptr %0, align 4
  store i32 %1, ptr %a, align 4
  %2 = load i32, ptr %0, align 4
  store i32 %2, ptr %b, align 4
  %ptradd = getelementptr inbounds i8, ptr %0, i64 4
  %3 = load i32, ptr %ptradd, align 4
  store i32 %3, ptr %c, align 4
  %ptradd1 = getelementptr inbounds i8, ptr %0, i64 -4
  %4 = load i32, ptr %ptradd1, align 4
  store i32 %4, ptr %d, align 4
  ret void
}

; Function Attrs:
define void @pointer_index.test2(ptr %0) #0 {
entry:
  %a = alloca i8, align 1
  %b = alloca i8, align 1
  %c = alloca i8, align 1
  %1 = load i8, ptr %0, align 1
  store i8 %1, ptr %a, align 1
  %2 = load i8, ptr %0, align 1
  store i8 %2, ptr %b, align 1
  %ptradd = getelementptr inbounds i8, ptr %0, i64 1
  %3 = load i8, ptr %ptradd, align 1
  store i8 %3, ptr %c, align 1
  ret void
}

; Function Attrs:
define void @pointer_index.test3(ptr %0) #0 {
entry:
  %a = alloca i64, align 8
  %b = alloca i64, align 8
  %c = alloca i64, align 8
  %1 = load i64, ptr %0, align 8
  store i64 %1, ptr %a, align 8
  %2 = load i64, ptr %0, align 8
  store i64 %2, ptr %b, align 8
  %ptradd = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load i64, ptr %ptradd, align 8
  store i64 %3, ptr %c, align 8
  ret void
}
