#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 acos(double);
double ln_get_earth_solar_dist(double);
double ln_get_mercury_earth_dist(double);
double ln_get_mercury_solar_dist(double);
double ln_rad_to_deg(double);
double ln_get_mercury_phase(double JD) {
  double i, r, delta, R;
  R = ln_get_earth_solar_dist(JD);
  r = ln_get_mercury_solar_dist(JD);
  delta = ln_get_mercury_earth_dist(JD);
  i = (r * r + delta * delta - R * R) / (2.0 * r * delta);
  i = acos(i);
  return ln_rad_to_deg(i);
}


x86 assembly (clang, -O0):
<ln_get_mercury_phase>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1060 <ln_get_earth_solar_dist@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1050 <ln_get_mercury_solar_dist@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1070 <ln_get_mercury_earth_dist@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe29(%rip),%xmm1
mulsd  -0x18(%rbp),%xmm1
mulsd  -0x20(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <acos@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <ln_rad_to_deg@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ln_get_mercury_phase>:
sub    $0x18,%rsp
movsd  %xmm0,(%rsp)
call   1060 <ln_get_earth_solar_dist@plt>
movsd  %xmm0,0x10(%rsp)
movsd  (%rsp),%xmm0
call   1050 <ln_get_mercury_solar_dist@plt>
movsd  %xmm0,0x8(%rsp)
movsd  (%rsp),%xmm0
call   1070 <ln_get_mercury_earth_dist@plt>
movsd  0x8(%rsp),%xmm2
movapd %xmm2,%xmm1
addsd  %xmm2,%xmm2
mulsd  %xmm0,%xmm2
mulsd  %xmm0,%xmm0
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0x10(%rsp),%xmm0
mulsd  %xmm0,%xmm0
subsd  %xmm0,%xmm1
divsd  %xmm2,%xmm1
movapd %xmm1,%xmm0
call   1030 <acos@plt>
add    $0x18,%rsp
jmp    1040 <ln_rad_to_deg@plt>

LLVM IR (-O0):
define double @ln_get_mercury_phase(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
store double %0, double* %2
%7 = load double, double* %2
%8 = call double @ln_get_earth_solar_dist(double %7)
store double %8, double* %6
%9 = load double, double* %2
%10 = call double @ln_get_mercury_solar_dist(double %9)
store double %10, double* %4
%11 = load double, double* %2
%12 = call double @ln_get_mercury_earth_dist(double %11)
store double %12, double* %5
%13 = load double, double* %4
%14 = load double, double* %4
%15 = load double, double* %5
%16 = load double, double* %5
%17 = fmul double %15, %16
%18 = call double @llvm.fmuladd.f64(double %13, double %14, double %17)
%19 = load double, double* %6
%20 = load double, double* %6
%21 = fneg double %19
%22 = call double @llvm.fmuladd.f64(double %21, double %20, double %18)
%23 = load double, double* %4
%24 = fmul double 2.000000e+00, %23
%25 = load double, double* %5
%26 = fmul double %24, %25
%27 = fdiv double %22, %26
store double %27, double* %3
%28 = load double, double* %3
%29 = call double @acos(double %28)
store double %29, double* %3
%30 = load double, double* %3
%31 = call double @ln_rad_to_deg(double %30)
ret double %31
}

LLVM IR (-O2):
define double @ln_get_mercury_phase(double %0) {
%2 = tail call double @ln_get_earth_solar_dist(double %0)
%3 = tail call double @ln_get_mercury_solar_dist(double %0)
%4 = tail call double @ln_get_mercury_earth_dist(double %0)
%5 = fmul double %4, %4
%6 = tail call double @llvm.fmuladd.f64(double %3, double %3, double %5)
%7 = fneg double %2
%8 = tail call double @llvm.fmuladd.f64(double %7, double %2, double %6)
%9 = fmul double %3, 2.000000e+00
%10 = fmul double %9, %4
%11 = fdiv double %8, %10
%12 = tail call double @acos(double %11)
%13 = tail call double @ln_rad_to_deg(double %12)
ret double %13
}