#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 */
scalar_t__ floor(double);
double fmod(double, double);
void mjd2cal(double mjd, int *day, int *month, int *year, double *ut) {
  int jd, temp1, temp2;
  *ut = fmod(mjd, 1.0);
  if (*ut < 0.0) {
    *ut += 1.0;
    mjd -= 1;
  }
  jd = (int)floor(mjd + 2400001);
  temp1 = 4 * (jd + ((6 * (((4 * jd - 17918) / 146097))) / 4 + 1) / 2 - 37);
  temp2 = 10 * (((temp1 - 237) % 1461) / 4) + 5;
  *year = temp1 / 1461 - 4712;
  *month = ((temp2 / 306 + 2) % 12) + 1;
  *day = (temp2 % 306) / 10 + 1;
}


x86 assembly (clang, -O0):
<mjd2cal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xeb6(%rip),%xmm1
call   1030 <fmod@plt>
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x28(%rbp),%rax
xorps  %xmm0,%xmm0
ucomisd (%rax),%xmm0
jbe    1192 <mjd2cal+0x72>
mov    -0x28(%rbp),%rax
movsd  0xe8c(%rip),%xmm0
addsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
movsd  -0x8(%rbp),%xmm0
movsd  0xe77(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  0xe6e(%rip),%xmm0
addsd  -0x8(%rbp),%xmm0
call   1040 <floor@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x2c(%rbp),%eax
shl    $0x2,%eax
sub    $0x45fe,%eax
mov    $0x23ab1,%ecx
cltd
idiv   %ecx
imul   $0x6,%eax,%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
add    $0x1,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
add    %ecx,%eax
sub    $0x25,%eax
shl    $0x2,%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
sub    $0xed,%eax
mov    $0x5b5,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
imul   $0xa,%eax,%eax
add    $0x5,%eax
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%eax
mov    $0x5b5,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
sub    $0x1268,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x34(%rbp),%eax
mov    $0x132,%ecx
cltd
idiv   %ecx
add    $0x2,%eax
mov    $0xc,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    -0x18(%rbp),%rax
mov    %edx,(%rax)
mov    -0x34(%rbp),%eax
mov    $0x132,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
add    $0x1,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mjd2cal>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    %rdx,%r12
mov    %rsi,%r15
mov    %rdi,%r14
movsd  0xec4(%rip),%xmm1
movsd  %xmm0,(%rsp)
call   1030 <fmod@plt>
movsd  %xmm0,(%rbx)
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jbe    116f <mjd2cal+0x4f>
addsd  0xea4(%rip),%xmm0
movsd  %xmm0,(%rbx)
movsd  (%rsp),%xmm0
addsd  0xe9b(%rip),%xmm0
jmp    1174 <mjd2cal+0x54>
movsd  (%rsp),%xmm0
addsd  0xe94(%rip),%xmm0
call   1040 <floor@plt>
lea    -0x45fe(,%rax,4),%ecx
movslq %ecx,%rcx
imul   $0x396b06bd,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x2f,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,2),%edx
lea    (%rcx,%rcx,2),%ecx
add    $0x3,%ecx
test   %edx,%edx
cmovns %edx,%ecx
shr    $0x2,%ecx
add    $0x1,%ecx
movzwl %cx,%ecx
mov    %ecx,%edx
shr    $0xf,%edx
add    %ecx,%edx
movswl %dx,%ecx
sar    %ecx
add    %eax,%ecx
lea    -0x94(,%rcx,4),%edx
lea    -0x181(,%rcx,4),%eax
cltq
imul   $0x166db073,%rax,%rcx
mov    %rcx,%rsi
shr    $0x3f,%rsi
sar    $0x27,%rcx
add    %esi,%ecx
imul   $0x5b5,%ecx,%ecx
sub    %ecx,%eax
lea    0x3(%rax),%ecx
test   %ax,%ax
cmovns %eax,%ecx
movswl %cx,%eax
sar    $0x2,%eax
lea    (%rax,%rax,4),%eax
add    %eax,%eax
add    $0x5,%eax
movslq %edx,%rcx
imul   $0x166db073,%rcx,%rcx
mov    %rcx,%rdx
sar    $0x27,%rdx
shr    $0x3f,%rcx
add    %edx,%ecx
add    $0xffffed98,%ecx
mov    %ecx,(%r12)
movswl %ax,%ecx
imul   $0x358b,%ecx,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x16,%ecx
add    %edx,%ecx
lea    0x2(%rcx),%edx
movsbl %dl,%edx
imul   $0x2b,%edx,%esi
movzwl %si,%edi
shr    $0x9,%esi
shr    $0xf,%edi
add    %sil,%dil
movzbl %dil,%esi
shl    $0x2,%esi
lea    (%rsi,%rsi,2),%esi
sub    %sil,%dl
add    $0x1,%dl
movsbl %dl,%edx
mov    %edx,(%r15)
imul   $0x132,%ecx,%ecx
sub    %ecx,%eax
cwtl
imul   $0x6667,%eax,%eax
mov    %eax,%ecx
sar    $0x12,%ecx
shr    $0x1f,%eax
add    %ecx,%eax
add    $0x1,%eax
cwtl
mov    %eax,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @mjd2cal(double %0, i32* %1, i32* %2, i32* %3, double* %4) {
%6 = alloca double
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca double*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store double %0, double* %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
store double* %4, double** %10
%14 = load double, double* %6
%15 = call double @fmod(double %14, double 1.000000e+00)
%16 = load double*, double** %10
store double %15, double* %16
%17 = load double*, double** %10
%18 = load double, double* %17
%19 = fcmp olt double %18, 0.000000e+00
br i1 %19, label %20, label %26
20: ; preds = %5
%21 = load double*, double** %10
%22 = load double, double* %21
%23 = fadd double %22, 1.000000e+00
store double %23, double* %21
%24 = load double, double* %6
%25 = fsub double %24, 1.000000e+00
store double %25, double* %6
br label %26
26: ; preds = %20, %5
%27 = load double, double* %6
%28 = fadd double %27, 0x41424F8080000000
%29 = call i64 @floor(double %28)
%30 = trunc i64 %29 to i32
store i32 %30, i32* %11
%31 = load i32, i32* %11
%32 = load i32, i32* %11
%33 = mul nsw i32 4, %32
%34 = sub nsw i32 %33, 17918
%35 = sdiv i32 %34, 146097
%36 = mul nsw i32 6, %35
%37 = sdiv i32 %36, 4
%38 = add nsw i32 %37, 1
%39 = sdiv i32 %38, 2
%40 = add nsw i32 %31, %39
%41 = sub nsw i32 %40, 37
%42 = mul nsw i32 4, %41
store i32 %42, i32* %12
%43 = load i32, i32* %12
%44 = sub nsw i32 %43, 237
%45 = srem i32 %44, 1461
%46 = sdiv i32 %45, 4
%47 = mul nsw i32 10, %46
%48 = add nsw i32 %47, 5
store i32 %48, i32* %13
%49 = load i32, i32* %12
%50 = sdiv i32 %49, 1461
%51 = sub nsw i32 %50, 4712
%52 = load i32*, i32** %9
store i32 %51, i32* %52
%53 = load i32, i32* %13
%54 = sdiv i32 %53, 306
%55 = add nsw i32 %54, 2
%56 = srem i32 %55, 12
%57 = add nsw i32 %56, 1
%58 = load i32*, i32** %8
store i32 %57, i32* %58
%59 = load i32, i32* %13
%60 = srem i32 %59, 306
%61 = sdiv i32 %60, 10
%62 = add nsw i32 %61, 1
%63 = load i32*, i32** %7
store i32 %62, i32* %63
ret void
}

