#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*/ cmalloc_free(int *);
scalar_t__ cmalloc_malloc(int);
int /*<<< orphan*/ cmalloc_trace();
int /*<<< orphan*/ printf(char *, int, int *);
int main(int argc, char *argv[]) {
  int i, *ptr;
  for (i = 0; i < 4096; ++i) {
    ptr = (int *)cmalloc_malloc(1);
    printf("%d\t%p\n", i, ptr);
  }
  cmalloc_free(ptr);
  cmalloc_trace();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x1000,-0x14(%rbp)
jge    1199 <main+0x59>
mov    $0x1,%edi
call   1040 <cmalloc_malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
lea    0xe7a(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115d <main+0x1d>
mov    -0x20(%rbp),%rdi
call   1050 <cmalloc_free@plt>
mov    $0x0,%al
call   1060 <cmalloc_trace@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
xor    %ebx,%ebx
lea    0xeb2(%rip),%r14
xchg   %ax,%ax
mov    $0x1,%edi
call   1040 <cmalloc_malloc@plt>
mov    %rax,%r15
mov    %r14,%rdi
mov    %ebx,%esi
mov    %rax,%rdx
call   1030 <printf@plt>
add    $0x1,%ebx
cmp    $0x1000,%ebx
jne    1150 <main+0x10>
mov    %r15,%rdi
call   1050 <cmalloc_free@plt>
xor    %eax,%eax
call   1060 <cmalloc_trace@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%d\09%p\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
br label %8
8: ; preds = %17, %2
%9 = load i32, i32* %6
%10 = icmp slt i32 %9, 4096
br i1 %10, label %11, label %20
11: ; preds = %8
%12 = call i64 @cmalloc_malloc(i32 1)
%13 = inttoptr i64 %12 to i32*
store i32* %13, i32** %7
%14 = load i32, i32* %6
%15 = load i32*, i32** %7
%16 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %14, i32* %15)
br label %17
17: ; preds = %11
%18 = load i32, i32* %6
%19 = add nsw i32 %18, 1
store i32 %19, i32* %6
br label %8
20: ; preds = %8
%21 = load i32*, i32** %7
%22 = call i32 @cmalloc_free(i32* %21)
%23 = call i32 (...) @cmalloc_trace()
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"%d\09%p\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
br label %3
3: ; preds = %2, %3
%4 = phi i32 [ 0, %2 ], [ %8, %3 ]
%5 = tail call i64 @cmalloc_malloc(i32 1)
%6 = inttoptr i64 %5 to i32*
%7 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %4, i32* %6)
%8 = add nuw nsw i32 %4, 1
%9 = icmp eq i32 %8, 4096
br i1 %9, label %10, label %3
10: ; preds = %3
%11 = inttoptr i64 %5 to i32*
%12 = tail call i32 @cmalloc_free(i32* %11)
%13 = tail call i32 (...) @cmalloc_trace()
ret i32 0
}