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

/* Variables and functions */
double Frac(double);
double Int(double);
int Round(double);
scalar_t__ floor(double);
void Calendar_Date(double jd, struct tm *cdate) {
  int Z, month;
  double A, B, C, D, E, F, alpha, day, year, factor;
  factor = 0.5 / 8.6400E4 / 1000;
  F = Frac(jd + 0.5);
  if (F + factor >= 1.0) {
    jd = jd + factor;
    F = 0.0;
  }
  Z = Round(jd);
  if (Z < 2299161)
    A = Z;
  else {
    alpha = Int((Z - 1867216.25) / 36524.25);
    A = Z + 1 + alpha - Int(alpha / 4);
  }
  B = A + 1524;
  C = Int((B - 122.1) / 365.25);
  D = Int(365.25 * C);
  E = Int((B - D) / 30.6001);
  day = B - D - Int(30.6001 * E) + F;
  if (E < 13.5)
    month = Round(E - 1);
  else
    month = Round(E - 13);
  if (month > 2.5)
    year = C - 4716;
  else
    year = C - 4715;
  cdate->tm_year = (int)year;
  cdate->tm_mon = month;
  cdate->tm_mday = (int)floor(day);
}


x86 assembly (clang, -O0):
<Calendar_Date>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
movsd  0xeb4(%rip),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  0xe9f(%rip),%xmm0
addsd  -0x8(%rbp),%xmm0
call   1030 <Frac@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
addsd  -0x68(%rbp),%xmm0
movsd  0xe76(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11ab <Calendar_Date+0x6b>
movsd  -0x8(%rbp),%xmm0
addsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1050 <Round@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x231519,-0x14(%rbp)
jge    11d4 <Calendar_Date+0x94>
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1236 <Calendar_Date+0xf6>
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  0xe47(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  0xe33(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1040 <Int@plt>
movsd  %xmm0,-0x50(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm0
addsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  0xdfc(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1040 <Int@plt>
movaps %xmm0,%xmm1
movsd  -0x70(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe12(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  0xdf3(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  0xddf(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1040 <Int@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  0xdc9(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
call   1040 <Int@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
movsd  0xda0(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1040 <Int@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  0xd7b(%rip),%xmm0
mulsd  -0x40(%rbp),%xmm0
call   1040 <Int@plt>
movaps %xmm0,%xmm1
movsd  -0x78(%rbp),%xmm0
subsd  %xmm1,%xmm0
addsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  0xd4b(%rip),%xmm0
ucomisd -0x40(%rbp),%xmm0
jbe    130e <Calendar_Date+0x1ce>
movsd  -0x40(%rbp),%xmm0
movsd  0xd03(%rip),%xmm1
subsd  %xmm1,%xmm0
call   1050 <Round@plt>
mov    %eax,-0x18(%rbp)
jmp    1327 <Calendar_Date+0x1e7>
movsd  -0x40(%rbp),%xmm0
movsd  0xd3d(%rip),%xmm1
subsd  %xmm1,%xmm0
call   1050 <Round@plt>
mov    %eax,-0x18(%rbp)
cvtsi2sdl -0x18(%rbp),%xmm0
movsd  0xd2c(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1359 <Calendar_Date+0x219>
movsd  -0x30(%rbp),%xmm0
movsd  0xd25(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
jmp    136f <Calendar_Date+0x22f>
movsd  -0x30(%rbp),%xmm0
movsd  0xd02(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
cvttsd2si -0x60(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x4(%rax)
movsd  -0x58(%rbp),%xmm0
call   1060 <floor@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x8(%rax)
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Calendar_Date>:
push   %rbp
push   %rbx
sub    $0x58,%rsp
mov    %rdi,%rbx
movapd %xmm0,%xmm1
movapd %xmm0,(%rsp)
movsd  0xea6(%rip),%xmm0
addsd  %xmm1,%xmm0
call   1030 <Frac@plt>
movapd %xmm0,%xmm1
movsd  0xe99(%rip),%xmm0
movapd %xmm1,0x30(%rsp)
addsd  %xmm0,%xmm1
movapd (%rsp),%xmm3
addsd  %xmm3,%xmm0
movsd  0xe86(%rip),%xmm2
cmpnlesd %xmm1,%xmm2
movapd %xmm2,%xmm1
andnpd %xmm0,%xmm1
movapd %xmm2,0x40(%rsp)
andpd  %xmm2,%xmm3
orpd   %xmm1,%xmm3
movapd %xmm3,%xmm0
call   1050 <Round@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
cmp    $0x231519,%eax
jl     1200 <Calendar_Date+0xc0>
mov    %eax,%ebp
addsd  0xe52(%rip),%xmm0
divsd  0xe52(%rip),%xmm0
call   1040 <Int@plt>
add    $0x1,%ebp
xorps  %xmm1,%xmm1
cvtsi2sd %ebp,%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
mulsd  0xe3a(%rip),%xmm0
call   1040 <Int@plt>
movsd  (%rsp),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
addsd  0xe28(%rip),%xmm0
movapd %xmm0,%xmm1
movsd  %xmm0,(%rsp)
movsd  0xe1f(%rip),%xmm0
addsd  %xmm1,%xmm0
divsd  0xe1b(%rip),%xmm0
call   1040 <Int@plt>
movsd  %xmm0,0x28(%rsp)
movsd  0xe08(%rip),%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
call   1040 <Int@plt>
movsd  (%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movapd %xmm1,%xmm0
divsd  0xde9(%rip),%xmm0
call   1040 <Int@plt>
movsd  %xmm0,0x18(%rsp)
movsd  0xdde(%rip),%xmm1
xor    %ebp,%ebp
ucomisd %xmm0,%xmm1
seta   %bpl
movsd  0xdc4(%rip),%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
call   1040 <Int@plt>
movsd  %xmm0,0x20(%rsp)
lea    0xdba(%rip),%rax
movsd  0x18(%rsp),%xmm0
addsd  (%rax,%rbp,8),%xmm0
call   1050 <Round@plt>
xor    %ecx,%ecx
cmp    $0x3,%eax
setge  %cl
movapd 0x40(%rsp),%xmm0
andpd  0x30(%rsp),%xmm0
lea    0xd9f(%rip),%rdx
movsd  0x28(%rsp),%xmm2
addsd  (%rdx,%rcx,8),%xmm2
movsd  (%rsp),%xmm1
subsd  0x20(%rsp),%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
cvttsd2si %xmm2,%ecx
mov    %ecx,(%rbx)
mov    %eax,0x4(%rbx)
call   1060 <floor@plt>
mov    %eax,0x8(%rbx)
add    $0x58,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32 }
define void @Calendar_Date(double %0, %struct.tm* %1) {
%3 = alloca double
%4 = alloca %struct.tm*
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca double
store double %0, double* %3
store %struct.tm* %1, %struct.tm** %4
store double 0x3E38DAEA1D7F4CF7, double* %16
%17 = load double, double* %3
%18 = fadd double %17, 5.000000e-01
%19 = call double @Frac(double %18)
store double %19, double* %12
%20 = load double, double* %12
%21 = load double, double* %16
%22 = fadd double %20, %21
%23 = fcmp oge double %22, 1.000000e+00
br i1 %23, label %24, label %28
24: ; preds = %2
%25 = load double, double* %3
%26 = load double, double* %16
%27 = fadd double %25, %26
store double %27, double* %3
store double 0.000000e+00, double* %12
br label %28
28: ; preds = %24, %2
%29 = load double, double* %3
%30 = call i32 @Round(double %29)
store i32 %30, i32* %5
%31 = load i32, i32* %5
%32 = icmp slt i32 %31, 2299161
br i1 %32, label %33, label %36
33: ; preds = %28
%34 = load i32, i32* %5
%35 = sitofp i32 %34 to double
store double %35, double* %7
br label %51
36: ; preds = %28
%37 = load i32, i32* %5
%38 = sitofp i32 %37 to double
%39 = fsub double %38, 0x413C7DD040000000
%40 = fdiv double %39, 0x40E1D58800000000
%41 = call double @Int(double %40)
store double %41, double* %13
%42 = load i32, i32* %5
%43 = add nsw i32 %42, 1
%44 = sitofp i32 %43 to double
%45 = load double, double* %13
%46 = fadd double %44, %45
%47 = load double, double* %13
%48 = fdiv double %47, 4.000000e+00
%49 = call double @Int(double %48)
%50 = fsub double %46, %49
store double %50, double* %7
br label %51
51: ; preds = %36, %33
%52 = load double, double* %7
%53 = fadd double %52, 1.524000e+03
store double %53, double* %8
%54 = load double, double* %8
%55 = fsub double %54, 1.221000e+02
%56 = fdiv double %55, 3.652500e+02
%57 = call double @Int(double %56)
store double %57, double* %9
%58 = load double, double* %9
%59 = fmul double 3.652500e+02, %58
%60 = call double @Int(double %59)
store double %60, double* %10
%61 = load double, double* %8
%62 = load double, double* %10
%63 = fsub double %61, %62
%64 = fdiv double %63, 3.060010e+01
%65 = call double @Int(double %64)
store double %65, double* %11
%66 = load double, double* %8
%67 = load double, double* %10
%68 = fsub double %66, %67
%69 = load double, double* %11
%70 = fmul double 3.060010e+01, %69
%71 = call double @Int(double %70)
%72 = fsub double %68, %71
%73 = load double, double* %12
%74 = fadd double %72, %73
store double %74, double* %14
%75 = load double, double* %11
%76 = fcmp olt double %75, 1.350000e+01
br i1 %76, label %77, label %81
77: ; preds = %51
%78 = load double, double* %11
%79 = fsub double %78, 1.000000e+00
%80 = call i32 @Round(double %79)
store i32 %80, i32* %6
br label %85
81: ; preds = %51
%82 = load double, double* %11
%83 = fsub double %82, 1.300000e+01
%84 = call i32 @Round(double %83)
store i32 %84, i32* %6
br label %85
85: ; preds = %81, %77
%86 = load i32, i32* %6
%87 = sitofp i32 %86 to double
%88 = fcmp ogt double %87, 2.500000e+00
br i1 %88, label %89, label %92
89: ; preds = %85
%90 = load double, double* %9
%91 = fsub double %90, 4.716000e+03
store double %91, double* %15
br label %95
92: ; preds = %85
%93 = load double, double* %9
%94 = fsub double %93, 4.715000e+03
store double %94, double* %15
br label %95
95: ; preds = %92, %89
%96 = load double, double* %15
%97 = fptosi double %96 to i32
%98 = load %struct.tm*, %struct.tm** %4
%99 = getelementptr inbounds %struct.tm, %struct.tm* %98, i32 0, i32 0
store i32 %97, i32* %99
%100 = load i32, i32* %6
%101 = load %struct.tm*, %struct.tm** %4
%102 = getelementptr inbounds %struct.tm, %struct.tm* %101, i32 0, i32 1
store i32 %100, i32* %102
%103 = load double, double* %14
%104 = call i64 @floor(double %103)
%105 = trunc i64 %104 to i32
%106 = load %struct.tm*, %struct.tm** %4
%107 = getelementptr inbounds %struct.tm, %struct.tm* %106, i32 0, i32 2
store i32 %105, i32* %107
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32 }
define void @Calendar_Date(double %0, %struct.tm* nocapture writeonly %1) {
%3 = fadd double %0, 5.000000e-01
%4 = tail call double @Frac(double %3)
%5 = fadd double %4, 0x3E38DAEA1D7F4CF7
%6 = fcmp ult double %5, 1.000000e+00
%7 = fadd double %0, 0x3E38DAEA1D7F4CF7
%8 = select i1 %6, double %0, double %7
%9 = tail call i32 @Round(double %8)
%10 = icmp slt i32 %9, 2299161
%11 = sitofp i32 %9 to double
br i1 %10, label %22, label %12
12: ; preds = %2
%13 = fadd double %11, 0xC13C7DD040000000
%14 = fdiv double %13, 0x40E1D58800000000
%15 = tail call double @Int(double %14)
%16 = add nuw nsw i32 %9, 1
%17 = sitofp i32 %16 to double
%18 = fadd double %15, %17
%19 = fmul double %15, 2.500000e-01
%20 = tail call double @Int(double %19)
%21 = fsub double %18, %20
br label %22
22: ; preds = %2, %12
%23 = phi double [ %21, %12 ], [ %11, %2 ]
%24 = fadd double %23, 1.524000e+03
%25 = fadd double %24, -1.221000e+02
%26 = fdiv double %25, 3.652500e+02
%27 = tail call double @Int(double %26)
%28 = fmul double %27, 3.652500e+02
%29 = tail call double @Int(double %28)
%30 = fsub double %24, %29
%31 = fdiv double %30, 3.060010e+01
%32 = tail call double @Int(double %31)
%33 = fmul double %32, 3.060010e+01
%34 = tail call double @Int(double %33)
%35 = fcmp olt double %32, 1.350000e+01
%36 = select i1 %35, double -1.000000e+00, double -1.300000e+01
%37 = fadd double %32, %36
%38 = tail call i32 @Round(double %37)
%39 = select i1 %6, double %4, double 0.000000e+00
%40 = icmp sgt i32 %38, 2
%41 = select i1 %40, double -4.716000e+03, double -4.715000e+03
%42 = fadd double %27, %41
%43 = fsub double %30, %34
%44 = fadd double %39, %43
%45 = fptosi double %42 to i32
%46 = getelementptr inbounds %struct.tm, %struct.tm* %1, i64 0, i32 0
store i32 %45, i32* %46
%47 = getelementptr inbounds %struct.tm, %struct.tm* %1, i64 0, i32 1
store i32 %38, i32* %47
%48 = tail call i64 @floor(double %44)
%49 = trunc i64 %48 to i32
%50 = getelementptr inbounds %struct.tm, %struct.tm* %1, i64 0, i32 2
store i32 %49, i32* %50
ret void
}