#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 */
void *malloc(int);
int /*<<< orphan*/ printf(char *, int, void *);
int main() {
  int i;
  for (i = 0; i < 20; i++) {
    int j;
    void *p;
    p = malloc(512);
    printf("[%02d] malloc(512) = %p\n", i, p);
    for (j = 0; j < 512; j++)
      ((char *)p)[j] = 0;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x14,-0x8(%rbp)
jge    11a2 <main+0x82>
mov    $0x200,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%esi
mov    -0x18(%rbp),%rdx
lea    0xea4(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x200,-0xc(%rbp)
jge    118f <main+0x6f>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1168 <main+0x48>
jmp    1194 <main+0x74>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1136 <main+0x16>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
xor    %ebx,%ebx
lea    0xec2(%rip),%r14
xchg   %ax,%ax
mov    $0x200,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    %r14,%rdi
mov    %ebx,%esi
mov    %rax,%rdx
call   1030 <printf@plt>
mov    $0x200,%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
add    $0x1,%ebx
cmp    $0x14,%ebx
jne    1140 <main+0x10>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [25 x i8] c"[%02d] malloc(512) = %p\0A\00"
define i32 @main() {
br label %1
1: ; preds = %0, %1
%2 = phi i32 [ 0, %0 ], [ %5, %1 ]
%3 = tail call dereferenceable_or_null(512) i8* @malloc(i32 512)
%4 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %2, i8* %3)
%5 = add nuw nsw i32 %2, 1
%6 = icmp eq i32 %5, 20
br i1 %6, label %7, label %1
7: ; preds = %1
ret i32 0
}