#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;
struct tm {
  int tm_mday;
  int tm_mon;
  int tm_year;
};
typedef int /*<<< orphan*/ man_readable_time;

/* Variables and functions */
double difftime(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ lunationEdgesOfTime(int /*<<< orphan*/, unsigned int *,
                                       int *, int /*<<< orphan*/ *,
                                       unsigned int *, int *,
                                       int /*<<< orphan*/ *);
int /*<<< orphan*/ lunphi_next(unsigned int, int, unsigned int *, int *);
int /*<<< orphan*/ memset(struct tm *, int /*<<< orphan*/, int);
int /*<<< orphan*/ mktime(struct tm *);
extern unsigned fillCalendar(const int year, const int month, double *lunations,
                             int *quarterDay) {
  struct tm man_readable_time;
  time_t mac_time, lower_t, upper_t;
  unsigned int lower_lun, upper_lun;
  int lower_phi, upper_phi;
  unsigned fillingDay = 0;
  unsigned booby_trap = 42;
  memset(&man_readable_time, 0, sizeof(man_readable_time));
  man_readable_time.tm_mday = 1;
  man_readable_time.tm_mon = month - 1;
  man_readable_time.tm_year = year - 1900;
  mac_time = mktime(&man_readable_time);
  lunationEdgesOfTime(mac_time, &lower_lun, &lower_phi, &lower_t, &upper_lun,
                      &upper_phi, &upper_t);
  do {
    double diff_x, diff_y, diff_z;
    double lunation_r, lunation_fraction;
    diff_x = difftime(upper_t, lower_t);
    diff_y = difftime(mac_time, lower_t);
    lunation_fraction = diff_y / diff_x;
    if (lunation_fraction < 1.) {
      diff_z = difftime(upper_t, mac_time);
      lunation_r = lunation_fraction + (double)lower_phi;
      quarterDay[fillingDay] = (diff_z < 86400.) ? (double)upper_phi : -1;
      lunations[fillingDay] = lunation_r;
      fillingDay++;
      man_readable_time.tm_mday++;
      mac_time = mktime(&man_readable_time);
    } else {
      lower_lun = upper_lun;
      lower_phi = upper_phi;
      lower_t = upper_t;
      upper_t = lunphi_next(lower_lun, lower_phi, &upper_lun, &upper_phi);
    }
  } while ((man_readable_time.tm_mon == (month - 1)) && (booby_trap--));
  return fillingDay;
}


x86 assembly (clang, -O0):
<fillCalendar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
movl   $0x0,-0x48(%rbp)
movl   $0x2a,-0x4c(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
movl   $0x1,-0x28(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x4(%rbp),%eax
sub    $0x76c,%eax
mov    %eax,-0x20(%rbp)
lea    -0x28(%rbp),%rdi
call   1070 <mktime@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
lea    -0x38(%rbp),%rsi
lea    -0x40(%rbp),%rdx
lea    -0x30(%rbp),%rcx
lea    -0x3c(%rbp),%r8
lea    -0x44(%rbp),%r9
lea    -0x34(%rbp),%rax
mov    %rax,(%rsp)
call   1030 <lunationEdgesOfTime@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%esi
call   1050 <difftime@plt>
movsd  %xmm0,-0x58(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x30(%rbp),%esi
call   1050 <difftime@plt>
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
divsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  0xdf7(%rip),%xmm0
ucomisd -0x78(%rbp),%xmm0
jbe    12b2 <fillCalendar+0x162>
mov    -0x34(%rbp),%edi
mov    -0x2c(%rbp),%esi
call   1050 <difftime@plt>
movsd  %xmm0,-0x68(%rbp)
movsd  -0x78(%rbp),%xmm0
cvtsi2sdl -0x40(%rbp),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  0xdc9(%rip),%xmm0
ucomisd -0x68(%rbp),%xmm0
jbe    1259 <fillCalendar+0x109>
cvtsi2sdl -0x44(%rbp),%xmm0
movsd  %xmm0,-0x80(%rbp)
jmp    126b <fillCalendar+0x11b>
movsd  0xdaf(%rip),%xmm0
movsd  %xmm0,-0x80(%rbp)
jmp    126b <fillCalendar+0x11b>
movsd  -0x80(%rbp),%xmm0
cvttsd2si %xmm0,%edx
mov    -0x18(%rbp),%rax
mov    -0x48(%rbp),%ecx
mov    %edx,(%rax,%rcx,4)
movsd  -0x70(%rbp),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x48(%rbp),%ecx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
lea    -0x28(%rbp),%rdi
call   1070 <mktime@plt>
mov    %eax,-0x2c(%rbp)
jmp    12da <fillCalendar+0x18a>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x44(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x38(%rbp),%edi
mov    -0x40(%rbp),%esi
lea    -0x3c(%rbp),%rdx
lea    -0x44(%rbp),%rcx
call   1040 <lunphi_next@plt>
mov    %eax,-0x34(%rbp)
jmp    12df <fillCalendar+0x18f>
mov    -0x24(%rbp),%ecx
mov    -0x8(%rbp),%edx
sub    $0x1,%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x81(%rbp)
jne    130f <fillCalendar+0x1bf>
mov    -0x4c(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x4c(%rbp)
cmp    $0x0,%eax
setne  %al
mov    %al,-0x81(%rbp)
mov    -0x81(%rbp),%al
test   $0x1,%al
jne    11d2 <fillCalendar+0x82>
mov    -0x48(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fillCalendar>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %esi,%ebp
mov    %edi,%r12d
lea    0x28(%rsp),%r13
xor    %ebx,%ebx
mov    %r13,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
movl   $0x1,0x28(%rsp)
add    $0xffffffff,%ebp
mov    %ebp,0x2c(%rsp)
add    $0xfffff894,%r12d
mov    %r12d,0x30(%rsp)
mov    %r13,%rdi
call   1070 <mktime@plt>
mov    %eax,%r13d
lea    0x14(%rsp),%rax
mov    %rax,(%rsp)
lea    0x44(%rsp),%rsi
lea    0x20(%rsp),%rdx
lea    0x1c(%rsp),%rcx
lea    0x24(%rsp),%r8
lea    0x18(%rsp),%r9
mov    %r13d,%edi
call   1030 <lunationEdgesOfTime@plt>
mov    $0xffffffd6,%r12d
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x14(%rsp),%edi
mov    0x1c(%rsp),%esi
call   1050 <difftime@plt>
movsd  %xmm0,0x38(%rsp)
mov    0x1c(%rsp),%esi
mov    %r13d,%edi
call   1050 <difftime@plt>
movapd %xmm0,%xmm1
divsd  0x38(%rsp),%xmm1
movsd  0xdef(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1290 <fillCalendar+0x140>
mov    0x14(%rsp),%edi
mov    %r13d,%esi
movsd  %xmm1,0x38(%rsp)
call   1050 <difftime@plt>
xorps  %xmm1,%xmm1
cvtsi2sdl 0x18(%rsp),%xmm1
cmpltsd 0xdcd(%rip),%xmm0
andpd  %xmm0,%xmm1
movsd  0xdc9(%rip),%xmm2
andnpd %xmm2,%xmm0
orpd   %xmm1,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sdl 0x20(%rsp),%xmm1
cvttsd2si %xmm0,%eax
movsd  0x38(%rsp),%xmm0
addsd  %xmm1,%xmm0
mov    %ebx,%ecx
mov    %eax,(%r14,%rcx,4)
movsd  %xmm0,(%r15,%rcx,8)
add    $0x1,%ebx
addl   $0x1,0x28(%rsp)
lea    0x28(%rsp),%rdi
call   1070 <mktime@plt>
mov    %eax,%r13d
cmp    %ebp,0x2c(%rsp)
je     12c1 <fillCalendar+0x171>
jmp    12d2 <fillCalendar+0x182>
nop
mov    0x24(%rsp),%edi
mov    %edi,0x44(%rsp)
mov    0x18(%rsp),%esi
mov    %esi,0x20(%rsp)
mov    0x14(%rsp),%eax
mov    %eax,0x1c(%rsp)
lea    0x24(%rsp),%rdx
lea    0x18(%rsp),%rcx
call   1040 <lunphi_next@plt>
mov    %eax,0x14(%rsp)
cmp    %ebp,0x2c(%rsp)
jne    12d2 <fillCalendar+0x182>
lea    0x1(%r12),%eax
test   %r12d,%r12d
mov    %eax,%r12d
jne    11e0 <fillCalendar+0x90>
mov    %ebx,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32 }
define i32 @fillCalendar(i32 %0, i32 %1, double* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca double*
%8 = alloca i32*
%9 = alloca %struct.tm
%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 double
%20 = alloca double
%21 = alloca double
%22 = alloca double
%23 = alloca double
store i32 %0, i32* %5
store i32 %1, i32* %6
store double* %2, double** %7
store i32* %3, i32** %8
store i32 0, i32* %17
store i32 42, i32* %18
%24 = call i32 @memset(%struct.tm* %9, i32 0, i32 12)
%25 = getelementptr inbounds %struct.tm, %struct.tm* %9, i32 0, i32 0
store i32 1, i32* %25
%26 = load i32, i32* %6
%27 = sub nsw i32 %26, 1
%28 = getelementptr inbounds %struct.tm, %struct.tm* %9, i32 0, i32 1
store i32 %27, i32* %28
%29 = load i32, i32* %5
%30 = sub nsw i32 %29, 1900
%31 = getelementptr inbounds %struct.tm, %struct.tm* %9, i32 0, i32 2
store i32 %30, i32* %31
%32 = call i32 @mktime(%struct.tm* %9)
store i32 %32, i32* %10
%33 = load i32, i32* %10
%34 = call i32 @lunationEdgesOfTime(i32 %33, i32* %13, i32* %15, i32* %11, i32* %14, i32* %16, i32* %12)
br label %35
35: ; preds = %97, %4
%36 = load i32, i32* %12
%37 = load i32, i32* %11
%38 = call double @difftime(i32 %36, i32 %37)
store double %38, double* %19
%39 = load i32, i32* %10
%40 = load i32, i32* %11
%41 = call double @difftime(i32 %39, i32 %40)
store double %41, double* %20
%42 = load double, double* %20
%43 = load double, double* %19
%44 = fdiv double %42, %43
store double %44, double* %23
%45 = load double, double* %23
%46 = fcmp olt double %45, 1.000000e+00
br i1 %46, label %47, label %79
47: ; preds = %35
%48 = load i32, i32* %12
%49 = load i32, i32* %10
%50 = call double @difftime(i32 %48, i32 %49)
store double %50, double* %21
%51 = load double, double* %23
%52 = load i32, i32* %15
%53 = sitofp i32 %52 to double
%54 = fadd double %51, %53
store double %54, double* %22
%55 = load double, double* %21
%56 = fcmp olt double %55, 8.640000e+04
br i1 %56, label %57, label %60
57: ; preds = %47
%58 = load i32, i32* %16
%59 = sitofp i32 %58 to double
br label %61
60: ; preds = %47
br label %61
61: ; preds = %60, %57
%62 = phi double [ %59, %57 ], [ -1.000000e+00, %60 ]
%63 = fptosi double %62 to i32
%64 = load i32*, i32** %8
%65 = load i32, i32* %17
%66 = zext i32 %65 to i64
%67 = getelementptr inbounds i32, i32* %64, i64 %66
store i32 %63, i32* %67
%68 = load double, double* %22
%69 = load double*, double** %7
%70 = load i32, i32* %17
%71 = zext i32 %70 to i64
%72 = getelementptr inbounds double, double* %69, i64 %71
store double %68, double* %72
%73 = load i32, i32* %17
%74 = add i32 %73, 1
store i32 %74, i32* %17
%75 = getelementptr inbounds %struct.tm, %struct.tm* %9, i32 0, i32 0
%76 = load i32, i32* %75
%77 = add nsw i32 %76, 1
store i32 %77, i32* %75
%78 = call i32 @mktime(%struct.tm* %9)
store i32 %78, i32* %10
br label %86
79: ; preds = %35
%80 = load i32, i32* %14
store i32 %80, i32* %13
%81 = load i32, i32* %16
store i32 %81, i32* %15
%82 = load i32, i32* %12
store i32 %82, i32* %11
%83 = load i32, i32* %13
%84 = load i32, i32* %15
%85 = call i32 @lunphi_next(i32 %83, i32 %84, i32* %14, i32* %16)
store i32 %85, i32* %12
br label %86
86: ; preds = %79, %61
br label %87
87: ; preds = %86
%88 = getelementptr inbounds %struct.tm, %struct.tm* %9, i32 0, i32 1
%89 = load i32, i32* %88
%90 = load i32, i32* %6
%91 = sub nsw i32 %90, 1
%92 = icmp eq i32 %89, %91
br i1 %92, label %93, label %97
93: ; preds = %87
%94 = load i32, i32* %18
%95 = add i32 %94, -1
store i32 %95, i32* %18
%96 = icmp ne i32 %94, 0
br label %97
97: ; preds = %93, %87
%98 = phi i1 [ false, %87 ], [ %96, %93 ]
br i1 %98, label %35, label %99
99: ; preds = %97
%100 = load i32, i32* %17
ret i32 %100
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32 }
define i32 @fillCalendar(i32 %0, i32 %1, double* nocapture writeonly %2, i32* nocapture writeonly %3) {
%5 = alloca %struct.tm
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = bitcast %struct.tm* %5 to i8*
%13 = bitcast i32* %6 to i8*
%14 = bitcast i32* %7 to i8*
%15 = bitcast i32* %8 to i8*
%16 = bitcast i32* %9 to i8*
%17 = bitcast i32* %10 to i8*
%18 = bitcast i32* %11 to i8*
%19 = call i32 @memset(%struct.tm* %5, i32 0, i32 12)
%20 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 0
store i32 1, i32* %20
%21 = add nsw i32 %1, -1
%22 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 1
store i32 %21, i32* %22
%23 = add nsw i32 %0, -1900
%24 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 2
store i32 %23, i32* %24
%25 = call i32 @mktime(%struct.tm* %5)
%26 = call i32 @lunationEdgesOfTime(i32 %25, i32* %8, i32* %10, i32* %6, i32* %9, i32* %11, i32* %7)
br label %27
27: ; preds = %61, %4
%28 = phi i32 [ 42, %4 ], [ %66, %61 ]
%29 = phi i32 [ 0, %4 ], [ %62, %61 ]
%30 = phi i32 [ %25, %4 ], [ %63, %61 ]
%31 = load i32, i32* %7
%32 = load i32, i32* %6
%33 = call double @difftime(i32 %31, i32 %32)
%34 = load i32, i32* %6
%35 = call double @difftime(i32 %30, i32 %34)
%36 = fdiv double %35, %33
%37 = fcmp olt double %36, 1.000000e+00
br i1 %37, label %38, label %56
38: ; preds = %27
%39 = load i32, i32* %7
%40 = call double @difftime(i32 %39, i32 %30)
%41 = load i32, i32* %10
%42 = sitofp i32 %41 to double
%43 = fadd double %36, %42
%44 = fcmp olt double %40, 8.640000e+04
%45 = load i32, i32* %11
%46 = sitofp i32 %45 to double
%47 = select i1 %44, double %46, double -1.000000e+00
%48 = fptosi double %47 to i32
%49 = zext i32 %29 to i64
%50 = getelementptr inbounds i32, i32* %3, i64 %49
store i32 %48, i32* %50
%51 = getelementptr inbounds double, double* %2, i64 %49
store double %43, double* %51
%52 = add i32 %29, 1
%53 = load i32, i32* %20
%54 = add nsw i32 %53, 1
store i32 %54, i32* %20
%55 = call i32 @mktime(%struct.tm* %5)
br label %61
56: ; preds = %27
%57 = load i32, i32* %9
store i32 %57, i32* %8
%58 = load i32, i32* %11
store i32 %58, i32* %10
%59 = load i32, i32* %7
store i32 %59, i32* %6
%60 = call i32 @lunphi_next(i32 %57, i32 %58, i32* %9, i32* %11)
store i32 %60, i32* %7
br label %61
61: ; preds = %56, %38
%62 = phi i32 [ %52, %38 ], [ %29, %56 ]
%63 = phi i32 [ %55, %38 ], [ %30, %56 ]
%64 = load i32, i32* %22
%65 = icmp ne i32 %64, %21
%66 = add nsw i32 %28, -1
%67 = icmp eq i32 %28, 0
%68 = select i1 %65, i1 true, i1 %67
br i1 %68, label %69, label %27
69: ; preds = %61
ret i32 %62
}