#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*/ __safeFree(void **);
int /*<<< orphan*/ printf(char *, int *);
scalar_t__ safeMalloc(int);
int main(int argc, char *argv[]) {
  int *pi = (int *)safeMalloc(1 * sizeof(int));
  *pi = 5;
  printf("Before: %p\n", pi);
  __safeFree((void **)&(pi));
  printf("After: %p\n", pi);
  __safeFree((void **)&(pi));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x4,%edi
call   1030 <safeMalloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x5,(%rax)
mov    -0x18(%rbp),%rsi
lea    0xe97(%rip),%rdi
call   1040 <printf@plt>
lea    -0x18(%rbp),%rdi
call   1050 <__safeFree@plt>
mov    -0x18(%rbp),%rsi
lea    0xe8a(%rip),%rdi
call   1040 <printf@plt>
lea    -0x18(%rbp),%rdi
call   1050 <__safeFree@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    $0x4,%edi
call   1030 <safeMalloc@plt>
mov    %rax,0x8(%rsp)
movl   $0x5,(%rax)
lea    0xeaf(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <__safeFree@plt>
mov    0x8(%rsp),%rsi
lea    0xe9a(%rip),%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1050 <__safeFree@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [12 x i8] c"Before: %p\0A\00"
@.str.1 = [11 x i8] c"After: %p\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i64 @safeMalloc(i32 4)
%8 = inttoptr i64 %7 to i32*
store i32* %8, i32** %6
%9 = load i32*, i32** %6
store i32 5, i32* %9
%10 = load i32*, i32** %6
%11 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32* %10)
%12 = bitcast i32** %6 to i8**
%13 = call i32 @__safeFree(i8** %12)
%14 = load i32*, i32** %6
%15 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32* %14)
%16 = bitcast i32** %6 to i8**
%17 = call i32 @__safeFree(i8** %16)
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"Before: %p\0A\00"
@.str.1 = [11 x i8] c"After: %p\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32*
%4 = bitcast i32** %3 to i8*
%5 = tail call i64 @safeMalloc(i32 4)
%6 = inttoptr i64 %5 to i32*
store i32* %6, i32** %3
store i32 5, i32* %6
%7 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32* %6)
%8 = bitcast i32** %3 to i8**
%9 = call i32 @__safeFree(i8** %8)
%10 = load i32*, i32** %3
%11 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32* %10)
%12 = call i32 @__safeFree(i8** %8)
ret i32 0
}