#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 floor(double);
int /*<<< orphan*/ printf(char *, int, int, int);
void mjd_to_date(long mjd) {
  int day, month, year;
  long julian;
  double y2;
  julian = mjd + 2400001l;
  y2 = julian - 1721119.1 +
       floor(0.75 * floor((julian - 1684594.75) / 36524.25));
  day = floor(y2 - floor(365.25 * floor(y2 / 365.25)) + 122.2);
  year = floor(y2 / 365.25) + floor(day / 429);
  month = floor(day / 30.61) - 1 - floor(day / 429) * 12;
  day = day - floor(30.61 * floor(day / 30.61));
  printf("%2d %2d %4d", day, month, year);
}


x86 assembly (clang, -O0):
<mjd_to_date>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x249f01,%rax
mov    %rax,-0x20(%rbp)
cvtsi2sdq -0x20(%rbp),%xmm0
movsd  0xee8(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
cvtsi2sdq -0x20(%rbp),%xmm0
movsd  0xec9(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  0xeb5(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1040 <floor@plt>
cvtsi2sd %eax,%xmm1
movsd  0xe98(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1040 <floor@plt>
movsd  -0x48(%rbp),%xmm0
cvtsi2sd %eax,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  0xe56(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1040 <floor@plt>
cvtsi2sd %eax,%xmm1
movsd  0xe41(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1040 <floor@plt>
movsd  -0x40(%rbp),%xmm0
cvtsi2sd %eax,%xmm1
subsd  %xmm1,%xmm0
movsd  0xe2b(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1040 <floor@plt>
mov    %eax,-0xc(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  0xe0a(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1040 <floor@plt>
mov    %eax,-0x34(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x1ad,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
call   1040 <floor@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
cvtsi2sdl -0xc(%rbp),%xmm0
movsd  0xdcb(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1040 <floor@plt>
sub    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x1ad,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
call   1040 <floor@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
imul   $0xc,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x2c(%rbp)
cvtsi2sdl -0xc(%rbp),%xmm0
movsd  0xd88(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1040 <floor@plt>
cvtsi2sd %eax,%xmm1
movsd  0xd73(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1040 <floor@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
lea    0xd88(%rip),%rdi
call   1030 <printf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mjd_to_date>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
add    $0x249f01,%rdi
cvtsi2sd %rdi,%xmm0
movsd  0xec2(%rip),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
addsd  0xeb8(%rip),%xmm0
divsd  0xeb8(%rip),%xmm0
call   1040 <floor@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xeac(%rip),%xmm0
call   1040 <floor@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
divsd  0xe94(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
call   1040 <floor@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xe7a(%rip),%xmm0
call   1040 <floor@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0x10(%rsp),%xmm1
subsd  %xmm0,%xmm1
addsd  0xe64(%rip),%xmm1
movapd %xmm1,%xmm0
call   1040 <floor@plt>
mov    %eax,%ebx
movsd  0x8(%rsp),%xmm0
call   1040 <floor@plt>
mov    %eax,%r14d
movslq %ebx,%rbx
imul   $0x13187759,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
add    %ecx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x10(%rsp)
call   1040 <floor@plt>
add    %eax,%r14d
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
divsd  0xe18(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
call   1040 <floor@plt>
mov    %eax,%r15d
movsd  0x10(%rsp),%xmm0
call   1040 <floor@plt>
shl    $0x2,%eax
lea    (%rax,%rax,2),%ebp
not    %ebp
add    %r15d,%ebp
movsd  0x8(%rsp),%xmm0
call   1040 <floor@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xdda(%rip),%xmm0
call   1040 <floor@plt>
sub    %eax,%ebx
lea    0xdd4(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %r14d,%ecx
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"%2d %2d %4d\00"
define void @mjd_to_date(i64 %0) {
%2 = alloca i64
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64
%7 = alloca double
store i64 %0, i64* %2
%8 = load i64, i64* %2
%9 = add nsw i64 %8, 2400001
store i64 %9, i64* %6
%10 = load i64, i64* %6
%11 = sitofp i64 %10 to double
%12 = fsub double %11, 0x413A431F1999999A
%13 = load i64, i64* %6
%14 = sitofp i64 %13 to double
%15 = fsub double %14, 0x4139B472C0000000
%16 = fdiv double %15, 0x40E1D58800000000
%17 = call i32 @floor(double %16)
%18 = sitofp i32 %17 to double
%19 = fmul double 7.500000e-01, %18
%20 = call i32 @floor(double %19)
%21 = sitofp i32 %20 to double
%22 = fadd double %12, %21
store double %22, double* %7
%23 = load double, double* %7
%24 = load double, double* %7
%25 = fdiv double %24, 3.652500e+02
%26 = call i32 @floor(double %25)
%27 = sitofp i32 %26 to double
%28 = fmul double 3.652500e+02, %27
%29 = call i32 @floor(double %28)
%30 = sitofp i32 %29 to double
%31 = fsub double %23, %30
%32 = fadd double %31, 1.222000e+02
%33 = call i32 @floor(double %32)
store i32 %33, i32* %3
%34 = load double, double* %7
%35 = fdiv double %34, 3.652500e+02
%36 = call i32 @floor(double %35)
%37 = load i32, i32* %3
%38 = sdiv i32 %37, 429
%39 = sitofp i32 %38 to double
%40 = call i32 @floor(double %39)
%41 = add nsw i32 %36, %40
store i32 %41, i32* %5
%42 = load i32, i32* %3
%43 = sitofp i32 %42 to double
%44 = fdiv double %43, 3.061000e+01
%45 = call i32 @floor(double %44)
%46 = sub nsw i32 %45, 1
%47 = load i32, i32* %3
%48 = sdiv i32 %47, 429
%49 = sitofp i32 %48 to double
%50 = call i32 @floor(double %49)
%51 = mul nsw i32 %50, 12
%52 = sub nsw i32 %46, %51
store i32 %52, i32* %4
%53 = load i32, i32* %3
%54 = load i32, i32* %3
%55 = sitofp i32 %54 to double
%56 = fdiv double %55, 3.061000e+01
%57 = call i32 @floor(double %56)
%58 = sitofp i32 %57 to double
%59 = fmul double 3.061000e+01, %58
%60 = call i32 @floor(double %59)
%61 = sub nsw i32 %53, %60
store i32 %61, i32* %3
%62 = load i32, i32* %3
%63 = load i32, i32* %4
%64 = load i32, i32* %5
%65 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %62, i32 %63, i32 %64)
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"%2d %2d %4d\00"
define void @mjd_to_date(i64 %0) {
%2 = add nsw i64 %0, 2400001
%3 = sitofp i64 %2 to double
%4 = fadd double %3, 0xC13A431F1999999A
%5 = fadd double %3, 0xC139B472C0000000
%6 = fdiv double %5, 0x40E1D58800000000
%7 = tail call i32 @floor(double %6)
%8 = sitofp i32 %7 to double
%9 = fmul double %8, 7.500000e-01
%10 = tail call i32 @floor(double %9)
%11 = sitofp i32 %10 to double
%12 = fadd double %4, %11
%13 = fdiv double %12, 3.652500e+02
%14 = tail call i32 @floor(double %13)
%15 = sitofp i32 %14 to double
%16 = fmul double %15, 3.652500e+02
%17 = tail call i32 @floor(double %16)
%18 = sitofp i32 %17 to double
%19 = fsub double %12, %18
%20 = fadd double %19, 1.222000e+02
%21 = tail call i32 @floor(double %20)
%22 = tail call i32 @floor(double %13)
%23 = sdiv i32 %21, 429
%24 = sitofp i32 %23 to double
%25 = tail call i32 @floor(double %24)
%26 = add nsw i32 %25, %22
%27 = sitofp i32 %21 to double
%28 = fdiv double %27, 3.061000e+01
%29 = tail call i32 @floor(double %28)
%30 = add nsw i32 %29, -1
%31 = tail call i32 @floor(double %24)
%32 = mul i32 %31, -12
%33 = add i32 %30, %32
%34 = tail call i32 @floor(double %28)
%35 = sitofp i32 %34 to double
%36 = fmul double %35, 3.061000e+01
%37 = tail call i32 @floor(double %36)
%38 = sub nsw i32 %21, %37
%39 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %38, i32 %33, i32 %26)
ret void
}