#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*/ mo_free(char *);
scalar_t__ mo_init();
char *mo_malloc(int);
int main(void) {
  if (mo_init() < 0)
    return -1;
  int i;
  char *buf[(1 << 17)];
  for (i = 1; i < (1 << 17); i++) {
    buf[i] = mo_malloc(i);
  }
  for (i = 1; i < (1 << 17); i++) {
    mo_free(buf[i]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100010,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1030 <mo_init@plt>
cmp    $0x0,%rax
jge    115f <main+0x2f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d2 <main+0xa2>
movl   $0x1,-0x8(%rbp)
cmpl   $0x20000,-0x8(%rbp)
jge    1198 <main+0x68>
mov    -0x8(%rbp),%edi
call   1050 <mo_malloc@plt>
mov    %rax,%rcx
movslq -0x8(%rbp),%rax
mov    %rcx,-0x100010(%rbp,%rax,8)
ff
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1166 <main+0x36>
movl   $0x1,-0x8(%rbp)
cmpl   $0x20000,-0x8(%rbp)
jge    11cb <main+0x9b>
movslq -0x8(%rbp),%rax
mov    -0x100010(%rbp,%rax,8),%rdi
ff
call   1040 <mo_free@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    119f <main+0x6f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x100010,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x100000,%rsp
xor    %eax,%eax
call   1030 <mo_init@plt>
test   %rax,%rax
js     118a <main+0x5a>
mov    $0x1,%ebx
nopl   0x0(%rax)
mov    %ebx,%edi
call   1050 <mo_malloc@plt>
mov    %rax,(%rsp,%rbx,8)
add    $0x1,%rbx
cmp    $0x20000,%rbx
jne    1150 <main+0x20>
mov    $0x1,%ebx
nopl   (%rax)
mov    (%rsp,%rbx,8),%rdi
call   1040 <mo_free@plt>
add    $0x1,%rbx
cmp    $0x20000,%rbx
jne    1170 <main+0x40>
xor    %eax,%eax
jmp    118f <main+0x5f>
mov    $0xffffffff,%eax
add    $0x100000,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [131072 x i8*]
store i32 0, i32* %1
%4 = call i64 (...) @mo_init()
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %7
6: ; preds = %0
store i32 -1, i32* %1
br label %34
7: ; preds = %0
store i32 1, i32* %2
br label %8
8: ; preds = %17, %7
%9 = load i32, i32* %2
%10 = icmp slt i32 %9, 131072
br i1 %10, label %11, label %20
11: ; preds = %8
%12 = load i32, i32* %2
%13 = call i8* @mo_malloc(i32 %12)
%14 = load i32, i32* %2
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [131072 x i8*], [131072 x i8*]* %3, i64 0, i64 %15
store i8* %13, i8** %16
br label %17
17: ; preds = %11
%18 = load i32, i32* %2
%19 = add nsw i32 %18, 1
store i32 %19, i32* %2
br label %8
20: ; preds = %8
store i32 1, i32* %2
br label %21
21: ; preds = %30, %20
%22 = load i32, i32* %2
%23 = icmp slt i32 %22, 131072
br i1 %23, label %24, label %33
24: ; preds = %21
%25 = load i32, i32* %2
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [131072 x i8*], [131072 x i8*]* %3, i64 0, i64 %26
%28 = load i8*, i8** %27
%29 = call i32 @mo_free(i8* %28)
br label %30
30: ; preds = %24
%31 = load i32, i32* %2
%32 = add nsw i32 %31, 1
store i32 %32, i32* %2
br label %21
33: ; preds = %21
store i32 0, i32* %1
br label %34
34: ; preds = %33, %6
%35 = load i32, i32* %1
ret i32 %35
}

LLVM IR (-O2):
define i32 @main() {
%1 = alloca [131072 x i8*]
%2 = tail call i64 (...) @mo_init()
%3 = icmp slt i64 %2, 0
br i1 %3, label %21, label %4
4: ; preds = %0
%5 = bitcast [131072 x i8*]* %1 to i8*
br label %6
6: ; preds = %4, %6
%7 = phi i64 [ 1, %4 ], [ %11, %6 ]
%8 = trunc i64 %7 to i32
%9 = tail call i8* @mo_malloc(i32 %8)
%10 = getelementptr inbounds [131072 x i8*], [131072 x i8*]* %1, i64 0, i64 %7
store i8* %9, i8** %10
%11 = add nuw nsw i64 %7, 1
%12 = icmp eq i64 %11, 131072
br i1 %12, label %13, label %6
13: ; preds = %6, %13
%14 = phi i64 [ %18, %13 ], [ 1, %6 ]
%15 = getelementptr inbounds [131072 x i8*], [131072 x i8*]* %1, i64 0, i64 %14
%16 = load i8*, i8** %15
%17 = tail call i32 @mo_free(i8* %16)
%18 = add nuw nsw i64 %14, 1
%19 = icmp eq i64 %18, 131072
br i1 %19, label %20, label %13
20: ; preds = %13
br label %21
21: ; preds = %0, %20
%22 = phi i32 [ 0, %20 ], [ -1, %0 ]
ret i32 %22
}