#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 */
char *calloc(int, int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  char *p;
  char *q;
  int num = 0;
  while (num < 512) {
    printf("%d\n", num);
    p = calloc(128, 1);
    q = calloc(128, 1);
    int i = 0;
    while (i < num) {
      *(p + i) = 'a';
      i++;
    }
    printf("zzzz\n");
    free(p);
    printf("aaaa\n");
    free(q);
    num++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x200,-0x24(%rbp)
jge    11fa <main+0xca>
mov    -0x24(%rbp),%esi
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x80,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x80,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11be <main+0x8e>
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
movb   $0x61,(%rax,%rcx,1)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1198 <main+0x68>
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    114d <main+0x1d>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe9e(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x80,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,%rbx
mov    $0x80,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,%r13
lea    0xe6b(%rip),%r15
mov    %r15,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe59(%rip),%r12
mov    %r12,%rdi
call   1040 <puts@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x80,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,%r13
mov    $0x80,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,%rbp
mov    %r13,%rdi
mov    $0x61,%esi
mov    %rbx,%rdx
call   1060 <memset@plt>
mov    %r15,%rdi
call   1040 <puts@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1040 <puts@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
add    $0x1,%rbx
cmp    $0x200,%rbx
jne    11d0 <main+0x80>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
@str = [5 x i8] c"zzzz\00"
@str.3 = [5 x i8] c"aaaa\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 0)
%4 = tail call dereferenceable_or_null(128) i8* @calloc(i32 128, i32 1)
%5 = tail call dereferenceable_or_null(128) i8* @calloc(i32 128, i32 1)
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 @free(i8* %4)
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.3, i64 0, i64 0))
%9 = tail call i32 @free(i8* %5)
br label %10
10: ; preds = %2, %10
%11 = phi i64 [ 1, %2 ], [ %20, %10 ]
%12 = trunc i64 %11 to i32
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = tail call dereferenceable_or_null(128) i8* @calloc(i32 128, i32 1)
%15 = tail call dereferenceable_or_null(128) i8* @calloc(i32 128, i32 1)
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
%17 = tail call i32 @free(i8* %14)
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.3, i64 0, i64 0))
%19 = tail call i32 @free(i8* %15)
%20 = add nuw nsw i64 %11, 1
%21 = icmp eq i64 %20, 512
br i1 %21, label %22, label %10
22: ; preds = %10
ret i32 0
}