#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 */
int /*<<< orphan*/ assert(int);
double floor(double);
scalar_t__ isLeapYear(long);
int /*<<< orphan*/ unitTest();
double daysPastEpoch(double date) {
  static unsigned unitTested = 0;
  if (!unitTested) {
    unitTest();
    unitTested = 1;
  }
  assert(date > 19000000);
  double year = floor(date / 10000);
  double month = floor(date / 100 - year * 100);
  double day = floor(date - year * 10000 - month * 100);
  const double firstYear = 1900;
  double yearDays = 0;
  for (unsigned yearNumber = firstYear; yearNumber < year - 1; yearNumber++) {
    yearDays += 365 + isLeapYear(yearNumber);
  }
  static double daysPerMonth[] = {0,  31, 28, 31, 30, 31, 30,
                                  31, 31, 30, 31, 30, 31};
  double monthDays = 0;
  for (unsigned monthNumber = 1; monthNumber < month; monthNumber++) {
    monthDays += daysPerMonth[monthNumber];
  }
  double leapDay = 0;
  if (isLeapYear((long)year) && month > 2)
    leapDay = 1;
  return yearDays + monthDays + leapDay + day - 1;
}


x86 assembly (clang, -O0):
<daysPastEpoch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x8(%rbp)
cmpl   $0x0,0x2f68(%rip)
jne    116b <daysPastEpoch+0x2b>
mov    $0x0,%al
call   1030 <unitTest@plt>
movl   $0x1,0x2f51(%rip)
movsd  -0x8(%rbp),%xmm0
movsd  0xea0(%rip),%xmm1
ucomisd %xmm1,%xmm0
seta   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movsd  -0x8(%rbp),%xmm0
movsd  0xe7a(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1060 <floor@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm1
movsd  0xe57(%rip),%xmm0
divsd  %xmm0,%xmm1
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xe2f(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1060 <floor@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
movsd  0xdfc(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xdc8(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1060 <floor@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  0xda6(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x76c,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cvtsi2sd %rax,%xmm1
movsd  -0x10(%rbp),%xmm0
movsd  0xd9d(%rip),%xmm2
subsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jbe    12be <daysPastEpoch+0x17e>
mov    -0x34(%rbp),%eax
mov    %eax,%edi
call   1050 <isLeapYear@plt>
add    $0x16d,%rax
cvtsi2sd %rax,%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    126e <daysPastEpoch+0x12e>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x1,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cvtsi2sd %rax,%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    130d <daysPastEpoch+0x1cd>
mov    -0x44(%rbp),%eax
mov    %eax,%ecx
lea    0x2d60(%rip),%rax
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    12cd <daysPastEpoch+0x18d>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
cvttsd2si -0x10(%rbp),%rdi
call   1050 <isLeapYear@plt>
cmp    $0x0,%rax
je     134e <daysPastEpoch+0x20e>
movsd  -0x18(%rbp),%xmm0
movsd  0xcf1(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    134e <daysPastEpoch+0x20e>
movsd  0xcd7(%rip),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x30(%rbp),%xmm0
addsd  -0x40(%rbp),%xmm0
addsd  -0x50(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  0xcb6(%rip),%xmm1
subsd  %xmm1,%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<daysPastEpoch>:
push   %rbx
sub    $0x40,%rsp
movsd  %xmm0,(%rsp)
cmpb   $0x0,0x2ef3(%rip)
jne    1161 <daysPastEpoch+0x21>
xor    %eax,%eax
call   1030 <unitTest@plt>
movb   $0x1,0x2ee3(%rip)
xor    %edi,%edi
movsd  (%rsp),%xmm0
ucomisd 0xe90(%rip),%xmm0
seta   %dil
call   1040 <assert@plt>
movsd  (%rsp),%xmm0
divsd  0xe82(%rip),%xmm0
call   1060 <floor@plt>
movapd %xmm0,%xmm2
movapd %xmm0,0x20(%rsp)
movsd  0xe73(%rip),%xmm1
movsd  (%rsp),%xmm0
divsd  %xmm1,%xmm0
mulsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
call   1060 <floor@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0xe57(%rip),%xmm0
addsd  0x20(%rsp),%xmm0
ucomisd 0xe51(%rip),%xmm0
xorpd  %xmm1,%xmm1
jbe    122c <daysPastEpoch+0xec>
xorpd  %xmm1,%xmm1
mov    $0x76c,%ebx
movsd  %xmm0,0x10(%rsp)
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  %xmm1,0x18(%rsp)
mov    %ebx,%edi
call   1050 <isLeapYear@plt>
movsd  0x18(%rsp),%xmm1
add    $0x16d,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  %xmm0,%xmm1
add    $0x1,%ebx
xorps  %xmm0,%xmm0
cvtsi2sd %rbx,%xmm0
movsd  0x10(%rsp),%xmm2
ucomisd %xmm0,%xmm2
ja     11f0 <daysPastEpoch+0xb0>
movsd  %xmm1,0x18(%rsp)
movapd 0xe06(%rip),%xmm0
xorpd  0x20(%rsp),%xmm0
movapd %xmm0,0x30(%rsp)
movsd  0x8(%rsp),%xmm1
ucomisd 0xdd4(%rip),%xmm1
xorpd  %xmm2,%xmm2
jbe    1288 <daysPastEpoch+0x148>
xorpd  %xmm2,%xmm2
mov    $0x1,%eax
lea    0xde6(%rip),%rcx
nopw   0x0(%rax,%rax,1)
mov    %eax,%edx
addsd  (%rcx,%rdx,8),%xmm2
add    $0x1,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
ucomisd %xmm0,%xmm1
ja     1270 <daysPastEpoch+0x130>
movsd  %xmm2,0x10(%rsp)
cvttsd2si 0x20(%rsp),%rdi
call   1050 <isLeapYear@plt>
test   %rax,%rax
jne    12b1 <daysPastEpoch+0x171>
xorpd  %xmm0,%xmm0
movapd %xmm0,0x20(%rsp)
movsd  0x8(%rsp),%xmm0
jmp    12d6 <daysPastEpoch+0x196>
movsd  0xd77(%rip),%xmm1
movsd  0x8(%rsp),%xmm0
cmpltsd %xmm0,%xmm1
movsd  0xd5c(%rip),%xmm2
andpd  %xmm1,%xmm2
movapd %xmm2,0x20(%rsp)
movapd 0x30(%rsp),%xmm1
mulsd  0xd24(%rip),%xmm1
addsd  (%rsp),%xmm1
mulsd  0xd47(%rip),%xmm0
addsd  %xmm1,%xmm0
call   1060 <floor@plt>
movsd  0x18(%rsp),%xmm1
addsd  0x10(%rsp),%xmm1
addsd  0x20(%rsp),%xmm1
addsd  %xmm1,%xmm0
addsd  0xd00(%rip),%xmm0
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@daysPastEpoch.unitTested = internal global i32 0
@daysPastEpoch.daysPerMonth = internal global [13 x double] [double 0.000000e+00, double 3.100000e+01, double 2.800000e+01, double 3.100000e+01, double 3.000000e+01, double 3.100000e+01, double 3.000000e+01, double 3.100000e+01, double 3.100000e+01, double 3.000000e+01, double 3.100000e+01, double 3.000000e+01, double 3.100000e+01]
define double @daysPastEpoch(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca i32
%9 = alloca double
%10 = alloca i32
%11 = alloca double
store double %0, double* %2
%12 = load i32, i32* @daysPastEpoch.unitTested
%13 = icmp ne i32 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %1
%15 = call i32 (...) @unitTest()
store i32 1, i32* @daysPastEpoch.unitTested
br label %16
16: ; preds = %14, %1
%17 = load double, double* %2
%18 = fcmp ogt double %17, 1.900000e+07
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = load double, double* %2
%22 = fdiv double %21, 1.000000e+04
%23 = call double @llvm.floor.f64(double %22)
store double %23, double* %3
%24 = load double, double* %2
%25 = fdiv double %24, 1.000000e+02
%26 = load double, double* %3
%27 = fneg double %26
%28 = call double @llvm.fmuladd.f64(double %27, double 1.000000e+02, double %25)
%29 = call double @llvm.floor.f64(double %28)
store double %29, double* %4
%30 = load double, double* %2
%31 = load double, double* %3
%32 = fneg double %31
%33 = call double @llvm.fmuladd.f64(double %32, double 1.000000e+04, double %30)
%34 = load double, double* %4
%35 = fneg double %34
%36 = call double @llvm.fmuladd.f64(double %35, double 1.000000e+02, double %33)
%37 = call double @llvm.floor.f64(double %36)
store double %37, double* %5
store double 1.900000e+03, double* %6
store double 0.000000e+00, double* %7
store i32 1900, i32* %8
br label %38
38: ; preds = %52, %16
%39 = load i32, i32* %8
%40 = uitofp i32 %39 to double
%41 = load double, double* %3
%42 = fsub double %41, 1.000000e+00
%43 = fcmp olt double %40, %42
br i1 %43, label %44, label %55
44: ; preds = %38
%45 = load i32, i32* %8
%46 = zext i32 %45 to i64
%47 = call i64 @isLeapYear(i64 %46)
%48 = add nsw i64 365, %47
%49 = sitofp i64 %48 to double
%50 = load double, double* %7
%51 = fadd double %50, %49
store double %51, double* %7
br label %52
52: ; preds = %44
%53 = load i32, i32* %8
%54 = add i32 %53, 1
store i32 %54, i32* %8
br label %38
55: ; preds = %38
store double 0.000000e+00, double* %9
store i32 1, i32* %10
br label %56
56: ; preds = %68, %55
%57 = load i32, i32* %10
%58 = uitofp i32 %57 to double
%59 = load double, double* %4
%60 = fcmp olt double %58, %59
br i1 %60, label %61, label %71
61: ; preds = %56
%62 = load i32, i32* %10
%63 = zext i32 %62 to i64
%64 = getelementptr inbounds [13 x double], [13 x double]* @daysPastEpoch.daysPerMonth, i64 0, i64 %63
%65 = load double, double* %64
%66 = load double, double* %9
%67 = fadd double %66, %65
store double %67, double* %9
br label %68
68: ; preds = %61
%69 = load i32, i32* %10
%70 = add i32 %69, 1
store i32 %70, i32* %10
br label %56
71: ; preds = %56
store double 0.000000e+00, double* %11
%72 = load double, double* %3
%73 = fptosi double %72 to i64
%74 = call i64 @isLeapYear(i64 %73)
%75 = icmp ne i64 %74, 0
br i1 %75, label %76, label %80
76: ; preds = %71
%77 = load double, double* %4
%78 = fcmp ogt double %77, 2.000000e+00
br i1 %78, label %79, label %80
79: ; preds = %76
store double 1.000000e+00, double* %11
br label %80
80: ; preds = %79, %76, %71
%81 = load double, double* %7
%82 = load double, double* %9
%83 = fadd double %81, %82
%84 = load double, double* %11
%85 = fadd double %83, %84
%86 = load double, double* %5
%87 = fadd double %85, %86
%88 = fsub double %87, 1.000000e+00
ret double %88
}

LLVM IR (-O2):
@daysPastEpoch.unitTested = internal unnamed_addr global i1 false
@daysPastEpoch.daysPerMonth = internal unnamed_addr constant [13 x double] [double 0.000000e+00, double 3.100000e+01, double 2.800000e+01, double 3.100000e+01, double 3.000000e+01, double 3.100000e+01, double 3.000000e+01, double 3.100000e+01, double 3.100000e+01, double 3.000000e+01, double 3.100000e+01, double 3.000000e+01, double 3.100000e+01]
define double @daysPastEpoch(double %0) {
%2 = load i1, i1* @daysPastEpoch.unitTested
br i1 %2, label %5, label %3
3: ; preds = %1
%4 = tail call i32 (...) @unitTest()
store i1 true, i1* @daysPastEpoch.unitTested
br label %5
5: ; preds = %3, %1
%6 = fcmp ogt double %0, 1.900000e+07
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = fdiv double %0, 1.000000e+04
%10 = tail call double @llvm.floor.f64(double %9)
%11 = fdiv double %0, 1.000000e+02
%12 = fneg double %10
%13 = tail call double @llvm.fmuladd.f64(double %12, double 1.000000e+02, double %11)
%14 = tail call double @llvm.floor.f64(double %13)
%15 = fadd double %10, -1.000000e+00
%16 = fcmp ogt double %15, 1.900000e+03
br i1 %16, label %20, label %17
17: ; preds = %20, %5
%18 = phi double [ 0.000000e+00, %5 ], [ %27, %20 ]
%19 = fcmp ogt double %14, 1.000000e+00
br i1 %19, label %47, label %31
20: ; preds = %5, %20
%21 = phi i32 [ %28, %20 ], [ 1900, %5 ]
%22 = phi double [ %27, %20 ], [ 0.000000e+00, %5 ]
%23 = zext i32 %21 to i64
%24 = tail call i64 @isLeapYear(i64 %23)
%25 = add nsw i64 %24, 365
%26 = sitofp i64 %25 to double
%27 = fadd double %22, %26
%28 = add i32 %21, 1
%29 = uitofp i32 %28 to double
%30 = fcmp ogt double %15, %29
br i1 %30, label %20, label %17
31: ; preds = %47, %17
%32 = phi double [ 0.000000e+00, %17 ], [ %53, %47 ]
%33 = fptosi double %10 to i64
%34 = tail call i64 @isLeapYear(i64 %33)
%35 = icmp ne i64 %34, 0
%36 = fcmp ogt double %14, 2.000000e+00
%37 = select i1 %35, i1 %36, i1 false
%38 = select i1 %37, double 1.000000e+00, double 0.000000e+00
%39 = fneg double %14
%40 = tail call double @llvm.fmuladd.f64(double %12, double 1.000000e+04, double %0)
%41 = tail call double @llvm.fmuladd.f64(double %39, double 1.000000e+02, double %40)
%42 = tail call double @llvm.floor.f64(double %41)
%43 = fadd double %18, %32
%44 = fadd double %43, %38
%45 = fadd double %42, %44
%46 = fadd double %45, -1.000000e+00
ret double %46
47: ; preds = %17, %47
%48 = phi i32 [ %54, %47 ], [ 1, %17 ]
%49 = phi double [ %53, %47 ], [ 0.000000e+00, %17 ]
%50 = zext i32 %48 to i64
%51 = getelementptr inbounds [13 x double], [13 x double]* @daysPastEpoch.daysPerMonth, i64 0, i64 %50
%52 = load double, double* %51
%53 = fadd double %49, %52
%54 = add i32 %48, 1
%55 = uitofp i32 %54 to double
%56 = fcmp ogt double %14, %55
br i1 %56, label %47, label %31
}