#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*/ add_strings_short_to_long(char *, char *, char **);
scalar_t__ calloc(int, int);
char **realloc(char **, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int strlen(char *);
void fib(int num, char ***vector) {
  *vector = realloc(*vector, (num + 1) * sizeof(char *));
  if (num < 2) {
    char *nextfib = (char *)calloc(2, sizeof(char));
    snprintf(nextfib, 2, "%d", num);
    *(nextfib + 1) = 0;
    *(*vector + num) = nextfib;
  } else {
    char *nextfib =
        (char *)calloc(strlen(*(*vector + num - 1)) + 1, sizeof(char));
    add_strings_short_to_long(*(*vector + num - 2), *(*vector + num - 1),
                              &nextfib);
    *(*vector + num) = nextfib;
  }
}


x86 assembly (clang, -O0):
<fib>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x4(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%esi
call   1070 <realloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
cmpl   $0x2,-0x4(%rbp)
jge    11d8 <fib+0x88>
mov    $0x2,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x4(%rbp),%ecx
mov    $0x2,%esi
lea    0xe4d(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x18(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movslq -0x4(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
jmp    123c <fib+0xec>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movslq -0x4(%rbp),%rcx
mov    -0x8(%rax,%rcx,8),%rdi
call   1030 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movslq -0x4(%rbp),%rcx
mov    -0x10(%rax,%rcx,8),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movslq -0x4(%rbp),%rcx
mov    -0x8(%rax,%rcx,8),%rsi
lea    -0x20(%rbp),%rdx
call   1060 <add_strings_short_to_long@plt>
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movslq -0x4(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fib>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
mov    (%rsi),%rdi
lea    0x8(,%rbx,8),%esi
call   1070 <realloc@plt>
mov    %rax,(%r14)
cmp    $0x1,%ebx
jg     11ae <fib+0x5e>
mov    $0x2,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,%r15
lea    0xe72(%rip),%rdx
mov    %rax,%rdi
mov    $0x2,%esi
mov    %ebx,%ecx
call   1040 <snprintf@plt>
movb   $0x0,0x1(%r15)
mov    (%r14),%rax
movslq %ebx,%rcx
mov    %r15,(%rax,%rcx,8)
jmp    11ef <fib+0x9f>
mov    %ebx,%ebx
mov    -0x8(%rax,%rbx,8),%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,0x8(%rsp)
mov    (%r14),%rax
mov    -0x10(%rax,%rbx,8),%rdi
mov    -0x8(%rax,%rbx,8),%rsi
lea    0x8(%rsp),%rdx
call   1060 <add_strings_short_to_long@plt>
mov    0x8(%rsp),%rax
mov    (%r14),%rcx
mov    %rax,(%rcx,%rbx,8)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define void @fib(i32 %0, i8*** nocapture %1) {
%3 = alloca i8*
%4 = load i8**, i8*** %1
%5 = shl i32 %0, 3
%6 = add i32 %5, 8
%7 = tail call i8** @realloc(i8** %4, i32 %6)
store i8** %7, i8*** %1
%8 = icmp slt i32 %0, 2
br i1 %8, label %9, label %17
9: ; preds = %2
%10 = tail call i64 @calloc(i32 2, i32 1)
%11 = inttoptr i64 %10 to i8*
%12 = tail call i32 @snprintf(i8* %11, i32 2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %0)
%13 = getelementptr inbounds i8, i8* %11, i64 1
store i8 0, i8* %13
%14 = load i8**, i8*** %1
%15 = sext i32 %0 to i64
%16 = getelementptr inbounds i8*, i8** %14, i64 %15
store i8* %11, i8** %16
br label %37
17: ; preds = %2
%18 = bitcast i8** %3 to i8*
%19 = zext i32 %0 to i64
%20 = getelementptr inbounds i8*, i8** %7, i64 %19
%21 = getelementptr inbounds i8*, i8** %20, i64 -1
%22 = load i8*, i8** %21
%23 = tail call i32 @strlen(i8* %22)
%24 = add nsw i32 %23, 1
%25 = tail call i64 @calloc(i32 %24, i32 1)
%26 = inttoptr i64 %25 to i8*
store i8* %26, i8** %3
%27 = load i8**, i8*** %1
%28 = getelementptr inbounds i8*, i8** %27, i64 %19
%29 = getelementptr inbounds i8*, i8** %28, i64 -2
%30 = load i8*, i8** %29
%31 = getelementptr inbounds i8*, i8** %28, i64 -1
%32 = load i8*, i8** %31
%33 = call i32 @add_strings_short_to_long(i8* %30, i8* %32, i8** %3)
%34 = load i8*, i8** %3
%35 = load i8**, i8*** %1
%36 = getelementptr inbounds i8*, i8** %35, i64 %19
store i8* %34, i8** %36
br label %37
37: ; preds = %17, %9
ret void
}