#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*/ memset(void *, int, long long);
int /*<<< orphan*/ printf(char *, long long);
int random();
char *realloc(char *, long long);
int /*<<< orphan*/ sleep(int);
int main(const int argc, const char **argv) {
  long long int max_size, size, i = 0, j = 0;
  char *buffer = NULL;
  max_size = 900000;
  printf("max_size: %lld\n", max_size);
  size = 1;
  do {
    j++;
    if (j % 10000000 != 0)
      continue;
    buffer = realloc(buffer, size * 1024);
    memset((void *)buffer, 65, size * 1024);
    printf("size: %lld\n", size * 1024);
    size = random() % 900000;
    i++;
    sleep(1);
  } while (size < 2 * max_size && i < 5);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0xdbba0,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe6f(%rip),%rdi
call   1030 <printf@plt>
movq   $0x1,-0x20(%rbp)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    $0x989680,%ecx
cqto
idiv   %rcx
cmp    $0x0,%rdx
je     11c7 <main+0x77>
jmp    1232 <main+0xe2>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rsi
shl    $0xa,%rsi
call   1060 <realloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rdx
shl    $0xa,%rdx
mov    $0x41,%esi
call   1040 <memset@plt>
mov    -0x20(%rbp),%rsi
shl    $0xa,%rsi
lea    0xe03(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <random@plt>
mov    $0xdbba0,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rdx
shl    $0x1,%rdx
xor    %eax,%eax
cmp    %rdx,%rcx
mov    %al,-0x39(%rbp)
jge    1257 <main+0x107>
cmpq   $0x5,-0x28(%rbp)
setl   %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    119e <main+0x4e>
xor    %eax,%eax
add    $0x40,%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),%rdi
mov    $0xdbba0,%esi
call   1030 <printf@plt>
mov    $0xffffffffffffffff,%r13
mov    $0x1,%ebx
movabs $0xd6bf94d5e57a42bd,%rbp
94 bf d6
mov    $0x1,%r12d
xor    %r14d,%r14d
xor    %r15d,%r15d
jmp    11a2 <main+0x52>
add    $0xffffffffffffffff,%r13
add    $0x1,%rbx
cmp    $0x5,%r14
jge    1224 <main+0xd4>
mov    %rbx,%rax
mul    %rbp
shr    $0x17,%rdx
imul   $0x989680,%rdx,%rax
add    %r13,%rax
jne    1190 <main+0x40>
shl    $0xa,%r12
mov    %r15,%rdi
mov    %r12,%rsi
call   1060 <realloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    $0x41,%esi
mov    %r12,%rdx
call   1040 <memset@plt>
lea    0xe23(%rip),%rdi
mov    %r12,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
call   1050 <random@plt>
cltq
imul   $0x4a90be59,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x32,%rcx
add    %edx,%ecx
imul   $0xdbba0,%ecx,%ecx
sub    %ecx,%eax
movslq %eax,%r12
add    $0x1,%r14
mov    $0x1,%edi
call   1070 <sleep@plt>
jmp    1190 <main+0x40>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"max_size: %lld\0A\00"
@.str.1 = [12 x i8] c"size: %lld\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %8
store i64 0, i64* %9
store i8* null, i8** %10
store i64 900000, i64* %6
%11 = load i64, i64* %6
%12 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i64 %11)
store i64 1, i64* %7
br label %13
13: ; preds = %46, %2
%14 = load i64, i64* %9
%15 = add nsw i64 %14, 1
store i64 %15, i64* %9
%16 = load i64, i64* %9
%17 = srem i64 %16, 10000000
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %13
br label %38
20: ; preds = %13
%21 = load i8*, i8** %10
%22 = load i64, i64* %7
%23 = mul nsw i64 %22, 1024
%24 = call i8* @realloc(i8* %21, i64 %23)
store i8* %24, i8** %10
%25 = load i8*, i8** %10
%26 = load i64, i64* %7
%27 = mul nsw i64 %26, 1024
%28 = call i32 @memset(i8* %25, i32 65, i64 %27)
%29 = load i64, i64* %7
%30 = mul nsw i64 %29, 1024
%31 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i64 %30)
%32 = call i32 (...) @random()
%33 = srem i32 %32, 900000
%34 = sext i32 %33 to i64
store i64 %34, i64* %7
%35 = load i64, i64* %8
%36 = add nsw i64 %35, 1
store i64 %36, i64* %8
%37 = call i32 @sleep(i32 1)
br label %38
38: ; preds = %20, %19
%39 = load i64, i64* %7
%40 = load i64, i64* %6
%41 = mul nsw i64 2, %40
%42 = icmp slt i64 %39, %41
br i1 %42, label %43, label %46
43: ; preds = %38
%44 = load i64, i64* %8
%45 = icmp slt i64 %44, 5
br label %46
46: ; preds = %43, %38
%47 = phi i1 [ false, %38 ], [ %45, %43 ]
br i1 %47, label %13, label %48
48: ; preds = %46
ret i32 0
}

LLVM IR (-O2):
@.str = [16 x i8] c"max_size: %lld\0A\00"
@.str.1 = [12 x i8] c"size: %lld\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i64 900000)
br label %4
4: ; preds = %22, %2
%5 = phi i64 [ 1, %2 ], [ %23, %22 ]
%6 = phi i64 [ 0, %2 ], [ %24, %22 ]
%7 = phi i64 [ 0, %2 ], [ %9, %22 ]
%8 = phi i8* [ null, %2 ], [ %25, %22 ]
%9 = add nuw nsw i64 %7, 1
%10 = urem i64 %9, 10000000
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %22
12: ; preds = %4
%13 = shl nsw i64 %5, 10
%14 = tail call i8* @realloc(i8* %8, i64 %13)
%15 = tail call i32 @memset(i8* %14, i32 65, i64 %13)
%16 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i64 %13)
%17 = tail call i32 (...) @random()
%18 = srem i32 %17, 900000
%19 = sext i32 %18 to i64
%20 = add nsw i64 %6, 1
%21 = tail call i32 @sleep(i32 1)
br label %22
22: ; preds = %4, %12
%23 = phi i64 [ %5, %4 ], [ %19, %12 ]
%24 = phi i64 [ %6, %4 ], [ %20, %12 ]
%25 = phi i8* [ %8, %4 ], [ %14, %12 ]
%26 = icmp slt i64 %24, 5
br i1 %26, label %4, label %27
27: ; preds = %22
ret i32 0
}