#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*/ time_t;

/* Variables and functions */
int difftime(int /*<<< orphan*/, int /*<<< orphan*/ const);
int /*<<< orphan*/ timeByMoonphase(unsigned int, unsigned int);
void lunationEdgesOfTime(const time_t t, unsigned int *lower_lun,
                         int *lower_phi, time_t *lower_time,
                         unsigned int *upper_lun, int *upper_phi,
                         time_t *upper_time) {
  unsigned int lunphi_lower = 0, lunphi_upper, lunphi_mid;
  unsigned int booby_trap = 64;
  lunphi_upper = (sizeof(time_t) < 8) ? 5691 : 16777216;
  time_t time_mid, time_upper = t, time_lower = t;
  do {
    lunphi_mid = (lunphi_lower + lunphi_upper) >> 1;
    time_mid = timeByMoonphase((lunphi_mid >> 2), (lunphi_mid & 3));
    if (difftime(time_mid, t) >= 0.) {
      lunphi_upper = lunphi_mid;
      time_upper = time_mid;
    } else {
      lunphi_lower = lunphi_mid;
      time_lower = time_mid;
    }
  } while ((lunphi_upper - lunphi_lower != 1) && booby_trap--);
  *lower_lun = (lunphi_lower >> 2);
  *lower_phi = (lunphi_lower & 3);
  *upper_lun = (lunphi_upper >> 2);
  *upper_phi = (lunphi_upper & 3);
  *lower_time = time_lower;
  *upper_time = time_upper;
}


