#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 */
typedef int /*<<< orphan*/ mpz_t;

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ mpz_add(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
char *mpz_get_str(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init_set_ui(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_set(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, unsigned int);
size_t strlen(char *);
int main(int argc, char *argv[]) {
  unsigned int length = 1000;
  mpz_t n;
  mpz_t n1;
  mpz_t n2;
  mpz_init_set_ui(n, 1);
  mpz_init_set_ui(n1, 1);
  mpz_init(n2);
  unsigned int term = 2;
  bool found = false;
  while (!found) {
    mpz_add(n2, n1, n);
    mpz_set(n1, n);
    mpz_set(n, n2);
    char *str = mpz_get_str(NULL, 10, n);
    size_t curr_len = strlen(str);
    free(str);
    if (curr_len >= length) {
      found = true;
    }
    term++;
  }
  printf("%u", term);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x3e8,-0x14(%rbp)
mov    -0x18(%rbp),%edi
mov    $0x1,%esi
call   10a0 <mpz_init_set_ui@plt>
mov    -0x1c(%rbp),%edi
mov    $0x1,%esi
call   10a0 <mpz_init_set_ui@plt>
mov    -0x20(%rbp),%edi
call   1070 <mpz_init@plt>
movl   $0x2,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11e3 <main+0x63>
jmp    1257 <main+0xd7>
mov    -0x20(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1090 <mpz_add@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1040 <mpz_set@plt>
mov    -0x18(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1040 <mpz_set@plt>
mov    -0x18(%rbp),%edx
xor    %eax,%eax
mov    %eax,%edi
mov    $0xa,%esi
call   1080 <mpz_get_str@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rax
mov    -0x14(%rbp),%ecx
cmp    %rcx,%rax
jb     1249 <main+0xc9>
movl   $0x1,-0x28(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11cd <main+0x4d>
mov    -0x24(%rbp),%esi
lea    0xd9f(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    $0x1,%esi
call   10a0 <mpz_init_set_ui@plt>
mov    $0x1,%esi
call   10a0 <mpz_init_set_ui@plt>
call   1070 <mpz_init@plt>
mov    $0x2,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
call   1090 <mpz_add@plt>
call   1040 <mpz_set@plt>
call   1040 <mpz_set@plt>
xor    %edi,%edi
mov    $0xa,%esi
call   1080 <mpz_get_str@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <strlen@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <free@plt>
add    $0x1,%ebp
cmp    $0x3e8,%r14
jb     11b0 <main+0x30>
lea    0xe0c(%rip),%rdi
mov    %ebp,%esi
call   1060 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%u\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1000, i32* %6
%14 = load i32, i32* %7
%15 = call i32 @mpz_init_set_ui(i32 %14, i32 1)
%16 = load i32, i32* %8
%17 = call i32 @mpz_init_set_ui(i32 %16, i32 1)
%18 = load i32, i32* %9
%19 = call i32 @mpz_init(i32 %18)
store i32 2, i32* %10
store i32 0, i32* %11
br label %20
20: ; preds = %46, %2
%21 = load i32, i32* %11
%22 = icmp ne i32 %21, 0
%23 = xor i1 %22, true
br i1 %23, label %24, label %49
24: ; preds = %20
%25 = load i32, i32* %9
%26 = load i32, i32* %8
%27 = load i32, i32* %7
%28 = call i32 @mpz_add(i32 %25, i32 %26, i32 %27)
%29 = load i32, i32* %8
%30 = load i32, i32* %7
%31 = call i32 @mpz_set(i32 %29, i32 %30)
%32 = load i32, i32* %7
%33 = load i32, i32* %9
%34 = call i32 @mpz_set(i32 %32, i32 %33)
%35 = load i32, i32* %7
%36 = call i8* @mpz_get_str(i32* null, i32 10, i32 %35)
store i8* %36, i8** %12
%37 = load i8*, i8** %12
%38 = call i64 @strlen(i8* %37)
store i64 %38, i64* %13
%39 = load i8*, i8** %12
%40 = call i32 @free(i8* %39)
%41 = load i64, i64* %13
%42 = load i32, i32* %6
%43 = zext i32 %42 to i64
%44 = icmp uge i64 %41, %43
br i1 %44, label %45, label %46
45: ; preds = %24
store i32 1, i32* %11
br label %46
46: ; preds = %45, %24
%47 = load i32, i32* %10
%48 = add i32 %47, 1
store i32 %48, i32* %10
br label %20
49: ; preds = %20
%50 = load i32, i32* %10
%51 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %50)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%u\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @mpz_init_set_ui(i32 undef, i32 1)
%4 = tail call i32 @mpz_init_set_ui(i32 undef, i32 1)
%5 = tail call i32 @mpz_init(i32 undef)
br label %6
6: ; preds = %2, %6
%7 = phi i32 [ 2, %2 ], [ %15, %6 ]
%8 = tail call i32 @mpz_add(i32 undef, i32 undef, i32 undef)
%9 = tail call i32 @mpz_set(i32 undef, i32 undef)
%10 = tail call i32 @mpz_set(i32 undef, i32 undef)
%11 = tail call i8* @mpz_get_str(i32* null, i32 10, i32 undef)
%12 = tail call i64 @strlen(i8* dereferenceable(1) %11)
%13 = tail call i32 @free(i8* %11)
%14 = icmp ult i64 %12, 1000
%15 = add i32 %7, 1
br i1 %14, label %6, label %16
16: ; preds = %6
%17 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %15)
ret i32 0
}