#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*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sleep(int);
int main() {
  printf("malloc 20M \n");
  char *p = malloc(20 * 1024 * 1024);
  sleep(20);
  printf("malloc 20M again\n");
  char *q = malloc(20 * 1024 * 1024);
  sleep(20);
  printf("free 20M \n");
  free(p);
  sleep(20);
  printf("free 20M again\n");
  free(q);
  printf("no mem used\n");
  sleep(20);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1400000,%edi
call   1050 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    $0x14,%edi
call   1060 <sleep@plt>
lea    0xe9a(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1400000,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x14,%edi
call   1060 <sleep@plt>
lea    0xe88(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    $0x14,%edi
call   1060 <sleep@plt>
lea    0xe74(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
lea    0xe6f(%rip),%rdi
call   1040 <printf@plt>
mov    $0x14,%edi
call   1060 <sleep@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xeb5(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1400000,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    $0x14,%edi
call   1060 <sleep@plt>
lea    0xe9e(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1400000,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    $0x14,%edi
call   1060 <sleep@plt>
lea    0xe8c(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    $0x14,%edi
call   1060 <sleep@plt>
lea    0xe78(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe73(%rip),%rdi
call   1040 <puts@plt>
mov    $0x14,%edi
call   1060 <sleep@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [13 x i8] c"malloc 20M \0A\00"
@.str.1 = [18 x i8] c"malloc 20M again\0A\00"
@.str.2 = [11 x i8] c"free 20M \0A\00"
@.str.3 = [16 x i8] c"free 20M again\0A\00"
@.str.4 = [13 x i8] c"no mem used\0A\00"
define i32 @main() {
%1 = alloca i8*
%2 = alloca i8*
%3 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%4 = call i8* @malloc(i32 20971520)
store i8* %4, i8** %1
%5 = call i32 @sleep(i32 20)
%6 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%7 = call i8* @malloc(i32 20971520)
store i8* %7, i8** %2
%8 = call i32 @sleep(i32 20)
%9 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%10 = load i8*, i8** %1
%11 = call i32 @free(i8* %10)
%12 = call i32 @sleep(i32 20)
%13 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%14 = load i8*, i8** %2
%15 = call i32 @free(i8* %14)
%16 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%17 = call i32 @sleep(i32 20)
ret i32 0
}

LLVM IR (-O2):
@str = [12 x i8] c"malloc 20M \00"
@str.5 = [17 x i8] c"malloc 20M again\00"
@str.6 = [10 x i8] c"free 20M \00"
@str.7 = [15 x i8] c"free 20M again\00"
@str.8 = [12 x i8] c"no mem used\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%2 = tail call dereferenceable_or_null(20971520) i8* @malloc(i32 20971520)
%3 = tail call i32 @sleep(i32 20)
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.5, i64 0, i64 0))
%5 = tail call dereferenceable_or_null(20971520) i8* @malloc(i32 20971520)
%6 = tail call i32 @sleep(i32 20)
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.6, i64 0, i64 0))
%8 = tail call i32 @free(i8* %2)
%9 = tail call i32 @sleep(i32 20)
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.7, i64 0, i64 0))
%11 = tail call i32 @free(i8* %5)
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.8, i64 0, i64 0))
%13 = tail call i32 @sleep(i32 20)
ret i32 0
}