#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(char *);
int getMem2(char **);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ system(char *);
int main(void) {
  char *p = NULL;
  int ret = 0;
  ret = getMem2(&p);
  if (ret != 0) {
    printf("getMem err: %d\n", ret);
    return ret;
  }
  printf("p = %s\n", p);
  if (p != NULL) {
    free(p);
    p = NULL;
  }
  printf("\n");
  system("pause");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    -0x10(%rbp),%rdi
call   1040 <getMem2@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1190 <main+0x50>
mov    -0x14(%rbp),%esi
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11df <main+0x9f>
mov    -0x10(%rbp),%rsi
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
je     11be <main+0x7e>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x10(%rbp)
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe45(%rip),%rdi
call   1050 <system@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rdi
call   1050 <getMem2@plt>
mov    %eax,%ebx
test   %eax,%eax
je     1180 <main+0x30>
lea    0xe8b(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    11c1 <main+0x71>
mov    0x8(%rsp),%rsi
lea    0xe84(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     11ab <main+0x5b>
call   1030 <free@plt>
movq   $0x0,0x8(%rsp)
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0xe5c(%rip),%rdi
call   1060 <system@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [16 x i8] c"getMem err: %d\0A\00"
@.str.1 = [8 x i8] c"p = %s\0A\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [6 x i8] c"pause\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
store i32 0, i32* %1
store i8* null, i8** %2
store i32 0, i32* %3
%4 = call i32 @getMem2(i8** %2)
store i32 %4, i32* %3
%5 = load i32, i32* %3
%6 = icmp ne i32 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = load i32, i32* %3
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = load i32, i32* %3
store i32 %10, i32* %1
br label %22
11: ; preds = %0
%12 = load i8*, i8** %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = load i8*, i8** %2
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = load i8*, i8** %2
%18 = call i32 @free(i8* %17)
store i8* null, i8** %2
br label %19
19: ; preds = %16, %11
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %1
br label %22
22: ; preds = %19, %7
%23 = load i32, i32* %1
ret i32 %23
}

LLVM IR (-O2):
@.str = [16 x i8] c"getMem err: %d\0A\00"
@.str.1 = [8 x i8] c"p = %s\0A\00"
@.str.3 = [6 x i8] c"pause\00"
define i32 @main() {
%1 = alloca i8*
%2 = bitcast i8** %1 to i8*
store i8* null, i8** %1
%3 = call i32 @getMem2(i8** %1)
%4 = icmp eq i32 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %0
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %3)
br label %17
7: ; preds = %0
%8 = load i8*, i8** %1
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%10 = load i8*, i8** %1
%11 = icmp eq i8* %10, null
br i1 %11, label %14, label %12
12: ; preds = %7
%13 = call i32 @free(i8* %10)
store i8* null, i8** %1
br label %14
14: ; preds = %12, %7
%15 = call i32 @putchar(i32 10)
%16 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %17
17: ; preds = %14, %5
ret i32 %3
}