#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 *addChars(char *, char *);
int getStringSize(char *);
int getFibonacciNumber(int length) {
  char *number1 = "1";
  char *number2 = "1";
  char *aux;
  int term = 2;
  do {
    aux = number2;
    number2 = addChars(number1, number2);
    number1 = aux;
    term++;
  } while (getStringSize(number2) < length);
  return term;
}


x86 assembly (clang, -O0):
<getFibonacciNumber>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
lea    0xece(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xec3(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x2,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <addChars@plt>
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <getStringSize@plt>
cmp    -0x4(%rbp),%eax
jl     1148 <getFibonacciNumber+0x28>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getFibonacciNumber>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r14d
mov    $0x2,%ebx
lea    0xeca(%rip),%rbp
mov    %rbp,%rdi
nopl   0x0(%rax)
mov    %rbp,%r15
mov    %rbp,%rsi
call   1030 <addChars@plt>
mov    %rax,%rbp
add    $0x1,%ebx
mov    %rax,%rdi
call   1040 <getStringSize@plt>
mov    %r15,%rdi
cmp    %r14d,%eax
jl     1140 <getFibonacciNumber+0x20>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"1\00"
define i32 @getFibonacciNumber(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i32 %0, i32* %2
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %3
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %4
store i32 2, i32* %6
br label %7
7: ; preds = %15, %1
%8 = load i8*, i8** %4
store i8* %8, i8** %5
%9 = load i8*, i8** %3
%10 = load i8*, i8** %4
%11 = call i8* @addChars(i8* %9, i8* %10)
store i8* %11, i8** %4
%12 = load i8*, i8** %5
store i8* %12, i8** %3
%13 = load i32, i32* %6
%14 = add nsw i32 %13, 1
store i32 %14, i32* %6
br label %15
15: ; preds = %7
%16 = load i8*, i8** %4
%17 = call i32 @getStringSize(i8* %16)
%18 = load i32, i32* %2
%19 = icmp slt i32 %17, %18
br i1 %19, label %7, label %20
20: ; preds = %15
%21 = load i32, i32* %6
ret i32 %21
}

LLVM IR (-O2):
@.str = [2 x i8] c"1\00"
define i32 @getFibonacciNumber(i32 %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %1 ], [ %6, %2 ]
%4 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %1 ], [ %3, %2 ]
%5 = phi i32 [ 2, %1 ], [ %7, %2 ]
%6 = tail call i8* @addChars(i8* %4, i8* %3)
%7 = add nuw nsw i32 %5, 1
%8 = tail call i32 @getStringSize(i8* %6)
%9 = icmp slt i32 %8, %0
br i1 %9, label %2, label %10
10: ; preds = %2
ret i32 %7
}