#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_mday;
  int tm_mon;
  int tm_year;
  int tm_yday;
  scalar_t__ tm_isdst;
  scalar_t__ tm_hour;
  scalar_t__ tm_min;
  scalar_t__ tm_sec;
};

/* Variables and functions */
int floor(double);
int /*<<< orphan*/ mktime(struct tm *);
int /*<<< orphan*/ printf(char *, int, int);
void mjd_to_yday(long mjd) {
  int day, month, year;
  long julian;
  double y2;
  struct tm tmptm;
  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));
  tmptm.tm_sec = tmptm.tm_min = tmptm.tm_hour = 0;
  tmptm.tm_mday = day;
  tmptm.tm_mon = month - 1;
  tmptm.tm_year = year - 1900;
  tmptm.tm_isdst = 0;
  mktime(&tmptm);
  printf("%d %d", tmptm.tm_yday + 1, year);
}


x86 assembly (clang, -O0):
<mjd_to_yday>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x249f01,%rax
mov    %rax,-0x20(%rbp)
cvtsi2sdq -0x20(%rbp),%xmm0
movsd  0xed5(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x78(%rbp)
cvtsi2sdq -0x20(%rbp),%xmm0
movsd  0xeb6(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  0xea2(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1050 <floor@plt>
cvtsi2sd %eax,%xmm1
movsd  0xe85(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1050 <floor@plt>
movsd  -0x78(%rbp),%xmm0
cvtsi2sd %eax,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  0xe43(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1050 <floor@plt>
cvtsi2sd %eax,%xmm1
movsd  0xe2e(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1050 <floor@plt>
movsd  -0x70(%rbp),%xmm0
cvtsi2sd %eax,%xmm1
subsd  %xmm1,%xmm0
movsd  0xe18(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1050 <floor@plt>
mov    %eax,-0xc(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  0xdf7(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1050 <floor@plt>
mov    %eax,-0x64(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x1ad,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
call   1050 <floor@plt>
mov    %eax,%ecx
mov    -0x64(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
cvtsi2sdl -0xc(%rbp),%xmm0
movsd  0xdb8(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1050 <floor@plt>
sub    $0x1,%eax
mov    %eax,-0x60(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x1ad,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
call   1050 <floor@plt>
mov    %eax,%ecx
mov    -0x60(%rbp),%eax
imul   $0xc,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x5c(%rbp)
cvtsi2sdl -0xc(%rbp),%xmm0
movsd  0xd75(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1050 <floor@plt>
cvtsi2sd %eax,%xmm1
movsd  0xd60(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1050 <floor@plt>
mov    %eax,%ecx
mov    -0x5c(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0xc(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x54(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x76c,%eax
mov    %eax,-0x50(%rbp)
movq   $0x0,-0x48(%rbp)
lea    -0x58(%rbp),%rdi
call   1040 <mktime@plt>
mov    -0x4c(%rbp),%esi
add    $0x1,%esi
mov    -0x14(%rbp),%edx
lea    0xd32(%rip),%rdi
call   1030 <printf@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mjd_to_yday>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
add    $0x249f01,%rdi
cvtsi2sd %rdi,%xmm0
movsd  0xeae(%rip),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
addsd  0xea4(%rip),%xmm0
divsd  0xea4(%rip),%xmm0
call   1050 <floor@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xe98(%rip),%xmm0
call   1050 <floor@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
divsd  0xe80(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
call   1050 <floor@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xe66(%rip),%xmm0
call   1050 <floor@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0x10(%rsp),%xmm1
subsd  %xmm0,%xmm1
addsd  0xe50(%rip),%xmm1
movapd %xmm1,%xmm0
call   1050 <floor@plt>
mov    %eax,%ebx
movsd  0x8(%rsp),%xmm0
call   1050 <floor@plt>
mov    %eax,%r15d
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,0x8(%rsp)
call   1050 <floor@plt>
mov    %eax,%r13d
lea    (%r15,%r13,1),%r14d
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
divsd  0xe00(%rip),%xmm0
movsd  %xmm0,0x10(%rsp)
call   1050 <floor@plt>
mov    %eax,%r12d
movsd  0x8(%rsp),%xmm0
call   1050 <floor@plt>
shl    $0x2,%eax
lea    (%rax,%rax,2),%ebp
movsd  0x10(%rsp),%xmm0
call   1050 <floor@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xdc7(%rip),%xmm0
call   1050 <floor@plt>
sub    %eax,%ebx
xorpd  %xmm0,%xmm0
movupd %xmm0,0x30(%rsp)
movq   $0x0,0x40(%rsp)
mov    %ebx,0x18(%rsp)
neg    %ebp
lea    (%r12,%rbp,1),%eax
add    $0xfffffffe,%eax
mov    %eax,0x1c(%rsp)
lea    -0x76c(%r13,%r15,1),%eax
ff
mov    %eax,0x20(%rsp)
movq   $0x0,0x28(%rsp)
lea    0x18(%rsp),%rdi
call   1040 <mktime@plt>
mov    0x24(%rsp),%esi
add    $0x1,%esi
lea    0xd77(%rip),%rdi
mov    %r14d,%edx
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>

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

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