#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*/ exit(int);
scalar_t__ malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int);
int get_memory(char ***ptr, int num) {
  char **tmp = NULL;
  int i;
  if (ptr == NULL)
    return -1;
  tmp = (char **)malloc(num * sizeof(char *));
  if (tmp == NULL) {
    perror("malloc");
    exit(1);
  }
  for (i = 0; i < num; i++) {
    tmp[i] = (char *)malloc(10 * sizeof(char));
    sprintf(tmp[i], "%d%d%d", i + 1, i + 1, i + 1);
  }
  *ptr = tmp;
}


x86 assembly (clang, -O0):
<get_memory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116e <get_memory+0x2e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1213 <get_memory+0xd3>
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a2 <get_memory+0x62>
lea    0xe6d(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1208 <get_memory+0xc8>
mov    $0xa,%edi
call   1030 <malloc@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x24(%rbp),%edx
add    $0x1,%edx
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
mov    -0x24(%rbp),%r8d
add    $0x1,%r8d
lea    0xe12(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11a9 <get_memory+0x69>
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_memory>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %rdi,%rdi
je     11ac <get_memory+0x6c>
mov    %esi,%ebx
mov    %rdi,%r14
lea    0x0(,%rbx,8),%edi
call   1030 <malloc@plt>
test   %rax,%rax
je     11bb <get_memory+0x7b>
mov    %rax,%r15
test   %ebx,%ebx
jle    11a9 <get_memory+0x69>
mov    %ebx,%r13d
xor    %ebx,%ebx
lea    0xe90(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1030 <malloc@plt>
mov    %rax,(%r15,%rbx,8)
add    $0x1,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
mov    %ebx,%ecx
mov    %ebx,%r8d
call   1050 <sprintf@plt>
cmp    %rbx,%r13
jne    1180 <get_memory+0x40>
mov    %r15,(%r14)
mov    $0xffffffff,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xe3e(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"malloc\00"
@.str.1 = [7 x i8] c"%d%d%d\00"
define i32 @get_memory(i8*** %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8***
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i32
store i8*** %0, i8**** %4
store i32 %1, i32* %5
store i8** null, i8*** %6
%8 = load i8***, i8**** %4
%9 = icmp eq i8*** %8, null
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 -1, i32* %3
br label %53
11: ; preds = %2
%12 = load i32, i32* %5
%13 = sext i32 %12 to i64
%14 = mul i64 %13, 8
%15 = trunc i64 %14 to i32
%16 = call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to i8**
store i8** %17, i8*** %6
%18 = load i8**, i8*** %6
%19 = icmp eq i8** %18, null
br i1 %19, label %20, label %23
20: ; preds = %11
%21 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %11
store i32 0, i32* %7
br label %24
24: ; preds = %47, %23
%25 = load i32, i32* %7
%26 = load i32, i32* %5
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %50
28: ; preds = %24
%29 = call i64 @malloc(i32 10)
%30 = inttoptr i64 %29 to i8*
%31 = load i8**, i8*** %6
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8*, i8** %31, i64 %33
store i8* %30, i8** %34
%35 = load i8**, i8*** %6
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8*, i8** %35, i64 %37
%39 = load i8*, i8** %38
%40 = load i32, i32* %7
%41 = add nsw i32 %40, 1
%42 = load i32, i32* %7
%43 = add nsw i32 %42, 1
%44 = load i32, i32* %7
%45 = add nsw i32 %44, 1
%46 = call i32 @sprintf(i8* %39, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %41, i32 %43, i32 %45)
br label %47
47: ; preds = %28
%48 = load i32, i32* %7
%49 = add nsw i32 %48, 1
store i32 %49, i32* %7
br label %24
50: ; preds = %24
%51 = load i8**, i8*** %6
%52 = load i8***, i8**** %4
store i8** %51, i8*** %52
br label %53
53: ; preds = %50, %10
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
@.str = [7 x i8] c"malloc\00"
@.str.1 = [7 x i8] c"%d%d%d\00"
define i32 @get_memory(i8*** writeonly %0, i32 %1) {
%3 = icmp eq i8*** %0, null
br i1 %3, label %26, label %4
4: ; preds = %2
%5 = shl i32 %1, 3
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to i8**
%8 = icmp eq i64 %6, 0
br i1 %8, label %13, label %9
9: ; preds = %4
%10 = icmp sgt i32 %1, 0
br i1 %10, label %11, label %25
11: ; preds = %9
%12 = zext i32 %1 to i64
br label %16
13: ; preds = %4
%14 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %11, %16
%17 = phi i64 [ 0, %11 ], [ %21, %16 ]
%18 = tail call i64 @malloc(i32 10)
%19 = inttoptr i64 %18 to i8*
%20 = getelementptr inbounds i8*, i8** %7, i64 %17
store i8* %19, i8** %20
%21 = add nuw nsw i64 %17, 1
%22 = trunc i64 %21 to i32
%23 = tail call i32 @sprintf(i8* dereferenceable(1) %19, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %22, i32 %22, i32 %22)
%24 = icmp eq i64 %21, %12
br i1 %24, label %25, label %16
25: ; preds = %16, %9
store i8** %7, i8*** %0
br label %26
26: ; preds = %2, %25
ret i32 -1
}