#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*/ cal_mjd(int, double, int, double *);
int /*<<< orphan*/ mjd_cal(double, int *, double *, int *);
void mjd_year(double mj, double *yr) {
  static double last_mj, last_yr;
  int m, y;
  double d;
  double e0, e1;
  if (mj == last_mj) {
    *yr = last_yr;
    return;
  }
  mjd_cal(mj, &m, &d, &y);
  if (y == -1)
    y = -2;
  cal_mjd(1, 1.0, y, &e0);
  cal_mjd(1, 1.0, y + 1, &e1);
  *yr = y + (mj - e0) / (e1 - e0);
  last_mj = mj;
  last_yr = *yr;
}


x86 assembly (clang, -O0):
<mjd_year>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
ucomisd 0x2efa(%rip),%xmm0
jne    115f <mjd_year+0x3f>
jp     115f <mjd_year+0x3f>
movsd  0x2eee(%rip),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    1201 <mjd_year+0xe1>
movsd  -0x8(%rbp),%xmm0
lea    -0x14(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1030 <mjd_cal@plt>
cmpl   $0xffffffff,-0x18(%rbp)
jne    1186 <mjd_year+0x66>
movl   $0xfffffffe,-0x18(%rbp)
mov    -0x18(%rbp),%esi
mov    $0x1,%edi
movsd  0xe6a(%rip),%xmm0
lea    -0x28(%rbp),%rdx
call   1040 <cal_mjd@plt>
mov    -0x18(%rbp),%esi
add    $0x1,%esi
mov    $0x1,%edi
movsd  0xe4e(%rip),%xmm0
lea    -0x30(%rbp),%rdx
call   1040 <cal_mjd@plt>
cvtsi2sdl -0x18(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm1
subsd  -0x28(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm2
subsd  -0x28(%rbp),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,0x2e47(%rip)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,0x2e3f(%rip)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mjd_year>:
push   %rbx
sub    $0x30,%rsp
mov    %rdi,%rbx
movsd  0x2f08(%rip),%xmm1
ucomisd %xmm0,%xmm1
jne    1149 <mjd_year+0x29>
jp     1149 <mjd_year+0x29>
movsd  0x2f00(%rip),%xmm0
movsd  %xmm0,(%rbx)
jmp    11f1 <mjd_year+0xd1>
lea    0x24(%rsp),%rdi
lea    0x28(%rsp),%rsi
lea    0x4(%rsp),%rdx
movsd  %xmm0,0x8(%rsp)
call   1030 <mjd_cal@plt>
mov    0x4(%rsp),%esi
cmp    $0xffffffff,%esi
jne    1179 <mjd_year+0x59>
movl   $0xfffffffe,0x4(%rsp)
ff
mov    $0xfffffffe,%esi
movsd  0xe7f(%rip),%xmm0
lea    0x18(%rsp),%rdx
mov    $0x1,%edi
call   1040 <cal_mjd@plt>
mov    0x4(%rsp),%esi
add    $0x1,%esi
lea    0x10(%rsp),%rdx
mov    $0x1,%edi
movsd  0xe57(%rip),%xmm0
call   1040 <cal_mjd@plt>
xorps  %xmm0,%xmm0
cvtsi2sdl 0x4(%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
movsd  0x8(%rsp),%xmm4
movapd %xmm4,%xmm2
subsd  %xmm1,%xmm2
movsd  0x10(%rsp),%xmm3
subsd  %xmm1,%xmm3
divsd  %xmm3,%xmm2
addsd  %xmm0,%xmm2
movsd  %xmm2,(%rbx)
movsd  %xmm4,0x2e4f(%rip)
movsd  %xmm2,0x2e4f(%rip)
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@mjd_year.last_mj = internal global double 0.000000e+00
@mjd_year.last_yr = internal global double 0.000000e+00
define void @mjd_year(double %0, double* %1) {
%3 = alloca double
%4 = alloca double*
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
%8 = alloca double
%9 = alloca double
store double %0, double* %3
store double* %1, double** %4
%10 = load double, double* %3
%11 = load double, double* @mjd_year.last_mj
%12 = fcmp oeq double %10, %11
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load double, double* @mjd_year.last_yr
%15 = load double*, double** %4
store double %14, double* %15
br label %42
16: ; preds = %2
%17 = load double, double* %3
%18 = call i32 @mjd_cal(double %17, i32* %5, double* %7, i32* %6)
%19 = load i32, i32* %6
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %22
21: ; preds = %16
store i32 -2, i32* %6
br label %22
22: ; preds = %21, %16
%23 = load i32, i32* %6
%24 = call i32 @cal_mjd(i32 1, double 1.000000e+00, i32 %23, double* %8)
%25 = load i32, i32* %6
%26 = add nsw i32 %25, 1
%27 = call i32 @cal_mjd(i32 1, double 1.000000e+00, i32 %26, double* %9)
%28 = load i32, i32* %6
%29 = sitofp i32 %28 to double
%30 = load double, double* %3
%31 = load double, double* %8
%32 = fsub double %30, %31
%33 = load double, double* %9
%34 = load double, double* %8
%35 = fsub double %33, %34
%36 = fdiv double %32, %35
%37 = fadd double %29, %36
%38 = load double*, double** %4
store double %37, double* %38
%39 = load double, double* %3
store double %39, double* @mjd_year.last_mj
%40 = load double*, double** %4
%41 = load double, double* %40
store double %41, double* @mjd_year.last_yr
br label %42
42: ; preds = %22, %13
ret void
}

LLVM IR (-O2):
@mjd_year.last_mj = internal unnamed_addr global double 0.000000e+00
@mjd_year.last_yr = internal unnamed_addr global double 0.000000e+00
define void @mjd_year(double %0, double* nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = bitcast i32* %3 to i8*
%9 = bitcast i32* %4 to i8*
%10 = bitcast double* %5 to i8*
%11 = bitcast double* %6 to i8*
%12 = bitcast double* %7 to i8*
%13 = load double, double* @mjd_year.last_mj
%14 = fcmp oeq double %13, %0
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = load double, double* @mjd_year.last_yr
store double %16, double* %1
br label %36
17: ; preds = %2
%18 = call i32 @mjd_cal(double %0, i32* %3, double* %5, i32* %4)
%19 = load i32, i32* %4
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %22
21: ; preds = %17
store i32 -2, i32* %4
br label %22
22: ; preds = %21, %17
%23 = phi i32 [ -2, %21 ], [ %19, %17 ]
%24 = call i32 @cal_mjd(i32 1, double 1.000000e+00, i32 %23, double* %6)
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 1
%27 = call i32 @cal_mjd(i32 1, double 1.000000e+00, i32 %26, double* %7)
%28 = load i32, i32* %4
%29 = sitofp i32 %28 to double
%30 = load double, double* %6
%31 = fsub double %0, %30
%32 = load double, double* %7
%33 = fsub double %32, %30
%34 = fdiv double %31, %33
%35 = fadd double %34, %29
store double %35, double* %1
store double %0, double* @mjd_year.last_mj
store double %35, double* @mjd_year.last_yr
br label %36
36: ; preds = %22, %15
ret void
}