int main() {
  char *s = malloc(100);
  printf("s = %p; after malloc()\n", s);
  free(s);
  printf("s = %p; after free()\n", s);
  s = malloc(1000);
  printf("s = %p; after another malloc()\n", s);
  lift_free_and_null(&s);
  printf("s = %p; after lift_free_and_null()\n", s);
  s = malloc(10000);
  printf("s = %p; after yet another malloc()\n", s);
  lift_free_and_null(&(s)), sizeof *(s);
  printf("s = %p; after lift_nfree()\n", s);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x64,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rsi
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x3e8,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x10(%rbp),%rdi
mov    $0x0,%al
call   1060 <lift_free_and_null@plt>
mov    -0x10(%rbp),%rsi
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x2710,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x10(%rbp),%rdi
mov    $0x0,%al
call   1060 <lift_free_and_null@plt>
mov    -0x10(%rbp),%rsi
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    $0x64,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0xea7(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xea6(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x3e8,%edi
call   1050 <malloc@plt>
mov    %rax,0x8(%rsp)
lea    0xe9c(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <lift_free_and_null@plt>
mov    0x8(%rsp),%rsi
lea    0xe97(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x2710,%edi
call   1050 <malloc@plt>
mov    %rax,0x8(%rsp)
lea    0xe9e(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <lift_free_and_null@plt>
mov    0x8(%rsp),%rsi
lea    0xea2(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [24 x i8] c"s = %p; after malloc()\0A\00"
@.str.1 = [22 x i8] c"s = %p; after free()\0A\00"
@.str.2 = [32 x i8] c"s = %p; after another malloc()\0A\00"
@.str.3 = [36 x i8] c"s = %p; after lift_free_and_null()\0A\00"
@.str.4 = [36 x i8] c"s = %p; after yet another malloc()\0A\00"
@.str.5 = [28 x i8] c"s = %p; after lift_nfree()\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
store i32 0, i32* %1
%3 = call i8* @malloc(i64 100)
store i8* %3, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %4)
%6 = load i8*, i8** %2
%7 = load i8*, i8** %2
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%9 = call i8* @malloc(i64 1000)
store i8* %9, i8** %2
%10 = load i8*, i8** %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %10)
%12 = call i32 (i8**, ...) bitcast (i32 (...)* @lift_free_and_null to i32 (i8**, ...)*)(i8** %2)
%13 = load i8*, i8** %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i8* %13)
%15 = call i8* @malloc(i64 10000)
store i8* %15, i8** %2
%16 = load i8*, i8** %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i8* %16)
%18 = call i32 (i8**, ...) bitcast (i32 (...)* @lift_free_and_null to i32 (i8**, ...)*)(i8** %2)
%19 = load i8*, i8** %2
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i8* %19)
ret i32 0
}

LLVM IR (-O2):
@.str = [24 x i8] c"s = %p; after malloc()\0A\00"
@.str.1 = [22 x i8] c"s = %p; after free()\0A\00"
@.str.2 = [32 x i8] c"s = %p; after another malloc()\0A\00"
@.str.3 = [36 x i8] c"s = %p; after lift_free_and_null()\0A\00"
@.str.4 = [36 x i8] c"s = %p; after yet another malloc()\0A\00"
@.str.5 = [28 x i8] c"s = %p; after lift_nfree()\0A\00"
define i32 @main() {
%1 = alloca i8*
%2 = bitcast i8** %1 to i8*
%3 = tail call dereferenceable_or_null(100) i8* @malloc(i64 100)
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %3)
tail call void @free(i8* %3)
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%6 = tail call dereferenceable_or_null(1000) i8* @malloc(i64 1000)
store i8* %6, i8** %1
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%8 = call i32 (i8**, ...) bitcast (i32 (...)* @lift_free_and_null to i32 (i8**, ...)*)(i8** %1)
%9 = load i8*, i8** %1
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i8* %9)
%11 = call dereferenceable_or_null(10000) i8* @malloc(i64 10000)
store i8* %11, i8** %1
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i8* %11)
%13 = call i32 (i8**, ...) bitcast (i32 (...)* @lift_free_and_null to i32 (i8**, ...)*)(i8** %1)
%14 = load i8*, i8** %1
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i8* %14)
ret i32 0
}