#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 Julian(int, int, double);
double MoonPosition(double, double);
double SunPosition(double);
double cos(double);
double MoonPhase(int year, int month, int day, double hour, int *ip) {
  double j = 0.0;
  double ls = 0.0;
  double lm = 0.0;
  double t = 0.0;
  j = Julian(year, month, (double)day + hour / 24.0) - 2444238.5;
  ls = SunPosition(j);
  lm = MoonPosition(j, ls);
  t = lm - ls;
  if (t < 0) {
    t = t + 360.0;
  }
  *ip = (int)((t + 22.5) / 45) & 0x7;
  return (1.0 - cos((lm - ls) * (3.1415926535897932384626433832795 / 180.0))) /
         2.0;
}


x86 assembly (clang, -O0):
<MoonPhase>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
cvtsi2sdl -0xc(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  0xe76(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
call   1040 <Julian@plt>
movsd  0xe59(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1030 <SunPosition@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
call   1050 <MoonPosition@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x40(%rbp),%xmm0
jbe    1202 <MoonPhase+0xc2>
movsd  0xe18(%rip),%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xe2e(%rip),%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  0xe19(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%ecx
and    $0x7,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movsd  -0x38(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
movsd  0xdee(%rip),%xmm1
mulsd  %xmm1,%xmm0
call   1060 <cos@plt>
movaps %xmm0,%xmm1
movsd  0xdd2(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  0xdbe(%rip),%xmm1
divsd  %xmm1,%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MoonPhase>:
push   %rbx
sub    $0x10,%rsp
cvtsi2sd %edx,%xmm1
mov    %rcx,%rbx
divsd  0xeac(%rip),%xmm0
addsd  %xmm1,%xmm0
call   1040 <Julian@plt>
addsd  0xea3(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
call   1030 <SunPosition@plt>
movapd %xmm0,%xmm1
movsd  %xmm0,(%rsp)
movsd  0x8(%rsp),%xmm0
call   1050 <MoonPosition@plt>
subsd  (%rsp),%xmm0
movsd  0xe7f(%rip),%xmm1
addsd  %xmm0,%xmm1
xorpd  %xmm2,%xmm2
movapd %xmm0,%xmm3
cmpltsd %xmm2,%xmm3
andpd  %xmm3,%xmm1
andnpd %xmm0,%xmm3
orpd   %xmm1,%xmm3
addsd  0xe62(%rip),%xmm3
divsd  0xe62(%rip),%xmm3
cvttsd2si %xmm3,%eax
and    $0x7,%eax
mov    %eax,(%rbx)
mulsd  0xe59(%rip),%xmm0
call   1060 <cos@plt>
movsd  0xe54(%rip),%xmm1
subsd  %xmm0,%xmm1
mulsd  0xe50(%rip),%xmm1
movapd %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @MoonPhase(i32 %0, i32 %1, i32 %2, double %3, i32* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca i32*
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store double %3, double* %9
store i32* %4, i32** %10
store double 0.000000e+00, double* %11
store double 0.000000e+00, double* %12
store double 0.000000e+00, double* %13
store double 0.000000e+00, double* %14
%15 = load i32, i32* %6
%16 = load i32, i32* %7
%17 = load i32, i32* %8
%18 = sitofp i32 %17 to double
%19 = load double, double* %9
%20 = fdiv double %19, 2.400000e+01
%21 = fadd double %18, %20
%22 = call double @Julian(i32 %15, i32 %16, double %21)
%23 = fsub double %22, 0x4142A5E740000000
store double %23, double* %11
%24 = load double, double* %11
%25 = call double @SunPosition(double %24)
store double %25, double* %12
%26 = load double, double* %11
%27 = load double, double* %12
%28 = call double @MoonPosition(double %26, double %27)
store double %28, double* %13
%29 = load double, double* %13
%30 = load double, double* %12
%31 = fsub double %29, %30
store double %31, double* %14
%32 = load double, double* %14
%33 = fcmp olt double %32, 0.000000e+00
br i1 %33, label %34, label %37
34: ; preds = %5
%35 = load double, double* %14
%36 = fadd double %35, 3.600000e+02
store double %36, double* %14
br label %37
37: ; preds = %34, %5
%38 = load double, double* %14
%39 = fadd double %38, 2.250000e+01
%40 = fdiv double %39, 4.500000e+01
%41 = fptosi double %40 to i32
%42 = and i32 %41, 7
%43 = load i32*, i32** %10
store i32 %42, i32* %43
%44 = load double, double* %13
%45 = load double, double* %12
%46 = fsub double %44, %45
%47 = fmul double %46, 0x3F91DF46A2529D39
%48 = call double @cos(double %47)
%49 = fsub double 1.000000e+00, %48
%50 = fdiv double %49, 2.000000e+00
ret double %50
}

LLVM IR (-O2):
define double @MoonPhase(i32 %0, i32 %1, i32 %2, double %3, i32* nocapture writeonly %4) {
%6 = sitofp i32 %2 to double
%7 = fdiv double %3, 2.400000e+01
%8 = fadd double %7, %6
%9 = tail call double @Julian(i32 %0, i32 %1, double %8)
%10 = fadd double %9, 0xC142A5E740000000
%11 = tail call double @SunPosition(double %10)
%12 = tail call double @MoonPosition(double %10, double %11)
%13 = fsub double %12, %11
%14 = fcmp olt double %13, 0.000000e+00
%15 = fadd double %13, 3.600000e+02
%16 = select i1 %14, double %15, double %13
%17 = fadd double %16, 2.250000e+01
%18 = fdiv double %17, 4.500000e+01
%19 = fptosi double %18 to i32
%20 = and i32 %19, 7
store i32 %20, i32* %4
%21 = fmul double %13, 0x3F91DF46A2529D39
%22 = tail call double @cos(double %21)
%23 = fsub double 1.000000e+00, %22
%24 = fmul double %23, 5.000000e-01
ret double %24
}