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


x86 assembly (clang, -O0):
<get_memory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1156 <get_memory+0x36>
movq   $0x0,-0x8(%rbp)
jmp    11d4 <get_memory+0xb4>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11cc <get_memory+0xac>
mov    $0x64,%edi
call   1030 <malloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    $0x6,%edx
sub    -0x1c(%rbp),%edx
add    $0x1,%edx
mov    $0x6,%ecx
sub    -0x1c(%rbp),%ecx
add    $0x1,%ecx
mov    $0x6,%r8d
sub    -0x1c(%rbp),%r8d
add    $0x1,%r8d
lea    0xe47(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115d <get_memory+0x3d>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_memory>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%ebp
lea    0x0(,%rbp,8),%edi
call   1030 <malloc@plt>
test   %rax,%rax
je     118e <get_memory+0x6e>
mov    %rax,%r15
test   %ebp,%ebp
jle    1191 <get_memory+0x71>
mov    %ebp,%r12d
mov    $0x7,%ebp
xor    %ebx,%ebx
lea    0xead(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x64,%edi
call   1030 <malloc@plt>
mov    %rax,(%r15,%rbx,8)
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    %ebp,%ecx
mov    %ebp,%r8d
call   1040 <sprintf@plt>
add    $0x1,%rbx
add    $0xffffffff,%ebp
cmp    %rbx,%r12
jne    1160 <get_memory+0x40>
jmp    1191 <get_memory+0x71>
xor    %r15d,%r15d
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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