#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_buf(char **, int);
char **getMem(int);
int /*<<< orphan*/ print_buf(char **, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ system(char *);
int main(void) {
  char **buf = NULL;
  int n = 3;
  buf = getMem(n);
  if (buf == NULL) {
    printf("getMem err\n");
    return -1;
  }
  print_buf(buf, n);
  free_buf(buf, n);
  buf = 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   $0x3,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1070 <getMem@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    119d <main+0x4d>
lea    0xe74(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11dc <main+0x8c>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <print_buf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1060 <free_buf@plt>
movq   $0x0,-0x10(%rbp)
lea    0xe46(%rip),%rdi
call   1050 <printf@plt>
lea    0xe3c(%rip),%rdi
call   1040 <system@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x3,%edi
call   1080 <getMem@plt>
test   %rax,%rax
je     11a7 <main+0x47>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x3,%esi
call   1040 <print_buf@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
call   1070 <free_buf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe62(%rip),%rdi
call   1060 <system@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe58(%rip),%rdi
call   1050 <puts@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [12 x i8] c"getMem err\0A\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [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 3, i32* %3
%4 = load i32, i32* %3
%5 = call i8** @getMem(i32 %4)
store i8** %5, i8*** %2
%6 = load i8**, i8*** %2
%7 = icmp eq i8** %6, null
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %19
10: ; preds = %0
%11 = load i8**, i8*** %2
%12 = load i32, i32* %3
%13 = call i32 @print_buf(i8** %11, i32 %12)
%14 = load i8**, i8*** %2
%15 = load i32, i32* %3
%16 = call i32 @free_buf(i8** %14, i32 %15)
store i8** null, i8*** %2
%17 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %19
19: ; preds = %10, %8
%20 = load i32, i32* %1
ret i32 %20
}

LLVM IR (-O2):
@.str.2 = [6 x i8] c"pause\00"
@str = [11 x i8] c"getMem err\00"
define i32 @main() {
%1 = tail call i8** @getMem(i32 3)
%2 = icmp eq i8** %1, null
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
br label %10
5: ; preds = %0
%6 = tail call i32 @print_buf(i8** %1, i32 3)
%7 = tail call i32 @free_buf(i8** %1, i32 3)
%8 = tail call i32 @putchar(i32 10)
%9 = tail call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %10
10: ; preds = %5, %3
%11 = phi i32 [ -1, %3 ], [ 0, %5 ]
ret i32 %11
}