#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 */
double floor(int);
void decode_julday(int calendar, int julday, int *year, int *mon, int *day) {
  int a = julday;
  double b, c;
  double d, e, f;
  b = floor((a - 1867216.25) / 36524.25);
  c = a + b - floor(b / 4) + 1525;
  if (calendar == 0)
    if (a < 2299161) {
      c = a + 1524;
    }
  d = floor((c - 122.1) / 365.25);
  e = floor(365.25 * d);
  f = floor((c - e) / 30.6001);
  *day = (int)(c - e - floor(30.6001 * f));
  *mon = (int)(f - 1 - 12 * floor(f / 14));
  *year = (int)(d - 4715 - floor((7 + *mon) / 10));
}


x86 assembly (clang, -O0):
<decode_julday>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x24(%rbp)
cvtsi2sdl -0x24(%rbp),%xmm0
movsd  0xedb(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  0xec7(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <floor@plt>
movsd  %xmm0,-0x30(%rbp)
cvtsi2sdl -0x24(%rbp),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xe91(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <floor@plt>
movaps %xmm0,%xmm1
movsd  -0x58(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  0xe68(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    11ce <decode_julday+0xbe>
cmpl   $0x231519,-0x24(%rbp)
jge    11c9 <decode_julday+0xb9>
mov    -0x24(%rbp),%eax
add    $0x5f4,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    11ce <decode_julday+0xbe>
movsd  -0x38(%rbp),%xmm0
movsd  0xe75(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  0xe61(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <floor@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  0xe47(%rip),%xmm0
mulsd  -0x40(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <floor@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x38(%rbp),%xmm0
subsd  -0x48(%rbp),%xmm0
movsd  0xe1a(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <floor@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x38(%rbp),%xmm0
subsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  0xdf1(%rip),%xmm0
mulsd  -0x50(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <floor@plt>
movaps %xmm0,%xmm1
movsd  -0x70(%rbp),%xmm0
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movsd  -0x50(%rbp),%xmm0
movsd  0xdb8(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  0xd9a(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <floor@plt>
movsd  -0x68(%rbp),%xmm1
movsd  0xd78(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movsd  -0x40(%rbp),%xmm0
movsd  0xd51(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
add    $0x7,%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1030 <floor@plt>
movaps %xmm0,%xmm1
movsd  -0x60(%rbp),%xmm0
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode_julday>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %r8,%r12
mov    %rcx,%r15
mov    %rdx,%r14
mov    %esi,%ebx
mov    %edi,%ebp
cvtsi2sd %esi,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0xec5(%rip),%xmm0
addsd  %xmm1,%xmm0
divsd  0xec1(%rip),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <floor@plt>
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
mulsd  0xea8(%rip),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <floor@plt>
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
addsd  0xe91(%rip),%xmm0
cmp    $0x231519,%ebx
jl     1199 <decode_julday+0x89>
movapd %xmm0,%xmm1
test   %ebp,%ebp
jne    11aa <decode_julday+0x9a>
jmp    11ae <decode_julday+0x9e>
add    $0x5f4,%ebx
xorps  %xmm1,%xmm1
cvtsi2sd %ebx,%xmm1
test   %ebp,%ebp
je     11ae <decode_julday+0x9e>
movapd %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
movsd  0xe64(%rip),%xmm0
addsd  %xmm1,%xmm0
divsd  0xe60(%rip),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <floor@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0xe49(%rip),%xmm1
mulsd  %xmm0,%xmm1
cvttsd2si %xmm1,%edi
call   1030 <floor@plt>
movsd  0x10(%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
movapd %xmm1,%xmm0
divsd  0xe28(%rip),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <floor@plt>
movsd  %xmm0,0x18(%rsp)
movsd  0xe11(%rip),%xmm1
mulsd  %xmm0,%xmm1
cvttsd2si %xmm1,%edi
call   1030 <floor@plt>
movsd  0x10(%rsp),%xmm1
subsd  %xmm0,%xmm1
cvttsd2si %xmm1,%eax
mov    %eax,(%r12)
movsd  0xdf2(%rip),%xmm1
movsd  0x18(%rsp),%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
divsd  0xde2(%rip),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <floor@plt>
mulsd  0xdd9(%rip),%xmm0
addsd  0x10(%rsp),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,(%r15)
movsd  0x8(%rsp),%xmm0
addsd  0xdc6(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
add    $0x7,%eax
cltq
imul   $0x66666667,%rax,%rdi
mov    %rdi,%rax
shr    $0x3f,%rax
sar    $0x22,%rdi
add    %eax,%edi
call   1030 <floor@plt>
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
cvttsd2si %xmm1,%eax
mov    %eax,(%r14)
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @decode_julday(i32 %0, i32 %1, i32* %2, i32* %3, i32* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca double
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32* %2, i32** %8
store i32* %3, i32** %9
store i32* %4, i32** %10
%17 = load i32, i32* %7
store i32 %17, i32* %11
%18 = load i32, i32* %11
%19 = sitofp i32 %18 to double
%20 = fsub double %19, 0x413C7DD040000000
%21 = fdiv double %20, 0x40E1D58800000000
%22 = fptosi double %21 to i32
%23 = call double @floor(i32 %22)
store double %23, double* %12
%24 = load i32, i32* %11
%25 = sitofp i32 %24 to double
%26 = load double, double* %12
%27 = fadd double %25, %26
%28 = load double, double* %12
%29 = fdiv double %28, 4.000000e+00
%30 = fptosi double %29 to i32
%31 = call double @floor(i32 %30)
%32 = fsub double %27, %31
%33 = fadd double %32, 1.525000e+03
store double %33, double* %13
%34 = load i32, i32* %6
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %44
36: ; preds = %5
%37 = load i32, i32* %11
%38 = icmp slt i32 %37, 2299161
br i1 %38, label %39, label %43
39: ; preds = %36
%40 = load i32, i32* %11
%41 = add nsw i32 %40, 1524
%42 = sitofp i32 %41 to double
store double %42, double* %13
br label %43
43: ; preds = %39, %36
br label %44
44: ; preds = %43, %5
%45 = load double, double* %13
%46 = fsub double %45, 1.221000e+02
%47 = fdiv double %46, 3.652500e+02
%48 = fptosi double %47 to i32
%49 = call double @floor(i32 %48)
store double %49, double* %14
%50 = load double, double* %14
%51 = fmul double 3.652500e+02, %50
%52 = fptosi double %51 to i32
%53 = call double @floor(i32 %52)
store double %53, double* %15
%54 = load double, double* %13
%55 = load double, double* %15
%56 = fsub double %54, %55
%57 = fdiv double %56, 3.060010e+01
%58 = fptosi double %57 to i32
%59 = call double @floor(i32 %58)
store double %59, double* %16
%60 = load double, double* %13
%61 = load double, double* %15
%62 = fsub double %60, %61
%63 = load double, double* %16
%64 = fmul double 3.060010e+01, %63
%65 = fptosi double %64 to i32
%66 = call double @floor(i32 %65)
%67 = fsub double %62, %66
%68 = fptosi double %67 to i32
%69 = load i32*, i32** %10
store i32 %68, i32* %69
%70 = load double, double* %16
%71 = fsub double %70, 1.000000e+00
%72 = load double, double* %16
%73 = fdiv double %72, 1.400000e+01
%74 = fptosi double %73 to i32
%75 = call double @floor(i32 %74)
%76 = call double @llvm.fmuladd.f64(double -1.200000e+01, double %75, double %71)
%77 = fptosi double %76 to i32
%78 = load i32*, i32** %9
store i32 %77, i32* %78
%79 = load double, double* %14
%80 = fsub double %79, 4.715000e+03
%81 = load i32*, i32** %9
%82 = load i32, i32* %81
%83 = add nsw i32 7, %82
%84 = sdiv i32 %83, 10
%85 = call double @floor(i32 %84)
%86 = fsub double %80, %85
%87 = fptosi double %86 to i32
%88 = load i32*, i32** %8
store i32 %87, i32* %88
ret void
}

LLVM IR (-O2):
define void @decode_julday(i32 %0, i32 %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3, i32* nocapture writeonly %4) {
%6 = sitofp i32 %1 to double
%7 = fadd double %6, 0xC13C7DD040000000
%8 = fdiv double %7, 0x40E1D58800000000
%9 = fptosi double %8 to i32
%10 = tail call double @floor(i32 %9)
%11 = fadd double %10, %6
%12 = fmul double %10, 2.500000e-01
%13 = fptosi double %12 to i32
%14 = tail call double @floor(i32 %13)
%15 = fsub double %11, %14
%16 = fadd double %15, 1.525000e+03
%17 = icmp eq i32 %0, 0
%18 = icmp slt i32 %1, 2299161
%19 = and i1 %17, %18
%20 = add nsw i32 %1, 1524
%21 = sitofp i32 %20 to double
%22 = select i1 %19, double %21, double %16
%23 = fadd double %22, -1.221000e+02
%24 = fdiv double %23, 3.652500e+02
%25 = fptosi double %24 to i32
%26 = tail call double @floor(i32 %25)
%27 = fmul double %26, 3.652500e+02
%28 = fptosi double %27 to i32
%29 = tail call double @floor(i32 %28)
%30 = fsub double %22, %29
%31 = fdiv double %30, 3.060010e+01
%32 = fptosi double %31 to i32
%33 = tail call double @floor(i32 %32)
%34 = fmul double %33, 3.060010e+01
%35 = fptosi double %34 to i32
%36 = tail call double @floor(i32 %35)
%37 = fsub double %30, %36
%38 = fptosi double %37 to i32
store i32 %38, i32* %4
%39 = fadd double %33, -1.000000e+00
%40 = fdiv double %33, 1.400000e+01
%41 = fptosi double %40 to i32
%42 = tail call double @floor(i32 %41)
%43 = tail call double @llvm.fmuladd.f64(double %42, double -1.200000e+01, double %39)
%44 = fptosi double %43 to i32
store i32 %44, i32* %3
%45 = fadd double %26, -4.715000e+03
%46 = add nsw i32 %44, 7
%47 = sdiv i32 %46, 10
%48 = tail call double @floor(i32 %47)
%49 = fsub double %45, %48
%50 = fptosi double %49 to i32
store i32 %50, i32* %2
ret void
}