#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*/ __lsan_do_leak_check();
int /*<<< orphan*/ free(unsigned int *);
unsigned int *malloc(int);
int /*<<< orphan*/ usleep(int);
void main(void) {
  unsigned int *p1, *p2, i = 0;
  while (1) {
    p1 = malloc(4096 * 3);
    p1[0] = 0;
    p1[1024] = 1;
    p1[1024 * 2] = 2;
    p2 = malloc(1024);
    p2[0] = 1;
    free(p2);
    usleep(10000);
    if (i++ == 10)
      __lsan_do_leak_check();
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x14(%rbp)
mov    $0x3000,%edi
call   1040 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x8(%rbp),%rax
movl   $0x1,0x1000(%rax)
mov    -0x8(%rbp),%rax
movl   $0x2,0x2000(%rax)
mov    $0x400,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    $0x2710,%edi
call   1060 <usleep@plt>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0xa,%eax
jne    11c9 <main+0x89>
mov    $0x0,%al
call   1050 <__lsan_do_leak_check@plt>
jmp    114f <main+0xf>

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0xa,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    $0x3000,%edi
call   1040 <malloc@plt>
movl   $0x0,(%rax)
movl   $0x1,0x1000(%rax)
movl   $0x2,0x2000(%rax)
mov    $0x400,%edi
call   1040 <malloc@plt>
movl   $0x1,(%rax)
mov    %rax,%rdi
call   1030 <free@plt>
mov    $0x2710,%edi
call   1060 <usleep@plt>
sub    $0x1,%ebx
jae    1150 <main+0x10>
xor    %eax,%eax
call   1050 <__lsan_do_leak_check@plt>
jmp    1150 <main+0x10>

LLVM IR (-O0):
define void @main() {
%1 = alloca i32*
%2 = alloca i32*
%3 = alloca i32
store i32 0, i32* %3
br label %4
4: ; preds = %0, %23
%5 = call i32* @malloc(i32 12288)
store i32* %5, i32** %1
%6 = load i32*, i32** %1
%7 = getelementptr inbounds i32, i32* %6, i64 0
store i32 0, i32* %7
%8 = load i32*, i32** %1
%9 = getelementptr inbounds i32, i32* %8, i64 1024
store i32 1, i32* %9
%10 = load i32*, i32** %1
%11 = getelementptr inbounds i32, i32* %10, i64 2048
store i32 2, i32* %11
%12 = call i32* @malloc(i32 1024)
store i32* %12, i32** %2
%13 = load i32*, i32** %2
%14 = getelementptr inbounds i32, i32* %13, i64 0
store i32 1, i32* %14
%15 = load i32*, i32** %2
%16 = call i32 @free(i32* %15)
%17 = call i32 @usleep(i32 10000)
%18 = load i32, i32* %3
%19 = add i32 %18, 1
store i32 %19, i32* %3
%20 = icmp eq i32 %18, 10
br i1 %20, label %21, label %23
21: ; preds = %4
%22 = call i32 (...) @__lsan_do_leak_check()
br label %23
23: ; preds = %21, %4
br label %4
}

LLVM IR (-O2):
define void @main() {
br label %1
1: ; preds = %13, %0
%2 = phi i32 [ 0, %0 ], [ %9, %13 ]
%3 = tail call i32* @malloc(i32 12288)
store i32 0, i32* %3
%4 = getelementptr inbounds i32, i32* %3, i64 1024
store i32 1, i32* %4
%5 = getelementptr inbounds i32, i32* %3, i64 2048
store i32 2, i32* %5
%6 = tail call i32* @malloc(i32 1024)
store i32 1, i32* %6
%7 = tail call i32 @free(i32* %6)
%8 = tail call i32 @usleep(i32 10000)
%9 = add i32 %2, 1
%10 = icmp eq i32 %2, 10
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = tail call i32 (...) @__lsan_do_leak_check()
br label %13
13: ; preds = %11, %1
br label %1
}