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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100010,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
cmpl   $0x20000,-0x8(%rbp)
jge    116b <main+0x4b>
mov    -0x8(%rbp),%edi
call   1040 <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    1139 <main+0x19>
movl   $0x1,-0x8(%rbp)
cmpl   $0x20000,-0x8(%rbp)
jge    119e <main+0x7e>
movslq -0x8(%rbp),%rax
mov    -0x100010(%rbp,%rax,8),%rdi
ff
call   1030 <free@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1172 <main+0x52>
xor    %eax,%eax
add    $0x100010,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x100000,%rsp
mov    $0x1,%ebx
nopl   (%rax)
mov    %ebx,%edi
call   1040 <malloc@plt>
mov    %rax,(%rsp,%rbx,8)
add    $0x1,%rbx
cmp    $0x20000,%rbx
jne    1130 <main+0x10>
mov    $0x1,%ebx
nopl   (%rax)
mov    (%rsp,%rbx,8),%rdi
call   1030 <free@plt>
add    $0x1,%rbx
cmp    $0x20000,%rbx
jne    1150 <main+0x30>
xor    %eax,%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
store i32 1, i32* %2
br label %4
4: ; preds = %13, %0
%5 = load i32, i32* %2
%6 = icmp slt i32 %5, 131072
br i1 %6, label %7, label %16
7: ; preds = %4
%8 = load i32, i32* %2
%9 = call i8* @malloc(i32 %8)
%10 = load i32, i32* %2
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [131072 x i8*], [131072 x i8*]* %3, i64 0, i64 %11
store i8* %9, i8** %12
br label %13
13: ; preds = %7
%14 = load i32, i32* %2
%15 = add nsw i32 %14, 1
store i32 %15, i32* %2
br label %4
16: ; preds = %4
store i32 1, i32* %2
br label %17
17: ; preds = %26, %16
%18 = load i32, i32* %2
%19 = icmp slt i32 %18, 131072
br i1 %19, label %20, label %29
20: ; preds = %17
%21 = load i32, i32* %2
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [131072 x i8*], [131072 x i8*]* %3, i64 0, i64 %22
%24 = load i8*, i8** %23
%25 = call i32 @free(i8* %24)
br label %26
26: ; preds = %20
%27 = load i32, i32* %2
%28 = add nsw i32 %27, 1
store i32 %28, i32* %2
br label %17
29: ; preds = %17
ret i32 0
}

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