#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 */
double floor(double);
int log(double);
double phi();
double psi();
int sqrt(int);
double sum_geometric(double, double, double);
int solve(int p) {
  double cte = 1 / sqrt(5);
  double h = phi();
  double s = psi();
  double phi3 = h * h * h;
  double psi3 = s * s * s;
  double n = floor(log(p * sqrt(5)) / log(h) + 1 / 2.0);
  double k = floor(n / 3.0);
  double term1 = sum_geometric(phi3, k, phi3);
  double term2 = sum_geometric(psi3, k, psi3);
  return (int)(cte * (term1 + term2));
}


x86 assembly (clang, -O0):
<solve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x5,%edi
call   1060 <sqrt@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    $0x0,%al
call   1040 <phi@plt>
movsd  %xmm0,-0x18(%rbp)
mov    $0x0,%al
call   1030 <psi@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    $0x5,%edi
call   1060 <sqrt@plt>
mov    %eax,%ecx
mov    -0x58(%rbp),%eax
imul   %ecx,%eax
cvtsi2sd %eax,%xmm0
call   1050 <log@plt>
mov    %eax,-0x54(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1050 <log@plt>
mov    %eax,%ecx
mov    -0x54(%rbp),%eax
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
movsd  0xdfe(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1080 <floor@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  0xddb(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1080 <floor@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
call   1070 <sum_geometric@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm2
call   1070 <sum_geometric@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm1
addsd  -0x50(%rbp),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<solve>:
push   %rbx
sub    $0x30,%rsp
mov    %edi,%ebx
mov    $0x5,%edi
call   1060 <sqrt@plt>
lea    0x1(%rax),%ecx
xor    %edx,%edx
cmp    $0x3,%ecx
cmovae %edx,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x28(%rsp)
xor    %eax,%eax
call   1040 <phi@plt>
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1030 <psi@plt>
movsd  0x8(%rsp),%xmm2
movapd %xmm2,%xmm1
mulsd  %xmm2,%xmm1
mulsd  %xmm2,%xmm1
movsd  %xmm1,0x18(%rsp)
movapd %xmm0,%xmm1
mulsd  %xmm0,%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x20(%rsp)
mov    $0x5,%edi
call   1060 <sqrt@plt>
imul   %ebx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
call   1050 <log@plt>
mov    %eax,%ebx
movsd  0x8(%rsp),%xmm0
call   1050 <log@plt>
mov    %eax,%ecx
mov    %ebx,%eax
cltd
idiv   %ecx
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
addsd  0xe00(%rip),%xmm0
call   1080 <floor@plt>
divsd  0xdfb(%rip),%xmm0
call   1080 <floor@plt>
movapd %xmm0,%xmm1
movsd  %xmm0,0x10(%rsp)
movsd  0x18(%rsp),%xmm0
movaps %xmm0,%xmm2
call   1070 <sum_geometric@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0x20(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
movapd %xmm0,%xmm2
call   1070 <sum_geometric@plt>
addsd  0x8(%rsp),%xmm0
mulsd  0x28(%rsp),%xmm0
cvttsd2si %xmm0,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @solve(i32 %0) {
%2 = alloca i32
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
store i32 %0, i32* %2
%12 = call i32 @sqrt(i32 5)
%13 = sdiv i32 1, %12
%14 = sitofp i32 %13 to double
store double %14, double* %3
%15 = call double (...) @phi()
store double %15, double* %4
%16 = call double (...) @psi()
store double %16, double* %5
%17 = load double, double* %4
%18 = load double, double* %4
%19 = fmul double %17, %18
%20 = load double, double* %4
%21 = fmul double %19, %20
store double %21, double* %6
%22 = load double, double* %5
%23 = load double, double* %5
%24 = fmul double %22, %23
%25 = load double, double* %5
%26 = fmul double %24, %25
store double %26, double* %7
%27 = load i32, i32* %2
%28 = call i32 @sqrt(i32 5)
%29 = mul nsw i32 %27, %28
%30 = sitofp i32 %29 to double
%31 = call i32 @log(double %30)
%32 = load double, double* %4
%33 = call i32 @log(double %32)
%34 = sdiv i32 %31, %33
%35 = sitofp i32 %34 to double
%36 = fadd double %35, 5.000000e-01
%37 = call double @llvm.floor.f64(double %36)
store double %37, double* %8
%38 = load double, double* %8
%39 = fdiv double %38, 3.000000e+00
%40 = call double @llvm.floor.f64(double %39)
store double %40, double* %9
%41 = load double, double* %6
%42 = load double, double* %9
%43 = load double, double* %6
%44 = call double @sum_geometric(double %41, double %42, double %43)
store double %44, double* %10
%45 = load double, double* %7
%46 = load double, double* %9
%47 = load double, double* %7
%48 = call double @sum_geometric(double %45, double %46, double %47)
store double %48, double* %11
%49 = load double, double* %3
%50 = load double, double* %10
%51 = load double, double* %11
%52 = fadd double %50, %51
%53 = fmul double %49, %52
%54 = fptosi double %53 to i32
ret i32 %54
}

LLVM IR (-O2):
define i32 @solve(i32 %0) {
%2 = tail call i32 @sqrt(i32 5)
%3 = add i32 %2, 1
%4 = icmp ult i32 %3, 3
%5 = select i1 %4, i32 %2, i32 0
%6 = sitofp i32 %5 to double
%7 = tail call double (...) @phi()
%8 = tail call double (...) @psi()
%9 = fmul double %7, %7
%10 = fmul double %7, %9
%11 = fmul double %8, %8
%12 = fmul double %8, %11
%13 = tail call i32 @sqrt(i32 5)
%14 = mul nsw i32 %13, %0
%15 = sitofp i32 %14 to double
%16 = tail call i32 @log(double %15)
%17 = tail call i32 @log(double %7)
%18 = sdiv i32 %16, %17
%19 = sitofp i32 %18 to double
%20 = fadd double %19, 5.000000e-01
%21 = tail call double @llvm.floor.f64(double %20)
%22 = fdiv double %21, 3.000000e+00
%23 = tail call double @llvm.floor.f64(double %22)
%24 = tail call double @sum_geometric(double %10, double %23, double %10)
%25 = tail call double @sum_geometric(double %12, double %23, double %12)
%26 = fadd double %24, %25
%27 = fmul double %26, %6
%28 = fptosi double %27 to i32
ret i32 %28
}