#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*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ memset(char *, int, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
int main(void) {
  char *blocks[10];
  int i;
  fprintf(stderr, "Allocating blocks...\n");
  for (i = 0; i < 10; i++)
    blocks[i] = malloc(1024);
  sleep(1);
  fprintf(stderr, "Using blocks...\n");
  for (i = 0; i < 10; i++)
    memset(blocks[i], 1, 1024);
  sleep(1);
  fprintf(stderr, "Freeing block...\n");
  for (i = 10 - 1; i > 0; i--)
    ;
  free(blocks[i]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
lea    0xe91(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x64(%rbp)
cmpl   $0xa,-0x64(%rbp)
jge    11a9 <main+0x59>
mov    $0x400,%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
movslq -0x64(%rbp),%rax
mov    %rcx,-0x60(%rbp,%rax,8)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    117b <main+0x2b>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
lea    0xe53(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x64(%rbp)
cmpl   $0xa,-0x64(%rbp)
jge    11ff <main+0xaf>
movslq -0x64(%rbp),%rax
mov    -0x60(%rbp,%rax,8),%rdi
mov    $0x1,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    11cf <main+0x7f>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
lea    0xe0e(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x9,-0x64(%rbp)
cmpl   $0x0,-0x64(%rbp)
jle    1242 <main+0xf2>
jmp    1234 <main+0xe4>
mov    -0x64(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x64(%rbp)
jmp    1225 <main+0xd5>
movslq -0x64(%rbp),%rax
mov    -0x60(%rbp,%rax,8),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x70,%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    0x2e7b(%rip),%rax
mov    (%rax),%edi
lea    0xe92(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x400,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    $0x400,%edi
call   1060 <malloc@plt>
mov    %rax,%r13
mov    $0x400,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
mov    $0x400,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    $0x400,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    $0x400,%edi
call   1060 <malloc@plt>
mov    %rax,%rbp
mov    $0x400,%edi
call   1060 <malloc@plt>
mov    %rax,0x8(%rsp)
mov    $0x400,%edi
call   1060 <malloc@plt>
mov    %rax,0x10(%rsp)
mov    $0x400,%edi
call   1060 <malloc@plt>
mov    %rax,0x18(%rsp)
mov    $0x400,%edi
call   1060 <malloc@plt>
mov    %rax,0x20(%rsp)
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
lea    0xdff(%rip),%rsi
call   1050 <fprintf@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    %rbp,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    0x8(%rsp),%rdi
mov    $0x1,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    0x10(%rsp),%rdi
mov    $0x1,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    0x18(%rsp),%rdi
mov    $0x1,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    0x20(%rsp),%rdi
mov    $0x1,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    0x2cf7(%rip),%rax
mov    (%rax),%edi
lea    0xd35(%rip),%rsi
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [22 x i8] c"Allocating blocks...\0A\00"
@.str.1 = [17 x i8] c"Using blocks...\0A\00"
@.str.2 = [18 x i8] c"Freeing block...\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i8*]
%3 = alloca i32
store i32 0, i32* %1
%4 = load i32, i32* @stderr
%5 = call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %6
6: ; preds = %14, %0
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 10
br i1 %8, label %9, label %17
9: ; preds = %6
%10 = call i8* @malloc(i32 1024)
%11 = load i32, i32* %3
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [10 x i8*], [10 x i8*]* %2, i64 0, i64 %12
store i8* %10, i8** %13
br label %14
14: ; preds = %9
%15 = load i32, i32* %3
%16 = add nsw i32 %15, 1
store i32 %16, i32* %3
br label %6
17: ; preds = %6
%18 = call i32 @sleep(i32 1)
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %21
21: ; preds = %30, %17
%22 = load i32, i32* %3
%23 = icmp slt i32 %22, 10
br i1 %23, label %24, label %33
24: ; preds = %21
%25 = load i32, i32* %3
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [10 x i8*], [10 x i8*]* %2, i64 0, i64 %26
%28 = load i8*, i8** %27
%29 = call i32 @memset(i8* %28, i32 1, i32 1024)
br label %30
30: ; preds = %24
%31 = load i32, i32* %3
%32 = add nsw i32 %31, 1
store i32 %32, i32* %3
br label %21
33: ; preds = %21
%34 = call i32 @sleep(i32 1)
%35 = load i32, i32* @stderr
%36 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
store i32 9, i32* %3
br label %37
37: ; preds = %41, %33
%38 = load i32, i32* %3
%39 = icmp sgt i32 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %37
br label %41
41: ; preds = %40
%42 = load i32, i32* %3
%43 = add nsw i32 %42, -1
store i32 %43, i32* %3
br label %37
44: ; preds = %37
%45 = load i32, i32* %3
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [10 x i8*], [10 x i8*]* %2, i64 0, i64 %46
%48 = load i8*, i8** %47
%49 = call i32 @free(i8* %48)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [22 x i8] c"Allocating blocks...\0A\00"
@.str.1 = [17 x i8] c"Using blocks...\0A\00"
@.str.2 = [18 x i8] c"Freeing block...\0A\00"
define i32 @main() {
%1 = load i32, i32* @stderr
%2 = tail call i32 @fprintf(i32 %1, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%3 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%4 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%5 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%6 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%7 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%8 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%9 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%10 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%11 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%12 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%13 = tail call i32 @sleep(i32 1)
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%16 = tail call i32 @memset(i8* %3, i32 1, i32 1024)
%17 = tail call i32 @memset(i8* %4, i32 1, i32 1024)
%18 = tail call i32 @memset(i8* %5, i32 1, i32 1024)
%19 = tail call i32 @memset(i8* %6, i32 1, i32 1024)
%20 = tail call i32 @memset(i8* %7, i32 1, i32 1024)
%21 = tail call i32 @memset(i8* %8, i32 1, i32 1024)
%22 = tail call i32 @memset(i8* %9, i32 1, i32 1024)
%23 = tail call i32 @memset(i8* %10, i32 1, i32 1024)
%24 = tail call i32 @memset(i8* %11, i32 1, i32 1024)
%25 = tail call i32 @memset(i8* %12, i32 1, i32 1024)
%26 = tail call i32 @sleep(i32 1)
%27 = load i32, i32* @stderr
%28 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%29 = tail call i32 @free(i8* %3)
ret i32 0
}