#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 */
int INT_MAX;
int floor(int);
int log10(double);
int sqrt(double);
int fib_analytic(int d) {
  double a = log10((sqrt(5.0) + 1) / 2);
  double b = log10(5.0) / 2;
  int i;
  for (i = 0; i < INT_MAX; i++) {
    if ((floor(i * a - b) + 1) == d)
      break;
  }
  return i;
}


x86 assembly (clang, -O0):
<fib_analytic>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movsd  0xebd(%rip),%xmm0
call   1040 <sqrt@plt>
add    $0x1,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
call   1030 <log10@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xe93(%rip),%xmm0
call   1030 <log10@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2e54(%rip),%rcx
cmp    (%rcx),%eax
jge    11f7 <fib_analytic+0xc7>
cvtsi2sdl -0x1c(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1050 <floor@plt>
add    $0x1,%eax
cmp    -0x4(%rbp),%eax
jne    11e4 <fib_analytic+0xb4>
jmp    11f7 <fib_analytic+0xc7>
jmp    11e9 <fib_analytic+0xb9>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118a <fib_analytic+0x5a>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fib_analytic>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %edi,%ebx
movsd  0xebe(%rip),%xmm0
call   1040 <sqrt@plt>
mov    %eax,%ecx
add    $0x1,%ecx
shr    $0x1f,%ecx
add    %ecx,%eax
add    $0x1,%eax
sar    %eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
call   1030 <log10@plt>
mov    %eax,%ebp
movsd  0xe94(%rip),%xmm0
call   1030 <log10@plt>
mov    0x2e70(%rip),%r14
cmpl   $0x0,(%r14)
jle    11dd <fib_analytic+0xad>
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
xorpd  0xe6d(%rip),%xmm0
movapd %xmm0,0x10(%rsp)
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mulsd  0x8(%rsp),%xmm0
addsd  0x10(%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1050 <floor@plt>
add    $0x1,%eax
cmp    %ebx,%eax
je     11df <fib_analytic+0xaf>
add    $0x1,%ebp
cmp    (%r14),%ebp
jl     11b0 <fib_analytic+0x80>
jmp    11df <fib_analytic+0xaf>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@INT_MAX = global i32 0
define i32 @fib_analytic(i32 %0) {
%2 = alloca i32
%3 = alloca double
%4 = alloca double
%5 = alloca i32
store i32 %0, i32* %2
%6 = call i32 @sqrt(double 5.000000e+00)
%7 = add nsw i32 %6, 1
%8 = sdiv i32 %7, 2
%9 = sitofp i32 %8 to double
%10 = call i32 @log10(double %9)
%11 = sitofp i32 %10 to double
store double %11, double* %3
%12 = call i32 @log10(double 5.000000e+00)
%13 = sdiv i32 %12, 2
%14 = sitofp i32 %13 to double
store double %14, double* %4
store i32 0, i32* %5
br label %15
15: ; preds = %33, %1
%16 = load i32, i32* %5
%17 = load i32, i32* @INT_MAX
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %36
19: ; preds = %15
%20 = load i32, i32* %5
%21 = sitofp i32 %20 to double
%22 = load double, double* %3
%23 = load double, double* %4
%24 = fneg double %23
%25 = call double @llvm.fmuladd.f64(double %21, double %22, double %24)
%26 = fptosi double %25 to i32
%27 = call i32 @floor(i32 %26)
%28 = add nsw i32 %27, 1
%29 = load i32, i32* %2
%30 = icmp eq i32 %28, %29
br i1 %30, label %31, label %32
31: ; preds = %19
br label %36
32: ; preds = %19
br label %33
33: ; preds = %32
%34 = load i32, i32* %5
%35 = add nsw i32 %34, 1
store i32 %35, i32* %5
br label %15
36: ; preds = %31, %15
%37 = load i32, i32* %5
ret i32 %37
}

LLVM IR (-O2):
@INT_MAX = global i32 0
define i32 @fib_analytic(i32 %0) {
%2 = tail call i32 @sqrt(double 5.000000e+00)
%3 = add nsw i32 %2, 1
%4 = sdiv i32 %3, 2
%5 = sitofp i32 %4 to double
%6 = tail call i32 @log10(double %5)
%7 = sitofp i32 %6 to double
%8 = tail call i32 @log10(double 5.000000e+00)
%9 = load i32, i32* @INT_MAX
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %27
11: ; preds = %1
%12 = sdiv i32 %8, 2
%13 = sitofp i32 %12 to double
%14 = fneg double %13
br label %15
15: ; preds = %11, %23
%16 = phi i32 [ 0, %11 ], [ %24, %23 ]
%17 = sitofp i32 %16 to double
%18 = tail call double @llvm.fmuladd.f64(double %17, double %7, double %14)
%19 = fptosi double %18 to i32
%20 = tail call i32 @floor(i32 %19)
%21 = add nsw i32 %20, 1
%22 = icmp eq i32 %21, %0
br i1 %22, label %27, label %23
23: ; preds = %15
%24 = add nuw nsw i32 %16, 1
%25 = load i32, i32* @INT_MAX
%26 = icmp slt i32 %24, %25
br i1 %26, label %15, label %27
27: ; preds = %23, %15, %1
%28 = phi i32 [ 0, %1 ], [ %16, %15 ], [ %24, %23 ]
ret i32 %28
}