#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ print_list();
int /*<<< orphan*/ printf(char *);
int main(int argc, char **argv) {
  printf("\n---- Running test1 ---\n");
  printf("Before any allocation\n");
  print_list();
  int *mem1 = (int *)malloc(8);
  *mem1 = 10;
  printf("mem1 = malloc(8)\n");
  print_list();
  int *mem2 = (int *)malloc(8);
  *mem2 = 11;
  printf("mem2 = malloc(8)\n");
  print_list();
  int *mem3 = (int *)malloc(8);
  *mem3 = 12;
  printf("mem3 = malloc(8)\n");
  print_list();
  free(mem2);
  printf("free(mem2))\n");
  print_list();
  free(mem1);
  printf("free(mem1))\n");
  print_list();
  free(mem3);
  printf("free(mem3))\n");
  print_list();
  exit(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)
lea    0xe93(%rip),%rdi
call   1050 <printf@plt>
lea    0xea0(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1040 <print_list@plt>
mov    $0x8,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movl   $0xa,(%rax)
lea    0xe8c(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1040 <print_list@plt>
mov    $0x8,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movl   $0xb,(%rax)
lea    0xe73(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1040 <print_list@plt>
mov    $0x8,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movl   $0xc,(%rax)
lea    0xe5a(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1040 <print_list@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
lea    0xe50(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1040 <print_list@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
lea    0xe41(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1040 <print_list@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
lea    0xe32(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1040 <print_list@plt>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
lea    0xea4(%rip),%rdi
call   1040 <puts@plt>
lea    0xeb0(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1050 <print_list@plt>
mov    $0x8,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
movl   $0xa,(%rax)
lea    0xea0(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1050 <print_list@plt>
mov    $0x8,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
movl   $0xb,(%rax)
lea    0xe8b(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1050 <print_list@plt>
mov    $0x8,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
movl   $0xc,(%rax)
lea    0xe76(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1050 <print_list@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe6c(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1050 <print_list@plt>
mov    %r14,%rdi
call   1030 <free@plt>
lea    0xe5d(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1050 <print_list@plt>
mov    %r15,%rdi
call   1030 <free@plt>
lea    0xe4e(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1050 <print_list@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"\0A---- Running test1 ---\0A\00"
@.str.1 = [23 x i8] c"Before any allocation\0A\00"
@.str.2 = [18 x i8] c"mem1 = malloc(8)\0A\00"
@.str.3 = [18 x i8] c"mem2 = malloc(8)\0A\00"
@.str.4 = [18 x i8] c"mem3 = malloc(8)\0A\00"
@.str.5 = [13 x i8] c"free(mem2))\0A\00"
@.str.6 = [13 x i8] c"free(mem1))\0A\00"
@.str.7 = [13 x i8] c"free(mem3))\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 (...) @print_list()
%12 = call i64 @malloc(i32 8)
%13 = inttoptr i64 %12 to i32*
store i32* %13, i32** %6
%14 = load i32*, i32** %6
store i32 10, i32* %14
%15 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 (...) @print_list()
%17 = call i64 @malloc(i32 8)
%18 = inttoptr i64 %17 to i32*
store i32* %18, i32** %7
%19 = load i32*, i32** %7
store i32 11, i32* %19
%20 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%21 = call i32 (...) @print_list()
%22 = call i64 @malloc(i32 8)
%23 = inttoptr i64 %22 to i32*
store i32* %23, i32** %8
%24 = load i32*, i32** %8
store i32 12, i32* %24
%25 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%26 = call i32 (...) @print_list()
%27 = load i32*, i32** %7
%28 = call i32 @free(i32* %27)
%29 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%30 = call i32 (...) @print_list()
%31 = load i32*, i32** %6
%32 = call i32 @free(i32* %31)
%33 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%34 = call i32 (...) @print_list()
%35 = load i32*, i32** %8
%36 = call i32 @free(i32* %35)
%37 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
%38 = call i32 (...) @print_list()
%39 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@str = [24 x i8] c"\0A---- Running test1 ---\00"
@str.8 = [22 x i8] c"Before any allocation\00"
@str.9 = [17 x i8] c"mem1 = malloc(8)\00"
@str.10 = [17 x i8] c"mem2 = malloc(8)\00"
@str.11 = [17 x i8] c"mem3 = malloc(8)\00"
@str.12 = [12 x i8] c"free(mem2))\00"
@str.13 = [12 x i8] c"free(mem1))\00"
@str.14 = [12 x i8] c"free(mem3))\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.8, i64 0, i64 0))
%5 = tail call i32 (...) @print_list()
%6 = tail call i64 @malloc(i32 8)
%7 = inttoptr i64 %6 to i32*
store i32 10, i32* %7
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.9, i64 0, i64 0))
%9 = tail call i32 (...) @print_list()
%10 = tail call i64 @malloc(i32 8)
%11 = inttoptr i64 %10 to i32*
store i32 11, i32* %11
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.10, i64 0, i64 0))
%13 = tail call i32 (...) @print_list()
%14 = tail call i64 @malloc(i32 8)
%15 = inttoptr i64 %14 to i32*
store i32 12, i32* %15
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.11, i64 0, i64 0))
%17 = tail call i32 (...) @print_list()
%18 = tail call i32 @free(i32* %11)
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.12, i64 0, i64 0))
%20 = tail call i32 (...) @print_list()
%21 = tail call i32 @free(i32* %7)
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.13, i64 0, i64 0))
%23 = tail call i32 (...) @print_list()
%24 = tail call i32 @free(i32* %15)
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.14, i64 0, i64 0))
%26 = tail call i32 (...) @print_list()
%27 = tail call i32 @exit(i32 0)
unreachable
}