#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ m5_dump_stats(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ m5_reset_stats(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ spm_malloc(int, int);
int main(int argc, char **argv) {
  printf("test program start\n");
  int *p = (int *)spm_malloc(sizeof(int) * 16 * 1024, 1);
  int *s = (int *)spm_malloc(sizeof(int) * 16 * 1024, 2);
  int i = 0;
  if (0) {
    printf("Virtual address pointer vaddr: %lu\n", p);
    exit(0);
  }
  m5_reset_stats(0, 0);
  for (i = 0; i < 1024; i++) {
    p[i] = i;
    s[i] = p[i] + 1;
    printf("dir: %d, %d\n", p[i], s[i]);
  }
  m5_dump_stats(0, 0);
  printf("test program finish\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x10000,%edi
mov    $0x1,%esi
call   1060 <spm_malloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x10000,%edi
mov    $0x2,%esi
call   1060 <spm_malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
xor    %esi,%esi
mov    %esi,%edi
call   1050 <m5_reset_stats@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0x400,-0x24(%rbp)
jge    1207 <main+0xc7>
mov    -0x24(%rbp),%edx
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11a1 <main+0x61>
xor    %esi,%esi
mov    %esi,%edi
call   1030 <m5_dump_stats@plt>
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xeae(%rip),%rdi
call   1040 <puts@plt>
mov    $0x10000,%edi
mov    $0x1,%esi
call   1070 <spm_malloc@plt>
mov    %rax,%r12
mov    $0x10000,%edi
mov    $0x2,%esi
call   1070 <spm_malloc@plt>
mov    %rax,%r14
xor    %edi,%edi
xor    %esi,%esi
call   1060 <m5_reset_stats@plt>
lea    0xe68(%rip),%r15
xor    %eax,%eax
nopw   0x0(%rax,%rax,1)
mov    %eax,(%r12,%rax,4)
lea    0x1(%rax),%rbx
mov    %ebx,(%r14,%rax,4)
mov    (%r12,%rax,4),%esi
mov    %r15,%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rax
cmp    $0x400,%rbx
jne    11a0 <main+0x50>
xor    %edi,%edi
xor    %esi,%esi
call   1030 <m5_dump_stats@plt>
lea    0xe48(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [20 x i8] c"test program start\0A\00"
@.str.1 = [13 x i8] c"dir: %d, %d\0A\00"
@.str.2 = [21 x i8] c"test program finish\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%10 = call i64 @spm_malloc(i32 65536, i32 1)
%11 = inttoptr i64 %10 to i32*
store i32* %11, i32** %6
%12 = call i64 @spm_malloc(i32 65536, i32 2)
%13 = inttoptr i64 %12 to i32*
store i32* %13, i32** %7
store i32 0, i32* %8
%14 = call i32 @m5_reset_stats(i32 0, i32 0)
store i32 0, i32* %8
br label %15
15: ; preds = %45, %2
%16 = load i32, i32* %8
%17 = icmp slt i32 %16, 1024
br i1 %17, label %18, label %48
18: ; preds = %15
%19 = load i32, i32* %8
%20 = load i32*, i32** %6
%21 = load i32, i32* %8
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %20, i64 %22
store i32 %19, i32* %23
%24 = load i32*, i32** %6
%25 = load i32, i32* %8
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %24, i64 %26
%28 = load i32, i32* %27
%29 = add nsw i32 %28, 1
%30 = load i32*, i32** %7
%31 = load i32, i32* %8
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %30, i64 %32
store i32 %29, i32* %33
%34 = load i32*, i32** %6
%35 = load i32, i32* %8
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32, i32* %34, i64 %36
%38 = load i32, i32* %37
%39 = load i32*, i32** %7
%40 = load i32, i32* %8
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i32, i32* %39, i64 %41
%43 = load i32, i32* %42
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %38, i32 %43)
br label %45
45: ; preds = %18
%46 = load i32, i32* %8
%47 = add nsw i32 %46, 1
store i32 %47, i32* %8
br label %15
48: ; preds = %15
%49 = call i32 @m5_dump_stats(i32 0, i32 0)
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
@.str.1 = [13 x i8] c"dir: %d, %d\0A\00"
@str = [19 x i8] c"test program start\00"
@str.3 = [20 x i8] c"test program finish\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%4 = tail call i64 @spm_malloc(i32 65536, i32 1)
%5 = inttoptr i64 %4 to i32*
%6 = tail call i64 @spm_malloc(i32 65536, i32 2)
%7 = inttoptr i64 %6 to i32*
%8 = tail call i32 @m5_reset_stats(i32 0, i32 0)
br label %9
9: ; preds = %2, %9
%10 = phi i64 [ 0, %2 ], [ %13, %9 ]
%11 = getelementptr inbounds i32, i32* %5, i64 %10
%12 = trunc i64 %10 to i32
store i32 %12, i32* %11
%13 = add nuw nsw i64 %10, 1
%14 = getelementptr inbounds i32, i32* %7, i64 %10
%15 = trunc i64 %13 to i32
store i32 %15, i32* %14
%16 = load i32, i32* %11
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %16, i32 %15)
%18 = icmp eq i64 %13, 1024
br i1 %18, label %19, label %9
19: ; preds = %9
%20 = tail call i32 @m5_dump_stats(i32 0, i32 0)
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.3, i64 0, i64 0))
ret i32 0
}