#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*/);
int /*<<< orphan*/ mpz_fib2_ui(int /*<<< orphan*/, int /*<<< orphan*/,
                               int /*<<< orphan*/);
char *mpz_get_str(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
int mpz_sizeinbase(int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, int);
int strlen(char *);
int main(int argc, char **argv) {
  int n = 12;
  char *s = NULL;
  mpz_t f1, f2, f3;
  mpz_init(f1);
  mpz_init(f2);
  mpz_init(f3);
  mpz_fib2_ui(f2, f1, n++);
  while (1) {
    mpz_add(f3, f1, f2);
    if (mpz_sizeinbase(f3, 10) >= 1000) {
      s = mpz_get_str(NULL, 10, f3);
      if (strlen(s) == 1000) {
        printf("%d\n", n);
        break;
      }
      free(s);
    }
    mpz_add(f1, f2, f3);
    if (mpz_sizeinbase(f1, 10) >= 1000) {
      s = mpz_get_str(NULL, 10, f2);
      if (strlen(s) == 1000) {
        printf("%d\n", n + 1);
        break;
      }
      free(s);
    }
    mpz_add(f2, f3, f1);
    if (mpz_sizeinbase(f2, 10) >= 1000) {
      s = mpz_get_str(NULL, 10, f2);
      if (strlen(s) == 1000) {
        printf("%d\n", n + 2);
        break;
      }
      free(s);
    }
    n += 3;
  }
  free(s);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xc,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x24(%rbp),%edi
call   1070 <mpz_init@plt>
mov    -0x28(%rbp),%edi
call   1070 <mpz_init@plt>
mov    -0x2c(%rbp),%edi
call   1070 <mpz_init@plt>
mov    -0x28(%rbp),%edi
mov    -0x24(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    %edx,%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
call   1040 <mpz_fib2_ui@plt>
mov    -0x2c(%rbp),%edi
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
call   1090 <mpz_add@plt>
mov    -0x2c(%rbp),%edi
mov    $0xa,%esi
call   10a0 <mpz_sizeinbase@plt>
cmp    $0x3e8,%eax
jl     123f <main+0xbf>
mov    -0x2c(%rbp),%edx
xor    %eax,%eax
mov    %eax,%edi
mov    $0xa,%esi
call   1080 <mpz_get_str@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x3e8,%eax
jne    1236 <main+0xb6>
mov    -0x14(%rbp),%esi
lea    0xdd4(%rip),%rdi
call   1060 <printf@plt>
jmp    132b <main+0x1ab>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%edi
mov    -0x28(%rbp),%esi
mov    -0x2c(%rbp),%edx
call   1090 <mpz_add@plt>
mov    -0x24(%rbp),%edi
mov    $0xa,%esi
call   10a0 <mpz_sizeinbase@plt>
cmp    $0x3e8,%eax
jl     12ae <main+0x12e>
mov    -0x28(%rbp),%edx
xor    %eax,%eax
mov    %eax,%edi
mov    $0xa,%esi
call   1080 <mpz_get_str@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x3e8,%eax
jne    12a5 <main+0x125>
mov    -0x14(%rbp),%esi
add    $0x1,%esi
lea    0xd65(%rip),%rdi
call   1060 <printf@plt>
jmp    132b <main+0x1ab>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%edi
mov    -0x2c(%rbp),%esi
mov    -0x24(%rbp),%edx
call   1090 <mpz_add@plt>
mov    -0x28(%rbp),%edi
mov    $0xa,%esi
call   10a0 <mpz_sizeinbase@plt>
cmp    $0x3e8,%eax
jl     131d <main+0x19d>
mov    -0x28(%rbp),%edx
xor    %eax,%eax
mov    %eax,%edi
mov    $0xa,%esi
call   1080 <mpz_get_str@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x3e8,%eax
jne    1314 <main+0x194>
mov    -0x14(%rbp),%esi
add    $0x2,%esi
lea    0xcf6(%rip),%rdi
call   1060 <printf@plt>
jmp    132b <main+0x1ab>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x14(%rbp)
jmp    11d3 <main+0x53>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
call   1070 <mpz_init@plt>
call   1070 <mpz_init@plt>
call   1070 <mpz_init@plt>
mov    $0xc,%edx
call   1040 <mpz_fib2_ui@plt>
mov    $0xd,%ebp
jmp    11b3 <main+0x33>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x3,%ebp
call   1090 <mpz_add@plt>
mov    $0xa,%esi
call   10a0 <mpz_sizeinbase@plt>
cmp    $0x3e8,%eax
jl     11f3 <main+0x73>
xor    %edi,%edi
mov    $0xa,%esi
call   1080 <mpz_get_str@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <strlen@plt>
cmp    $0x3e8,%eax
je     127c <main+0xfc>
mov    %rbx,%rdi
call   1030 <free@plt>
call   1090 <mpz_add@plt>
mov    $0xa,%esi
call   10a0 <mpz_sizeinbase@plt>
cmp    $0x3e8,%eax
jl     122f <main+0xaf>
xor    %edi,%edi
mov    $0xa,%esi
call   1080 <mpz_get_str@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <strlen@plt>
cmp    $0x3e8,%eax
je     1274 <main+0xf4>
mov    %rbx,%rdi
call   1030 <free@plt>
call   1090 <mpz_add@plt>
mov    $0xa,%esi
call   10a0 <mpz_sizeinbase@plt>
cmp    $0x3e8,%eax
jl     11b0 <main+0x30>
xor    %edi,%edi
mov    $0xa,%esi
call   1080 <mpz_get_str@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <strlen@plt>
cmp    $0x3e8,%eax
je     1279 <main+0xf9>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    11b0 <main+0x30>
add    $0x1,%ebp
jmp    127c <main+0xfc>
add    $0x2,%ebp
lea    0xd7d(%rip),%rdi
mov    %ebp,%esi
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 12, i32* %6
store i8* null, i8** %7
%11 = load i32, i32* %8
%12 = call i32 @mpz_init(i32 %11)
%13 = load i32, i32* %9
%14 = call i32 @mpz_init(i32 %13)
%15 = load i32, i32* %10
%16 = call i32 @mpz_init(i32 %15)
%17 = load i32, i32* %9
%18 = load i32, i32* %8
%19 = load i32, i32* %6
%20 = add nsw i32 %19, 1
store i32 %20, i32* %6
%21 = call i32 @mpz_fib2_ui(i32 %17, i32 %18, i32 %19)
br label %22
22: ; preds = %2, %84
%23 = load i32, i32* %10
%24 = load i32, i32* %8
%25 = load i32, i32* %9
%26 = call i32 @mpz_add(i32 %23, i32 %24, i32 %25)
%27 = load i32, i32* %10
%28 = call i32 @mpz_sizeinbase(i32 %27, i32 10)
%29 = icmp sge i32 %28, 1000
br i1 %29, label %30, label %42
30: ; preds = %22
%31 = load i32, i32* %10
%32 = call i8* @mpz_get_str(i32* null, i32 10, i32 %31)
store i8* %32, i8** %7
%33 = load i8*, i8** %7
%34 = call i32 @strlen(i8* %33)
%35 = icmp eq i32 %34, 1000
br i1 %35, label %36, label %39
36: ; preds = %30
%37 = load i32, i32* %6
%38 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %37)
br label %87
39: ; preds = %30
%40 = load i8*, i8** %7
%41 = call i32 @free(i8* %40)
br label %42
42: ; preds = %39, %22
%43 = load i32, i32* %8
%44 = load i32, i32* %9
%45 = load i32, i32* %10
%46 = call i32 @mpz_add(i32 %43, i32 %44, i32 %45)
%47 = load i32, i32* %8
%48 = call i32 @mpz_sizeinbase(i32 %47, i32 10)
%49 = icmp sge i32 %48, 1000
br i1 %49, label %50, label %63
50: ; preds = %42
%51 = load i32, i32* %9
%52 = call i8* @mpz_get_str(i32* null, i32 10, i32 %51)
store i8* %52, i8** %7
%53 = load i8*, i8** %7
%54 = call i32 @strlen(i8* %53)
%55 = icmp eq i32 %54, 1000
br i1 %55, label %56, label %60
56: ; preds = %50
%57 = load i32, i32* %6
%58 = add nsw i32 %57, 1
%59 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %58)
br label %87
60: ; preds = %50
%61 = load i8*, i8** %7
%62 = call i32 @free(i8* %61)
br label %63
63: ; preds = %60, %42
%64 = load i32, i32* %9
%65 = load i32, i32* %10
%66 = load i32, i32* %8
%67 = call i32 @mpz_add(i32 %64, i32 %65, i32 %66)
%68 = load i32, i32* %9
%69 = call i32 @mpz_sizeinbase(i32 %68, i32 10)
%70 = icmp sge i32 %69, 1000
br i1 %70, label %71, label %84
71: ; preds = %63
%72 = load i32, i32* %9
%73 = call i8* @mpz_get_str(i32* null, i32 10, i32 %72)
store i8* %73, i8** %7
%74 = load i8*, i8** %7
%75 = call i32 @strlen(i8* %74)
%76 = icmp eq i32 %75, 1000
br i1 %76, label %77, label %81
77: ; preds = %71
%78 = load i32, i32* %6
%79 = add nsw i32 %78, 2
%80 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %79)
br label %87
81: ; preds = %71
%82 = load i8*, i8** %7
%83 = call i32 @free(i8* %82)
br label %84
84: ; preds = %81, %63
%85 = load i32, i32* %6
%86 = add nsw i32 %85, 3
store i32 %86, i32* %6
br label %22
87: ; preds = %77, %56, %36
%88 = load i8*, i8** %7
%89 = call i32 @free(i8* %88)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @mpz_init(i32 undef)
%4 = tail call i32 @mpz_init(i32 undef)
%5 = tail call i32 @mpz_init(i32 undef)
%6 = tail call i32 @mpz_fib2_ui(i32 undef, i32 undef, i32 12)
br label %7
7: ; preds = %42, %2
%8 = phi i32 [ 13, %2 ], [ %43, %42 ]
%9 = tail call i32 @mpz_add(i32 undef, i32 undef, i32 undef)
%10 = tail call i32 @mpz_sizeinbase(i32 undef, i32 10)
%11 = icmp sgt i32 %10, 999
br i1 %11, label %12, label %18
12: ; preds = %7
%13 = tail call i8* @mpz_get_str(i32* null, i32 10, i32 undef)
%14 = tail call i32 @strlen(i8* %13)
%15 = icmp eq i32 %14, 1000
br i1 %15, label %44, label %16
16: ; preds = %12
%17 = tail call i32 @free(i8* %13)
br label %18
18: ; preds = %16, %7
%19 = tail call i32 @mpz_add(i32 undef, i32 undef, i32 undef)
%20 = tail call i32 @mpz_sizeinbase(i32 undef, i32 10)
%21 = icmp sgt i32 %20, 999
br i1 %21, label %22, label %30
22: ; preds = %18
%23 = tail call i8* @mpz_get_str(i32* null, i32 10, i32 undef)
%24 = tail call i32 @strlen(i8* %23)
%25 = icmp eq i32 %24, 1000
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = add nuw nsw i32 %8, 1
br label %44
28: ; preds = %22
%29 = tail call i32 @free(i8* %23)
br label %30
30: ; preds = %28, %18
%31 = tail call i32 @mpz_add(i32 undef, i32 undef, i32 undef)
%32 = tail call i32 @mpz_sizeinbase(i32 undef, i32 10)
%33 = icmp sgt i32 %32, 999
br i1 %33, label %34, label %42
34: ; preds = %30
%35 = tail call i8* @mpz_get_str(i32* null, i32 10, i32 undef)
%36 = tail call i32 @strlen(i8* %35)
%37 = icmp eq i32 %36, 1000
br i1 %37, label %38, label %40
38: ; preds = %34
%39 = add nuw nsw i32 %8, 2
br label %44
40: ; preds = %34
%41 = tail call i32 @free(i8* %35)
br label %42
42: ; preds = %40, %30
%43 = add nuw nsw i32 %8, 3
br label %7
44: ; preds = %12, %38, %26
%45 = phi i32 [ %39, %38 ], [ %27, %26 ], [ %8, %12 ]
%46 = phi i8* [ %35, %38 ], [ %23, %26 ], [ %13, %12 ]
%47 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %45)
%48 = tail call i32 @free(i8* %46)
ret i32 0
}