#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_middle();
int /*<<< orphan*/ insufficient_memory_malloc();
int /*<<< orphan*/ not_malloced_free();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ redundantly_free();
int /*<<< orphan*/ valid_free();
int main(int argc, char *argv[]) {
  printf("----------------------------------------------------------\n");
  printf("Test 1: Free the memory of a variable located on the stack\n");
  not_malloced_free();
  printf("----------------------------------------------------------\n");
  printf("Test 2: Free the memory at the address which is not returned by "
         "malloc()\n");
  free_middle();
  printf("----------------------------------------------------------\n");
  printf("Test 3: Redundantly free the same address the second time\n");
  redundantly_free();
  printf("----------------------------------------------------------\n");
  printf("Test 4: Reallocate a new memory on the same freed address and free "
         "it again\n");
  valid_free();
  printf("----------------------------------------------------------\n");
  printf("Test 5: Request a great amount of memory that the library cannot "
         "provide\n");
  insufficient_memory_malloc();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe83(%rip),%rdi
call   1050 <printf@plt>
lea    0xeb3(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1030 <not_malloced_free@plt>
lea    0xe64(%rip),%rdi
call   1050 <printf@plt>
lea    0xed0(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1070 <free_middle@plt>
lea    0xe45(%rip),%rdi
call   1050 <printf@plt>
lea    0xefb(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1060 <redundantly_free@plt>
lea    0xe26(%rip),%rdi
call   1050 <printf@plt>
lea    0xf17(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1080 <valid_free@plt>
lea    0xe07(%rip),%rdi
call   1050 <printf@plt>
lea    0xf45(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1040 <insufficient_memory_malloc@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xfa2(%rip),%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0xe89(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <not_malloced_free@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0xea9(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1070 <free_middle@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0xed7(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1060 <redundantly_free@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0xef6(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1080 <valid_free@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0xf62(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <insufficient_memory_malloc@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [60 x i8] c"----------------------------------------------------------\0A\00"
@.str.1 = [60 x i8] c"Test 1: Free the memory of a variable located on the stack\0A\00"
@.str.2 = [74 x i8] c"Test 2: Free the memory at the address which is not returned by malloc()\0A\00"
@.str.3 = [59 x i8] c"Test 3: Redundantly free the same address the second time\0A\00"
@.str.4 = [77 x i8] c"Test 4: Reallocate a new memory on the same freed address and free it again\0A\00"
@.str.5 = [74 x i8] c"Test 5: Request a great amount of memory that the library cannot provide\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = call i32 @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 (...) @not_malloced_free()
%9 = call i32 @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 (...) @free_middle()
%12 = call i32 @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.3, i64 0, i64 0))
%14 = call i32 (...) @redundantly_free()
%15 = call i32 @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @printf(i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.4, i64 0, i64 0))
%17 = call i32 (...) @valid_free()
%18 = call i32 @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.5, i64 0, i64 0))
%20 = call i32 (...) @insufficient_memory_malloc()
ret i32 0
}

LLVM IR (-O2):
@str.6 = [59 x i8] c"Test 1: Free the memory of a variable located on the stack\00"
@str.8 = [73 x i8] c"Test 2: Free the memory at the address which is not returned by malloc()\00"
@str.10 = [58 x i8] c"Test 3: Redundantly free the same address the second time\00"
@str.12 = [76 x i8] c"Test 4: Reallocate a new memory on the same freed address and free it again\00"
@str.13 = [59 x i8] c"----------------------------------------------------------\00"
@str.14 = [73 x i8] c"Test 5: Request a great amount of memory that the library cannot provide\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @str.13, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @str.6, i64 0, i64 0))
%5 = tail call i32 (...) @not_malloced_free()
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @str.13, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([73 x i8], [73 x i8]* @str.8, i64 0, i64 0))
%8 = tail call i32 (...) @free_middle()
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @str.13, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @str.10, i64 0, i64 0))
%11 = tail call i32 (...) @redundantly_free()
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @str.13, i64 0, i64 0))
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([76 x i8], [76 x i8]* @str.12, i64 0, i64 0))
%14 = tail call i32 (...) @valid_free()
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @str.13, i64 0, i64 0))
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([73 x i8], [73 x i8]* @str.14, i64 0, i64 0))
%17 = tail call i32 (...) @insufficient_memory_malloc()
ret i32 0
}