#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*/ mpz_add(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ mpz_addmul_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init_set_ui(int /*<<< orphan*/, int);
scalar_t__ mpz_length(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_set(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_sub(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int main(void) {
  mpz_t p, q, t;
  mpz_init(t);
  mpz_init_set_ui(p, 1);
  mpz_init_set_ui(q, 2);
  int sum = 0;
  int i;
  for (i = 1; i < 1000; ++i) {
    mpz_add(p, p, q);
    if (mpz_length(p) > mpz_length(q))
      ++sum;
    mpz_sub(p, p, q);
    mpz_set(t, p);
    mpz_addmul_ui(t, q, 2);
    mpz_set(p, q);
    mpz_set(q, t);
  }
  printf("%d\n", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    -0x10(%rbp),%edi
call   1080 <mpz_init@plt>
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
call   10a0 <mpz_init_set_ui@plt>
mov    -0xc(%rbp),%edi
mov    $0x2,%esi
call   10a0 <mpz_init_set_ui@plt>
movl   $0x0,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
cmpl   $0x3e8,-0x18(%rbp)
jge    1254 <main+0xd4>
mov    -0x8(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1090 <mpz_add@plt>
mov    -0x8(%rbp),%edi
call   1070 <mpz_length@plt>
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%edi
call   1070 <mpz_length@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
jle    1207 <main+0x87>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1050 <mpz_sub@plt>
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <mpz_set@plt>
mov    -0x10(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    $0x2,%edx
call   1030 <mpz_addmul_ui@plt>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1040 <mpz_set@plt>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1040 <mpz_set@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11bf <main+0x3f>
mov    -0x14(%rbp),%esi
lea    0xda2(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
call   1080 <mpz_init@plt>
mov    $0x1,%esi
call   10a0 <mpz_init_set_ui@plt>
mov    $0x2,%esi
call   10a0 <mpz_init_set_ui@plt>
xor    %ebx,%ebx
mov    $0x3e7,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
call   1090 <mpz_add@plt>
call   1070 <mpz_length@plt>
mov    %rax,%r14
call   1070 <mpz_length@plt>
xor    %ecx,%ecx
cmp    %rax,%r14
setg   %cl
add    %ecx,%ebx
call   1050 <mpz_sub@plt>
call   1040 <mpz_set@plt>
mov    $0x2,%edx
call   1030 <mpz_addmul_ui@plt>
call   1040 <mpz_set@plt>
call   1040 <mpz_set@plt>
add    $0xffffffff,%ebp
jne    11b0 <main+0x30>
lea    0xe0a(%rip),%rdi
mov    %ebx,%esi
call   1060 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = tail call i32 @mpz_init(i32 undef)
%2 = tail call i32 @mpz_init_set_ui(i32 undef, i32 1)
%3 = tail call i32 @mpz_init_set_ui(i32 undef, i32 2)
br label %4
4: ; preds = %0, %4
%5 = phi i32 [ 1, %0 ], [ %18, %4 ]
%6 = phi i32 [ 0, %0 ], [ %12, %4 ]
%7 = tail call i32 @mpz_add(i32 undef, i32 undef, i32 undef)
%8 = tail call i64 @mpz_length(i32 undef)
%9 = tail call i64 @mpz_length(i32 undef)
%10 = icmp sgt i64 %8, %9
%11 = zext i1 %10 to i32
%12 = add nuw nsw i32 %6, %11
%13 = tail call i32 @mpz_sub(i32 undef, i32 undef, i32 undef)
%14 = tail call i32 @mpz_set(i32 undef, i32 undef)
%15 = tail call i32 @mpz_addmul_ui(i32 undef, i32 undef, i32 2)
%16 = tail call i32 @mpz_set(i32 undef, i32 undef)
%17 = tail call i32 @mpz_set(i32 undef, i32 undef)
%18 = add nuw nsw i32 %5, 1
%19 = icmp eq i32 %18, 1000
br i1 %19, label %20, label %4
20: ; preds = %4
%21 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %12)
ret i32 0
}