#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_debug(void *);
void *malloc_debug(int);
int /*<<< orphan*/ printf(char *);
int main() {
  void *p = malloc_debug(12);
  printf("malloc ...");
  if (p) {
    free_debug(p);
    printf("free a pointer\n");
    free_debug(p);
    printf("2 free a pointer\n");
  }
  printf("hello eyu\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0xc,%edi
call   1040 <malloc_debug@plt>
mov    %rax,-0x10(%rbp)
lea    0xeac(%rip),%rdi
call   1030 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
je     118e <main+0x5e>
mov    -0x10(%rbp),%rdi
call   1050 <free_debug@plt>
lea    0xe99(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <free_debug@plt>
lea    0xe82(%rip),%rdi
call   1030 <printf@plt>
lea    0xe88(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0xc,%edi
call   1050 <malloc_debug@plt>
mov    %rax,%rbx
lea    0xeab(%rip),%rdi
call   1040 <printf@plt>
test   %rbx,%rbx
je     1187 <main+0x47>
mov    %rbx,%rdi
call   1060 <free_debug@plt>
lea    0xea9(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1060 <free_debug@plt>
lea    0xe93(%rip),%rdi
call   1030 <puts@plt>
lea    0xe7d(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [11 x i8] c"malloc ...\00"
@.str.1 = [16 x i8] c"free a pointer\0A\00"
@.str.2 = [18 x i8] c"2 free a pointer\0A\00"
@.str.3 = [11 x i8] c"hello eyu\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
store i32 0, i32* %1
%3 = call i8* @malloc_debug(i32 12)
store i8* %3, i8** %2
%4 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%5 = load i8*, i8** %2
%6 = icmp ne i8* %5, null
br i1 %6, label %7, label %14
7: ; preds = %0
%8 = load i8*, i8** %2
%9 = call i32 @free_debug(i8* %8)
%10 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%11 = load i8*, i8** %2
%12 = call i32 @free_debug(i8* %11)
%13 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %14
14: ; preds = %7, %0
%15 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"malloc ...\00"
@str = [10 x i8] c"hello eyu\00"
@str.4 = [15 x i8] c"free a pointer\00"
@str.5 = [17 x i8] c"2 free a pointer\00"
define i32 @main() {
%1 = tail call i8* @malloc_debug(i32 12)
%2 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %1, null
br i1 %3, label %9, label %4
4: ; preds = %0
%5 = tail call i32 @free_debug(i8* %1)
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.4, i64 0, i64 0))
%7 = tail call i32 @free_debug(i8* %1)
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.5, i64 0, i64 0))
br label %9
9: ; preds = %4, %0
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
ret i32 0
}