#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*/ printf(char *, unsigned int, unsigned int, int);
int main() {
  unsigned int lengths[] = {32, 4, 20, 0, 64, 32, 32, 32, 32, 32};
  unsigned int *ptr[10];
  int i;
  for (i = 0; i < 10; i++)
    ptr[i] = malloc(lengths[i]);
  for (i = 0; i < 9; i++)
    printf("malloc(%2d) is at 0x%08x, %3d bytes to the next pointer\n",
           lengths[i], (unsigned int)ptr[i],
           (ptr[i + 1] - ptr[i]) * sizeof(unsigned int));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xeb3(%rip),%rsi
mov    $0x28,%edx
call   1040 <memcpy@plt>
movl   $0x0,-0x84(%rbp)
cmpl   $0xa,-0x84(%rbp)
jge    11a1 <main+0x71>
movslq -0x84(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%edi
call   1050 <malloc@plt>
mov    %rax,%rcx
movslq -0x84(%rbp),%rax
mov    %rcx,-0x80(%rbp,%rax,8)
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    1161 <main+0x31>
movl   $0x0,-0x84(%rbp)
cmpl   $0x9,-0x84(%rbp)
jge    121a <main+0xea>
movslq -0x84(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%esi
movslq -0x84(%rbp),%rax
mov    -0x80(%rbp,%rax,8),%rax
mov    %eax,%edx
mov    -0x84(%rbp),%eax
add    $0x1,%eax
cltq
mov    -0x80(%rbp,%rax,8),%rax
movslq -0x84(%rbp),%rcx
mov    -0x80(%rbp,%rcx,8),%rcx
sub    %rcx,%rax
sar    $0x2,%rax
shl    $0x2,%rax
mov    %eax,%ecx
lea    0xe27(%rip),%rdi
call   1030 <printf@plt>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    11ab <main+0x7b>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    $0x20,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    $0x4,%edi
call   1040 <malloc@plt>
mov    %rax,%r13
mov    $0x14,%edi
call   1040 <malloc@plt>
mov    %rax,%r12
xor    %edi,%edi
call   1040 <malloc@plt>
mov    %rax,%r15
mov    $0x40,%edi
call   1040 <malloc@plt>
mov    %rax,%rbp
mov    $0x20,%edi
call   1040 <malloc@plt>
mov    %rax,(%rsp)
mov    $0x20,%edi
call   1040 <malloc@plt>
mov    %rax,0x8(%rsp)
mov    $0x20,%edi
call   1040 <malloc@plt>
mov    %rax,0x10(%rsp)
mov    $0x20,%edi
call   1040 <malloc@plt>
mov    %rax,0x18(%rsp)
mov    $0x20,%edi
call   1040 <malloc@plt>
mov    %rax,0x20(%rsp)
mov    %r13d,%ecx
sub    %ebx,%ecx
lea    0xe3e(%rip),%r14
mov    %r14,%rdi
mov    $0x20,%esi
mov    %ebx,%edx
call   1030 <printf@plt>
mov    %r12d,%ecx
sub    %r13d,%ecx
mov    %r14,%rdi
mov    $0x4,%esi
mov    %r13d,%edx
call   1030 <printf@plt>
mov    %r15d,%ecx
sub    %r12d,%ecx
mov    %r14,%rdi
mov    $0x14,%esi
mov    %r12d,%edx
call   1030 <printf@plt>
mov    %ebp,%ecx
sub    %r15d,%ecx
mov    %r14,%rdi
xor    %esi,%esi
mov    %r15d,%edx
call   1030 <printf@plt>
mov    (%rsp),%rbx
mov    %ebx,%ecx
sub    %ebp,%ecx
mov    %r14,%rdi
mov    $0x40,%esi
mov    %ebp,%edx
call   1030 <printf@plt>
mov    0x8(%rsp),%rbp
mov    %ebp,%ecx
sub    %ebx,%ecx
mov    %rbx,%rdx
mov    %r14,%rdi
mov    $0x20,%esi
call   1030 <printf@plt>
mov    0x10(%rsp),%rbx
mov    %ebx,%ecx
sub    %ebp,%ecx
mov    %rbp,%rdx
mov    %r14,%rdi
mov    $0x20,%esi
call   1030 <printf@plt>
mov    0x18(%rsp),%rbp
mov    %ebp,%ecx
sub    %ebx,%ecx
mov    %rbx,%rdx
mov    %r14,%rdi
mov    $0x20,%esi
call   1030 <printf@plt>
mov    0x20(%rsp),%rcx
sub    %ebp,%ecx
mov    %rbp,%rdx
mov    %r14,%rdi
mov    $0x20,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.lengths = [10 x i32] [i32 32, i32 4, i32 20, i32 0, i32 64, i32 32, i32 32, i32 32, i32 32, i32 32]
@.str = [57 x i8] c"malloc(%2d) is at 0x%08x, %3d bytes to the next pointer\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i32]
%3 = alloca [10 x i32*]
%4 = alloca i32
store i32 0, i32* %1
%5 = bitcast [10 x i32]* %2 to i8*
store i32 0, i32* %4
br label %6
6: ; preds = %18, %0
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 10
br i1 %8, label %9, label %21
9: ; preds = %6
%10 = load i32, i32* %4
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %11
%13 = load i32, i32* %12
%14 = call i32* @malloc(i32 %13)
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [10 x i32*], [10 x i32*]* %3, i64 0, i64 %16
store i32* %14, i32** %17
br label %18
18: ; preds = %9
%19 = load i32, i32* %4
%20 = add nsw i32 %19, 1
store i32 %20, i32* %4
br label %6
21: ; preds = %6
store i32 0, i32* %4
br label %22
22: ; preds = %51, %21
%23 = load i32, i32* %4
%24 = icmp slt i32 %23, 9
br i1 %24, label %25, label %54
25: ; preds = %22
%26 = load i32, i32* %4
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %27
%29 = load i32, i32* %28
%30 = load i32, i32* %4
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [10 x i32*], [10 x i32*]* %3, i64 0, i64 %31
%33 = load i32*, i32** %32
%34 = ptrtoint i32* %33 to i32
%35 = load i32, i32* %4
%36 = add nsw i32 %35, 1
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [10 x i32*], [10 x i32*]* %3, i64 0, i64 %37
%39 = load i32*, i32** %38
%40 = load i32, i32* %4
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [10 x i32*], [10 x i32*]* %3, i64 0, i64 %41
%43 = load i32*, i32** %42
%44 = ptrtoint i32* %39 to i64
%45 = ptrtoint i32* %43 to i64
%46 = sub i64 %44, %45
%47 = sdiv exact i64 %46, 4
%48 = mul i64 %47, 4
%49 = trunc i64 %48 to i32
%50 = call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 %29, i32 %34, i32 %49)
br label %51
51: ; preds = %25
%52 = load i32, i32* %4
%53 = add nsw i32 %52, 1
store i32 %53, i32* %4
br label %22
54: ; preds = %22
ret i32 0
}

LLVM IR (-O2):
@.str = [57 x i8] c"malloc(%2d) is at 0x%08x, %3d bytes to the next pointer\0A\00"
define i32 @main() {
%1 = tail call i32* @malloc(i32 32)
%2 = tail call i32* @malloc(i32 4)
%3 = tail call i32* @malloc(i32 20)
%4 = tail call i32* @malloc(i32 0)
%5 = tail call i32* @malloc(i32 64)
%6 = tail call i32* @malloc(i32 32)
%7 = tail call i32* @malloc(i32 32)
%8 = tail call i32* @malloc(i32 32)
%9 = tail call i32* @malloc(i32 32)
%10 = tail call i32* @malloc(i32 32)
%11 = ptrtoint i32* %1 to i64
%12 = trunc i64 %11 to i32
%13 = ptrtoint i32* %2 to i64
%14 = sub i64 %13, %11
%15 = trunc i64 %14 to i32
%16 = tail call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 32, i32 %12, i32 %15)
%17 = trunc i64 %13 to i32
%18 = ptrtoint i32* %3 to i64
%19 = sub i64 %18, %13
%20 = trunc i64 %19 to i32
%21 = tail call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 4, i32 %17, i32 %20)
%22 = trunc i64 %18 to i32
%23 = ptrtoint i32* %4 to i64
%24 = sub i64 %23, %18
%25 = trunc i64 %24 to i32
%26 = tail call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 20, i32 %22, i32 %25)
%27 = trunc i64 %23 to i32
%28 = ptrtoint i32* %5 to i64
%29 = sub i64 %28, %23
%30 = trunc i64 %29 to i32
%31 = tail call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 0, i32 %27, i32 %30)
%32 = trunc i64 %28 to i32
%33 = ptrtoint i32* %6 to i64
%34 = sub i64 %33, %28
%35 = trunc i64 %34 to i32
%36 = tail call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 64, i32 %32, i32 %35)
%37 = trunc i64 %33 to i32
%38 = ptrtoint i32* %7 to i64
%39 = sub i64 %38, %33
%40 = trunc i64 %39 to i32
%41 = tail call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 32, i32 %37, i32 %40)
%42 = trunc i64 %38 to i32
%43 = ptrtoint i32* %8 to i64
%44 = sub i64 %43, %38
%45 = trunc i64 %44 to i32
%46 = tail call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 32, i32 %42, i32 %45)
%47 = trunc i64 %43 to i32
%48 = ptrtoint i32* %9 to i64
%49 = sub i64 %48, %43
%50 = trunc i64 %49 to i32
%51 = tail call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 32, i32 %47, i32 %50)
%52 = trunc i64 %48 to i32
%53 = ptrtoint i32* %10 to i64
%54 = sub i64 %53, %48
%55 = trunc i64 %54 to i32
%56 = tail call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 32, i32 %52, i32 %55)
ret i32 0
}