#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_get_str(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init_set_ui(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_mul_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_set(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int strlen(char *);
int main(int argc, char *argv[]) {
  int count = 0;
  mpz_t n;
  mpz_t d;
  mpz_t n1;
  mpz_t d1;
  mpz_init_set_ui(n, 1);
  mpz_init_set_ui(d, 1);
  mpz_init_set_ui(n1, 3);
  mpz_init_set_ui(d1, 2);
  for (int i = 2; i <= 1000; i++) {
    mpz_t n2;
    mpz_t d2;
    mpz_init(n2);
    mpz_init(d2);
    mpz_mul_ui(n2, n1, 2);
    mpz_add(n2, n2, n);
    mpz_mul_ui(d2, d1, 2);
    mpz_add(d2, d2, d);
    char n_digits[1024] = {'\0'};
    char d_digits[1024] = {'\0'};
    mpz_get_str(n_digits, 10, n2);
    mpz_get_str(d_digits, 10, d2);
    int nlen = strlen(n_digits);
    int dlen = strlen(d_digits);
    if (nlen > dlen) {
      count++;
    }
    mpz_set(n, n1);
    mpz_set(n1, n2);
    mpz_set(d, d1);
    mpz_set(d1, d2);
  }
  printf("%i", count);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-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
mov    $0x3,%esi
call   10a0 <mpz_init_set_ui@plt>
mov    -0x24(%rbp),%edi
mov    $0x2,%esi
call   10a0 <mpz_init_set_ui@plt>
movl   $0x2,-0x28(%rbp)
cmpl   $0x3e8,-0x28(%rbp)
jg     130b <main+0x17b>
mov    -0x2c(%rbp),%edi
call   1070 <mpz_init@plt>
mov    -0x30(%rbp),%edi
call   1070 <mpz_init@plt>
mov    -0x2c(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    $0x2,%edx
call   10b0 <mpz_mul_ui@plt>
mov    -0x2c(%rbp),%edi
mov    -0x2c(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1090 <mpz_add@plt>
mov    -0x30(%rbp),%edi
mov    -0x24(%rbp),%esi
mov    $0x2,%edx
call   10b0 <mpz_mul_ui@plt>
mov    -0x30(%rbp),%edi
mov    -0x30(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1090 <mpz_add@plt>
lea    -0x430(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
lea    -0x830(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
lea    -0x430(%rbp),%rdi
mov    -0x2c(%rbp),%edx
mov    $0xa,%esi
call   1080 <mpz_get_str@plt>
lea    -0x830(%rbp),%rdi
mov    -0x30(%rbp),%edx
mov    $0xa,%esi
call   1080 <mpz_get_str@plt>
lea    -0x430(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x834(%rbp)
lea    -0x830(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x838(%rbp)
mov    -0x834(%rbp),%eax
cmp    -0x838(%rbp),%eax
jle    12d1 <main+0x141>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1030 <mpz_set@plt>
mov    -0x20(%rbp),%edi
mov    -0x2c(%rbp),%esi
call   1030 <mpz_set@plt>
mov    -0x1c(%rbp),%edi
mov    -0x24(%rbp),%esi
call   1030 <mpz_set@plt>
mov    -0x24(%rbp),%edi
mov    -0x30(%rbp),%esi
call   1030 <mpz_set@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11eb <main+0x5b>
mov    -0x14(%rbp),%esi
lea    0xceb(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x800,%rsp
mov    $0x1,%esi
call   10a0 <mpz_init_set_ui@plt>
mov    $0x1,%esi
call   10a0 <mpz_init_set_ui@plt>
mov    $0x3,%esi
call   10a0 <mpz_init_set_ui@plt>
mov    $0x2,%esi
call   10a0 <mpz_init_set_ui@plt>
xor    %r12d,%r12d
mov    $0x3e7,%ebx
lea    0x400(%rsp),%r14
mov    %rsp,%r15
nopw   0x0(%rax,%rax,1)
call   1070 <mpz_init@plt>
call   1070 <mpz_init@plt>
mov    $0x2,%edx
call   10b0 <mpz_mul_ui@plt>
call   1090 <mpz_add@plt>
mov    $0x2,%edx
call   10b0 <mpz_mul_ui@plt>
call   1090 <mpz_add@plt>
mov    $0x400,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
mov    $0x400,%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
mov    %r14,%rdi
mov    $0xa,%esi
call   1080 <mpz_get_str@plt>
mov    %r15,%rdi
mov    $0xa,%esi
call   1080 <mpz_get_str@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r15,%rdi
call   1040 <strlen@plt>
xor    %ecx,%ecx
cmp    %eax,%ebp
setg   %cl
add    %ecx,%r12d
call   1030 <mpz_set@plt>
call   1030 <mpz_set@plt>
call   1030 <mpz_set@plt>
call   1030 <mpz_set@plt>
add    $0xffffffff,%ebx
jne    11e0 <main+0x50>
lea    0xd80(%rip),%rdi
mov    %r12d,%esi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x800,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%i\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = tail call i32 @mpz_init_set_ui(i32 undef, i32 1)
%6 = tail call i32 @mpz_init_set_ui(i32 undef, i32 1)
%7 = tail call i32 @mpz_init_set_ui(i32 undef, i32 3)
%8 = tail call i32 @mpz_init_set_ui(i32 undef, i32 2)
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
br label %13
11: ; preds = %13
%12 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %28)
ret i32 0
13: ; preds = %2, %13
%14 = phi i32 [ 0, %2 ], [ %28, %13 ]
%15 = phi i32 [ 2, %2 ], [ %33, %13 ]
%16 = call i32 @mpz_init(i32 undef)
%17 = call i32 @mpz_init(i32 undef)
%18 = call i32 @mpz_mul_ui(i32 undef, i32 undef, i32 2)
%19 = call i32 @mpz_add(i32 undef, i32 undef, i32 undef)
%20 = call i32 @mpz_mul_ui(i32 undef, i32 undef, i32 2)
%21 = call i32 @mpz_add(i32 undef, i32 undef, i32 undef)
%22 = call i32 @mpz_get_str(i8* %9, i32 10, i32 undef)
%23 = call i32 @mpz_get_str(i8* %10, i32 10, i32 undef)
%24 = call i32 @strlen(i8* %9)
%25 = call i32 @strlen(i8* %10)
%26 = icmp sgt i32 %24, %25
%27 = zext i1 %26 to i32
%28 = add nuw nsw i32 %14, %27
%29 = call i32 @mpz_set(i32 undef, i32 undef)
%30 = call i32 @mpz_set(i32 undef, i32 undef)
%31 = call i32 @mpz_set(i32 undef, i32 undef)
%32 = call i32 @mpz_set(i32 undef, i32 undef)
%33 = add nuw nsw i32 %15, 1
%34 = icmp eq i32 %33, 1001
br i1 %34, label %11, label %13
}