LLVM IR (-O2):
define void @mjd2cal(double %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3, double* nocapture writeonly %4) {
%6 = tail call double @fmod(double %0, double 1.000000e+00)
store double %6, double* %4
%7 = fcmp olt double %6, 0.000000e+00
br i1 %7, label %8, label %11
8: ; preds = %5
%9 = fadd double %6, 1.000000e+00
store double %9, double* %4
%10 = fadd double %0, -1.000000e+00
br label %11
11: ; preds = %8, %5
%12 = phi double [ %10, %8 ], [ %0, %5 ]
%13 = fadd double %12, 0x41424F8080000000
%14 = tail call i64 @floor(double %13)
%15 = trunc i64 %14 to i32
%16 = shl nsw i32 %15, 2
%17 = add nsw i32 %16, -17918
%18 = sdiv i32 %17, 146097
%19 = mul nsw i32 %18, 6
%20 = sdiv i32 %19, 4
%21 = trunc i32 %20 to i16
%22 = add nsw i16 %21, 1
%23 = sdiv i16 %22, 2
%24 = sext i16 %23 to i32
%25 = add nsw i32 %24, %15
%26 = shl i32 %25, 2
%27 = add i32 %26, -148
%28 = add i32 %26, -385
%29 = srem i32 %28, 1461
%30 = trunc i32 %29 to i16
%31 = sdiv i16 %30, 4
%32 = mul nsw i16 %31, 10
%33 = add nsw i16 %32, 5
%34 = sdiv i32 %27, 1461
%35 = add nsw i32 %34, -4712
store i32 %35, i32* %3
%36 = sdiv i16 %33, 306
%37 = trunc i16 %36 to i8
%38 = add nsw i8 %37, 2
%39 = srem i8 %38, 12
%40 = add nsw i8 %39, 1
%41 = sext i8 %40 to i32
store i32 %41, i32* %2
%42 = srem i16 %33, 306
%43 = sdiv i16 %42, 10
%44 = add nsw i16 %43, 1
%45 = sext i16 %44 to i32
store i32 %45, i32* %1
ret void
}