#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(unsigned int *);
unsigned int *malloc(unsigned int);
int /*<<< orphan*/ print_chunk(unsigned int *);
int /*<<< orphan*/ printf(char *);
int main() {
  unsigned int *ptr[15];
  unsigned int lengths[] = {0,   4,   8,    16,   24,   32,   64,   128,
                            256, 512, 1024, 2048, 4096, 8192, 16384};
  int i;
  printf("mallocing...\n");
  for (i = 0; i < 15; i++)
    ptr[i] = malloc(lengths[i]);
  for (i = 0; i < 15; i++)
    print_chunk(ptr[i]);
  printf("\nfreeing every other chunk...\n");
  for (i = 0; i < 15; i += 2)
    free(ptr[i]);
  for (i = 0; i < 15 - 1; i++)
    print_chunk(ptr[i]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xc0(%rbp),%rdi
lea    0xe90(%rip),%rsi
mov    $0x3c,%edx
call   1060 <memcpy@plt>
lea    0xebb(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0xc4(%rbp)
cmpl   $0xf,-0xc4(%rbp)
jge    11d3 <main+0x83>
movslq -0xc4(%rbp),%rax
mov    -0xc0(%rbp,%rax,4),%edi
call   1070 <malloc@plt>
mov    %rax,%rcx
movslq -0xc4(%rbp),%rax
mov    %rcx,-0x80(%rbp,%rax,8)
mov    -0xc4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc4(%rbp)
jmp    1190 <main+0x40>
movl   $0x0,-0xc4(%rbp)
cmpl   $0xf,-0xc4(%rbp)
jge    120f <main+0xbf>
movslq -0xc4(%rbp),%rax
mov    -0x80(%rbp,%rax,8),%rdi
call   1050 <print_chunk@plt>
mov    -0xc4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc4(%rbp)
jmp    11dd <main+0x8d>
lea    0xe34(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0xc4(%rbp)
cmpl   $0xf,-0xc4(%rbp)
jge    1257 <main+0x107>
movslq -0xc4(%rbp),%rax
mov    -0x80(%rbp,%rax,8),%rdi
call   1030 <free@plt>
mov    -0xc4(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0xc4(%rbp)
jmp    1225 <main+0xd5>
movl   $0x0,-0xc4(%rbp)
cmpl   $0xe,-0xc4(%rbp)
jge    1293 <main+0x143>
movslq -0xc4(%rbp),%rax
mov    -0x80(%rbp,%rax,8),%rdi
call   1050 <print_chunk@plt>
mov    -0xc4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc4(%rbp)
jmp    1261 <main+0x111>
xor    %eax,%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
lea    0xeab(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
mov    $0x4,%edi
call   1060 <malloc@plt>
mov    %rax,%rbp
mov    %rax,0x70(%rsp)
mov    $0x8,%edi
call   1060 <malloc@plt>
mov    %rax,(%rsp)
mov    $0x10,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    %rax,0x68(%rsp)
mov    $0x18,%edi
call   1060 <malloc@plt>
mov    %rax,0x48(%rsp)
mov    $0x20,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,0x60(%rsp)
mov    $0x40,%edi
call   1060 <malloc@plt>
mov    %rax,0x40(%rsp)
mov    $0x80,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    %rax,0x58(%rsp)
mov    $0x100,%edi
call   1060 <malloc@plt>
mov    %rax,0x38(%rsp)
mov    $0x200,%edi
call   1060 <malloc@plt>
mov    %rax,%r13
mov    %rax,0x50(%rsp)
mov    $0x400,%edi
call   1060 <malloc@plt>
mov    %rax,0x30(%rsp)
mov    $0x800,%edi
call   1060 <malloc@plt>
mov    %rax,0x18(%rsp)
mov    $0x1000,%edi
call   1060 <malloc@plt>
mov    %rax,0x28(%rsp)
mov    $0x2000,%edi
call   1060 <malloc@plt>
mov    %rax,0x10(%rsp)
mov    $0x4000,%edi
call   1060 <malloc@plt>
mov    %rax,0x20(%rsp)
mov    %r12,0x8(%rsp)
mov    %r12,%rdi
call   1050 <print_chunk@plt>
mov    %rbp,%rdi
call   1050 <print_chunk@plt>
mov    (%rsp),%rdi
call   1050 <print_chunk@plt>
mov    %r14,%rdi
call   1050 <print_chunk@plt>
mov    0x48(%rsp),%r14
mov    %r14,%rdi
call   1050 <print_chunk@plt>
mov    %rbx,%rdi
call   1050 <print_chunk@plt>
mov    0x40(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <print_chunk@plt>
mov    %r15,%rdi
call   1050 <print_chunk@plt>
mov    0x38(%rsp),%r12
mov    %r12,%rdi
call   1050 <print_chunk@plt>
mov    %r13,%rdi
call   1050 <print_chunk@plt>
mov    0x30(%rsp),%r13
mov    %r13,%rdi
call   1050 <print_chunk@plt>
mov    0x18(%rsp),%rdi
call   1050 <print_chunk@plt>
mov    0x28(%rsp),%r15
mov    %r15,%rdi
call   1050 <print_chunk@plt>
mov    0x10(%rsp),%rdi
call   1050 <print_chunk@plt>
mov    0x20(%rsp),%rbp
mov    %rbp,%rdi
call   1050 <print_chunk@plt>
lea    0xd22(%rip),%rdi
call   1040 <puts@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rdi
call   1050 <print_chunk@plt>
mov    0x70(%rsp),%rdi
call   1050 <print_chunk@plt>
mov    (%rsp),%rdi
call   1050 <print_chunk@plt>
mov    0x68(%rsp),%rdi
call   1050 <print_chunk@plt>
mov    %r14,%rdi
call   1050 <print_chunk@plt>
mov    0x60(%rsp),%rdi
call   1050 <print_chunk@plt>
mov    %rbx,%rdi
call   1050 <print_chunk@plt>
mov    0x58(%rsp),%rdi
call   1050 <print_chunk@plt>
mov    %r12,%rdi
call   1050 <print_chunk@plt>
mov    0x50(%rsp),%rdi
call   1050 <print_chunk@plt>
mov    %r13,%rdi
call   1050 <print_chunk@plt>
mov    0x18(%rsp),%rdi
call   1050 <print_chunk@plt>
mov    %r15,%rdi
call   1050 <print_chunk@plt>
mov    0x10(%rsp),%rdi
call   1050 <print_chunk@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.lengths = [15 x i32] [i32 0, i32 4, i32 8, i32 16, i32 24, i32 32, i32 64, i32 128, i32 256, i32 512, i32 1024, i32 2048, i32 4096, i32 8192, i32 16384]
@.str = [14 x i8] c"mallocing...\0A\00"
@.str.1 = [31 x i8] c"\0Afreeing every other chunk...\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [15 x i32*]
%3 = alloca [15 x i32]
%4 = alloca i32
store i32 0, i32* %1
%5 = bitcast [15 x i32]* %3 to i8*
%6 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
br label %7
7: ; preds = %19, %0
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 15
br i1 %9, label %10, label %22
10: ; preds = %7
%11 = load i32, i32* %4
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [15 x i32], [15 x i32]* %3, i64 0, i64 %12
%14 = load i32, i32* %13
%15 = call i32* @malloc(i32 %14)
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [15 x i32*], [15 x i32*]* %2, i64 0, i64 %17
store i32* %15, i32** %18
br label %19
19: ; preds = %10
%20 = load i32, i32* %4
%21 = add nsw i32 %20, 1
store i32 %21, i32* %4
br label %7
22: ; preds = %7
store i32 0, i32* %4
br label %23
23: ; preds = %32, %22
%24 = load i32, i32* %4
%25 = icmp slt i32 %24, 15
br i1 %25, label %26, label %35
26: ; preds = %23
%27 = load i32, i32* %4
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [15 x i32*], [15 x i32*]* %2, i64 0, i64 %28
%30 = load i32*, i32** %29
%31 = call i32 @print_chunk(i32* %30)
br label %32
32: ; preds = %26
%33 = load i32, i32* %4
%34 = add nsw i32 %33, 1
store i32 %34, i32* %4
br label %23
35: ; preds = %23
%36 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %4
br label %37
37: ; preds = %46, %35
%38 = load i32, i32* %4
%39 = icmp slt i32 %38, 15
br i1 %39, label %40, label %49
40: ; preds = %37
%41 = load i32, i32* %4
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [15 x i32*], [15 x i32*]* %2, i64 0, i64 %42
%44 = load i32*, i32** %43
%45 = call i32 @free(i32* %44)
br label %46
46: ; preds = %40
%47 = load i32, i32* %4
%48 = add nsw i32 %47, 2
store i32 %48, i32* %4
br label %37
49: ; preds = %37
store i32 0, i32* %4
br label %50
50: ; preds = %59, %49
%51 = load i32, i32* %4
%52 = icmp slt i32 %51, 14
br i1 %52, label %53, label %62
53: ; preds = %50
%54 = load i32, i32* %4
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [15 x i32*], [15 x i32*]* %2, i64 0, i64 %55
%57 = load i32*, i32** %56
%58 = call i32 @print_chunk(i32* %57)
br label %59
59: ; preds = %53
%60 = load i32, i32* %4
%61 = add nsw i32 %60, 1
store i32 %61, i32* %4
br label %50
62: ; preds = %50
ret i32 0
}

LLVM IR (-O2):
@str = [13 x i8] c"mallocing...\00"
@str.2 = [30 x i8] c"\0Afreeing every other chunk...\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%2 = tail call i32* @malloc(i32 0)
%3 = tail call i32* @malloc(i32 4)
%4 = tail call i32* @malloc(i32 8)
%5 = tail call i32* @malloc(i32 16)
%6 = tail call i32* @malloc(i32 24)
%7 = tail call i32* @malloc(i32 32)
%8 = tail call i32* @malloc(i32 64)
%9 = tail call i32* @malloc(i32 128)
%10 = tail call i32* @malloc(i32 256)
%11 = tail call i32* @malloc(i32 512)
%12 = tail call i32* @malloc(i32 1024)
%13 = tail call i32* @malloc(i32 2048)
%14 = tail call i32* @malloc(i32 4096)
%15 = tail call i32* @malloc(i32 8192)
%16 = tail call i32* @malloc(i32 16384)
%17 = tail call i32 @print_chunk(i32* %2)
%18 = tail call i32 @print_chunk(i32* %3)
%19 = tail call i32 @print_chunk(i32* %4)
%20 = tail call i32 @print_chunk(i32* %5)
%21 = tail call i32 @print_chunk(i32* %6)
%22 = tail call i32 @print_chunk(i32* %7)
%23 = tail call i32 @print_chunk(i32* %8)
%24 = tail call i32 @print_chunk(i32* %9)
%25 = tail call i32 @print_chunk(i32* %10)
%26 = tail call i32 @print_chunk(i32* %11)
%27 = tail call i32 @print_chunk(i32* %12)
%28 = tail call i32 @print_chunk(i32* %13)
%29 = tail call i32 @print_chunk(i32* %14)
%30 = tail call i32 @print_chunk(i32* %15)
%31 = tail call i32 @print_chunk(i32* %16)
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.2, i64 0, i64 0))
%33 = tail call i32 @free(i32* %2)
%34 = tail call i32 @free(i32* %4)
%35 = tail call i32 @free(i32* %6)
%36 = tail call i32 @free(i32* %8)
%37 = tail call i32 @free(i32* %10)
%38 = tail call i32 @free(i32* %12)
%39 = tail call i32 @free(i32* %14)
%40 = tail call i32 @free(i32* %16)
%41 = tail call i32 @print_chunk(i32* %2)
%42 = tail call i32 @print_chunk(i32* %3)
%43 = tail call i32 @print_chunk(i32* %4)
%44 = tail call i32 @print_chunk(i32* %5)
%45 = tail call i32 @print_chunk(i32* %6)
%46 = tail call i32 @print_chunk(i32* %7)
%47 = tail call i32 @print_chunk(i32* %8)
%48 = tail call i32 @print_chunk(i32* %9)
%49 = tail call i32 @print_chunk(i32* %10)
%50 = tail call i32 @print_chunk(i32* %11)
%51 = tail call i32 @print_chunk(i32* %12)
%52 = tail call i32 @print_chunk(i32* %13)
%53 = tail call i32 @print_chunk(i32* %14)
%54 = tail call i32 @print_chunk(i32* %15)
ret i32 0
}