#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 */
unsigned int *malloc(unsigned int);
int /*<<< orphan*/ print_chunk(unsigned int *, 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], lengths[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    0xea0(%rip),%rsi
mov    $0x3c,%edx
call   1050 <memcpy@plt>
lea    0xecb(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0xc4(%rbp)
cmpl   $0xf,-0xc4(%rbp)
jge    11c3 <main+0x83>
movslq -0xc4(%rbp),%rax
mov    -0xc0(%rbp,%rax,4),%edi
call   1060 <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    1180 <main+0x40>
movl   $0x0,-0xc4(%rbp)
cmpl   $0xf,-0xc4(%rbp)
jge    120d <main+0xcd>
movslq -0xc4(%rbp),%rax
mov    -0x80(%rbp,%rax,8),%rdi
movslq -0xc4(%rbp),%rax
mov    -0xc0(%rbp,%rax,4),%esi
call   1040 <print_chunk@plt>
mov    -0xc4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc4(%rbp)
jmp    11cd <main+0x8d>
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    $0x48,%rsp
lea    0xebb(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1050 <malloc@plt>
mov    %rax,0x40(%rsp)
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,0x38(%rsp)
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,0x30(%rsp)
mov    $0x10,%edi
call   1050 <malloc@plt>
mov    %rax,0x28(%rsp)
mov    $0x18,%edi
call   1050 <malloc@plt>
mov    %rax,0x20(%rsp)
mov    $0x20,%edi
call   1050 <malloc@plt>
mov    %rax,0x18(%rsp)
mov    $0x40,%edi
call   1050 <malloc@plt>
mov    %rax,0x10(%rsp)
mov    $0x80,%edi
call   1050 <malloc@plt>
mov    %rax,0x8(%rsp)
mov    $0x100,%edi
call   1050 <malloc@plt>
mov    %rax,(%rsp)
mov    $0x200,%edi
call   1050 <malloc@plt>
mov    %rax,%r13
mov    $0x400,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    $0x800,%edi
call   1050 <malloc@plt>
mov    %rax,%rbp
mov    $0x1000,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    $0x2000,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    $0x4000,%edi
call   1050 <malloc@plt>
mov    %rax,%r12
mov    0x40(%rsp),%rdi
xor    %esi,%esi
call   1040 <print_chunk@plt>
mov    0x38(%rsp),%rdi
mov    $0x4,%esi
call   1040 <print_chunk@plt>
mov    0x30(%rsp),%rdi
mov    $0x8,%esi
call   1040 <print_chunk@plt>
mov    0x28(%rsp),%rdi
mov    $0x10,%esi
call   1040 <print_chunk@plt>
mov    0x20(%rsp),%rdi
mov    $0x18,%esi
call   1040 <print_chunk@plt>
mov    0x18(%rsp),%rdi
mov    $0x20,%esi
call   1040 <print_chunk@plt>
mov    0x10(%rsp),%rdi
mov    $0x40,%esi
call   1040 <print_chunk@plt>
mov    0x8(%rsp),%rdi
mov    $0x80,%esi
call   1040 <print_chunk@plt>
mov    (%rsp),%rdi
mov    $0x100,%esi
call   1040 <print_chunk@plt>
mov    %r13,%rdi
mov    $0x200,%esi
call   1040 <print_chunk@plt>
mov    %rbx,%rdi
mov    $0x400,%esi
call   1040 <print_chunk@plt>
mov    %rbp,%rdi
mov    $0x800,%esi
call   1040 <print_chunk@plt>
mov    %r14,%rdi
mov    $0x1000,%esi
call   1040 <print_chunk@plt>
mov    %r15,%rdi
mov    $0x2000,%esi
call   1040 <print_chunk@plt>
mov    %r12,%rdi
mov    $0x4000,%esi
call   1040 <print_chunk@plt>
xor    %eax,%eax
add    $0x48,%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"
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 = %36, %22
%24 = load i32, i32* %4
%25 = icmp slt i32 %24, 15
br i1 %25, label %26, label %39
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 = load i32, i32* %4
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [15 x i32], [15 x i32]* %3, i64 0, i64 %32
%34 = load i32, i32* %33
%35 = call i32 @print_chunk(i32* %30, i32 %34)
br label %36
36: ; preds = %26
%37 = load i32, i32* %4
%38 = add nsw i32 %37, 1
store i32 %38, i32* %4
br label %23
39: ; preds = %23
ret i32 0
}

LLVM IR (-O2):
@str = [13 x i8] c"mallocing...\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, i32 0)
%18 = tail call i32 @print_chunk(i32* %3, i32 4)
%19 = tail call i32 @print_chunk(i32* %4, i32 8)
%20 = tail call i32 @print_chunk(i32* %5, i32 16)
%21 = tail call i32 @print_chunk(i32* %6, i32 24)
%22 = tail call i32 @print_chunk(i32* %7, i32 32)
%23 = tail call i32 @print_chunk(i32* %8, i32 64)
%24 = tail call i32 @print_chunk(i32* %9, i32 128)
%25 = tail call i32 @print_chunk(i32* %10, i32 256)
%26 = tail call i32 @print_chunk(i32* %11, i32 512)
%27 = tail call i32 @print_chunk(i32* %12, i32 1024)
%28 = tail call i32 @print_chunk(i32* %13, i32 2048)
%29 = tail call i32 @print_chunk(i32* %14, i32 4096)
%30 = tail call i32 @print_chunk(i32* %15, i32 8192)
%31 = tail call i32 @print_chunk(i32* %16, i32 16384)
ret i32 0
}