#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);
int /*<<< orphan*/ free(void *);
int getpid();
void *malloc(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int i = 0;
  fprintf(stderr, "%d\n", getpid());
  sleep(30);
  for (; i < 100; i++) {
    sleep(1);
    void *p = malloc(1024000);
    printf("printf = %d\n", i);
    if (p) {
      free(p);
      p = NULL;
    }
  }
  sleep(200);
}


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,-0x14(%rbp)
mov    0x2e5c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x24(%rbp),%edi
mov    %eax,%edx
lea    0xe6d(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1e,%edi
call   1080 <sleep@plt>
cmpl   $0x64,-0x14(%rbp)
jge    120b <main+0xab>
mov    $0x1,%edi
call   1080 <sleep@plt>
mov    $0xfa000,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe29(%rip),%rdi
call   1050 <printf@plt>
cmpq   $0x0,-0x20(%rbp)
je     11f8 <main+0x98>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x20(%rbp)
jmp    11fd <main+0x9d>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11ab <main+0x4b>
mov    $0xc8,%edi
call   1080 <sleep@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2e72(%rip),%rax
mov    (%rax),%ebp
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe89(%rip),%rsi
mov    %ebp,%edi
mov    %eax,%edx
call   1060 <fprintf@plt>
mov    $0x1e,%edi
call   1080 <sleep@plt>
lea    0xe66(%rip),%r14
jmp    11a8 <main+0x48>
nopl   0x0(%rax)
add    $0x1,%ebx
cmp    $0x64,%ebx
je     11d8 <main+0x78>
mov    $0x1,%edi
call   1080 <sleep@plt>
mov    $0xfa000,%edi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    %r14,%rdi
mov    %ebx,%esi
call   1050 <printf@plt>
test   %r15,%r15
je     11a0 <main+0x40>
mov    %r15,%rdi
call   1030 <free@plt>
jmp    11a0 <main+0x40>
mov    $0xc8,%edi
call   1080 <sleep@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [13 x i8] c"printf = %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @stderr
%4 = tail call i32 (...) @getpid()
%5 = tail call i32 @fprintf(i32 %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = tail call i32 @sleep(i32 30)
br label %7
7: ; preds = %2, %15
%8 = phi i32 [ 0, %2 ], [ %16, %15 ]
%9 = tail call i32 @sleep(i32 1)
%10 = tail call dereferenceable_or_null(1024000) i8* @malloc(i32 1024000)
%11 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%12 = icmp eq i8* %10, null
br i1 %12, label %15, label %13
13: ; preds = %7
%14 = tail call i32 @free(i8* %10)
br label %15
15: ; preds = %13, %7
%16 = add nuw nsw i32 %8, 1
%17 = icmp eq i32 %16, 100
br i1 %17, label %18, label %7
18: ; preds = %15
%19 = tail call i32 @sleep(i32 200)
ret i32 0
}