x86 assembly (clang, -O0):
<lunationEdgesOfTime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x10(%rbp),%rax
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x40,-0x40(%rbp)
movl   $0x163b,-0x38(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x34(%rbp),%eax
add    -0x38(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%edi
shr    $0x2,%edi
mov    -0x3c(%rbp),%esi
and    $0x3,%esi
call   1040 <timeByMoonphase@plt>
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%edi
mov    -0x4(%rbp),%esi
call   1030 <difftime@plt>
cvtsi2sd %eax,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11b1 <lunationEdgesOfTime+0x91>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x44(%rbp),%eax
mov    %eax,-0x48(%rbp)
jmp    11bd <lunationEdgesOfTime+0x9d>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x44(%rbp),%eax
mov    %eax,-0x4c(%rbp)
jmp    11c2 <lunationEdgesOfTime+0xa2>
mov    -0x38(%rbp),%ecx
sub    -0x34(%rbp),%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
mov    %al,-0x4d(%rbp)
je     11ea <lunationEdgesOfTime+0xca>
mov    -0x40(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x40(%rbp)
cmp    $0x0,%eax
setne  %al
mov    %al,-0x4d(%rbp)
mov    -0x4d(%rbp),%al
test   $0x1,%al
jne    1164 <lunationEdgesOfTime+0x44>
mov    -0x34(%rbp),%ecx
shr    $0x2,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x34(%rbp),%ecx
and    $0x3,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x38(%rbp),%ecx
shr    $0x2,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x38(%rbp),%ecx
and    $0x3,%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x4c(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x48(%rbp),%ecx
mov    0x10(%rbp),%rax
mov    %ecx,(%rax)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lunationEdgesOfTime>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r9,0x30(%rsp)
mov    %r8,0x20(%rsp)
mov    %rcx,0x28(%rsp)
mov    %rdx,0x18(%rsp)
mov    %rsi,0x10(%rsp)
mov    %edi,%ebp
xor    %r13d,%r13d
mov    $0x163b,%r15d
mov    $0xffffffc0,%r12d
mov    %edi,0xc(%rsp)
mov    %edi,0x8(%rsp)
lea    (%r15,%r13,1),%edi
mov    %edi,%ebx
shr    %ebx
shr    $0x3,%edi
mov    %ebx,%esi
and    $0x3,%esi
call   1040 <timeByMoonphase@plt>
mov    %eax,%r14d
mov    %eax,%edi
mov    %ebp,%esi
call   1030 <difftime@plt>
test   %eax,%eax
jns    1190 <lunationEdgesOfTime+0x70>
mov    %ebx,%r13d
mov    %r14d,0x8(%rsp)
jmp    1198 <lunationEdgesOfTime+0x78>
nop
mov    %ebx,%r15d
mov    %r14d,0xc(%rsp)
mov    %r15d,%eax
sub    %r13d,%eax
cmp    $0x1,%eax
je     11b0 <lunationEdgesOfTime+0x90>
lea    0x1(%r12),%eax
test   %r12d,%r12d
mov    %eax,%r12d
jne    1160 <lunationEdgesOfTime+0x40>
mov    %r13d,%eax
shr    $0x2,%eax
mov    0x10(%rsp),%rcx
mov    %eax,(%rcx)
and    $0x3,%r13d
mov    0x18(%rsp),%rax
mov    %r13d,(%rax)
mov    %r15d,%eax
shr    $0x2,%eax
mov    0x20(%rsp),%rcx
mov    %eax,(%rcx)
and    $0x3,%r15d
mov    0x30(%rsp),%rax
mov    %r15d,(%rax)
mov    0x28(%rsp),%rax
mov    0x8(%rsp),%ecx
mov    %ecx,(%rax)
mov    0x70(%rsp),%rax
mov    0xc(%rsp),%ecx
mov    %ecx,(%rax)
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @lunationEdgesOfTime(i32 %0, i32* %1, i32* %2, i32* %3, i32* %4, i32* %5, i32* %6) {
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
store i32 %0, i32* %8
store i32* %1, i32** %9
store i32* %2, i32** %10
store i32* %3, i32** %11
store i32* %4, i32** %12
store i32* %5, i32** %13
store i32* %6, i32** %14
store i32 0, i32* %15
store i32 64, i32* %18
store i32 5691, i32* %16
%22 = load i32, i32* %8
store i32 %22, i32* %20
%23 = load i32, i32* %8
store i32 %23, i32* %21
br label %24
24: ; preds = %55, %7
%25 = load i32, i32* %15
%26 = load i32, i32* %16
%27 = add i32 %25, %26
%28 = lshr i32 %27, 1
store i32 %28, i32* %17
%29 = load i32, i32* %17
%30 = lshr i32 %29, 2
%31 = load i32, i32* %17
%32 = and i32 %31, 3
%33 = call i32 @timeByMoonphase(i32 %30, i32 %32)
store i32 %33, i32* %19
%34 = load i32, i32* %19
%35 = load i32, i32* %8
%36 = call i32 @difftime(i32 %34, i32 %35)
%37 = sitofp i32 %36 to double
%38 = fcmp oge double %37, 0.000000e+00
br i1 %38, label %39, label %42
39: ; preds = %24
%40 = load i32, i32* %17
store i32 %40, i32* %16
%41 = load i32, i32* %19
store i32 %41, i32* %20
br label %45
42: ; preds = %24
%43 = load i32, i32* %17
store i32 %43, i32* %15
%44 = load i32, i32* %19
store i32 %44, i32* %21
br label %45
45: ; preds = %42, %39
br label %46
46: ; preds = %45
%47 = load i32, i32* %16
%48 = load i32, i32* %15
%49 = sub i32 %47, %48
%50 = icmp ne i32 %49, 1
br i1 %50, label %51, label %55
51: ; preds = %46
%52 = load i32, i32* %18
%53 = add i32 %52, -1
store i32 %53, i32* %18
%54 = icmp ne i32 %52, 0
br label %55
55: ; preds = %51, %46
%56 = phi i1 [ false, %46 ], [ %54, %51 ]
br i1 %56, label %24, label %57
57: ; preds = %55
%58 = load i32, i32* %15
%59 = lshr i32 %58, 2
%60 = load i32*, i32** %9
store i32 %59, i32* %60
%61 = load i32, i32* %15
%62 = and i32 %61, 3
%63 = load i32*, i32** %10
store i32 %62, i32* %63
%64 = load i32, i32* %16
%65 = lshr i32 %64, 2
%66 = load i32*, i32** %12
store i32 %65, i32* %66
%67 = load i32, i32* %16
%68 = and i32 %67, 3
%69 = load i32*, i32** %13
store i32 %68, i32* %69
%70 = load i32, i32* %21
%71 = load i32*, i32** %11
store i32 %70, i32* %71
%72 = load i32, i32* %20
%73 = load i32*, i32** %14
store i32 %72, i32* %73
ret void
}

LLVM IR (-O2):
define void @lunationEdgesOfTime(i32 %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3, i32* nocapture writeonly %4, i32* nocapture writeonly %5, i32* nocapture writeonly %6) {
br label %8
8: ; preds = %8, %7
%9 = phi i32 [ 5691, %7 ], [ %21, %8 ]
%10 = phi i32 [ 64, %7 ], [ %27, %8 ]
%11 = phi i32 [ 0, %7 ], [ %22, %8 ]
%12 = phi i32 [ %0, %7 ], [ %23, %8 ]
%13 = phi i32 [ %0, %7 ], [ %24, %8 ]
%14 = add i32 %11, %9
%15 = lshr i32 %14, 1
%16 = lshr i32 %14, 3
%17 = and i32 %15, 3
%18 = tail call i32 @timeByMoonphase(i32 %16, i32 %17)
%19 = tail call i32 @difftime(i32 %18, i32 %0)
%20 = icmp sgt i32 %19, -1
%21 = select i1 %20, i32 %15, i32 %9
%22 = select i1 %20, i32 %11, i32 %15
%23 = select i1 %20, i32 %18, i32 %12
%24 = select i1 %20, i32 %13, i32 %18
%25 = sub i32 %21, %22
%26 = icmp eq i32 %25, 1
%27 = add nsw i32 %10, -1
%28 = icmp eq i32 %10, 0
%29 = select i1 %26, i1 true, i1 %28
br i1 %29, label %30, label %8
30: ; preds = %8
%31 = lshr i32 %22, 2
store i32 %31, i32* %1
%32 = and i32 %22, 3
store i32 %32, i32* %2
%33 = lshr i32 %21, 2
store i32 %33, i32* %4
%34 = and i32 %21, 3
store i32 %34, i32* %5
store i32 %24, i32* %3
store i32 %23, i32* %6
ret void
}