double JulianDay0FromGregorian(int year) {
  if (year >= 1901 && year <= 2099)
    return (1721409.5 + (int)(365.25 * (year - 1)));
  else {
    year--;
    int a = (int)(year / 100);
    return ((int)(365.25 * year) - a + (int)(a / 4) + 1721424.5);
  }
}


x86 assembly (clang, -O0):
<JulianDay0FromGregorian>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0xc(%rbp)
cmpl   $0x76d,-0xc(%rbp)
jl     1155 <JulianDay0FromGregorian+0x55>
cmpl   $0x833,-0xc(%rbp)
jg     1155 <JulianDay0FromGregorian+0x55>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm1
movsd  0xed5(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
cvtsi2sd %eax,%xmm1
movsd  0xec9(%rip),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11ae <JulianDay0FromGregorian+0xae>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
cvtsi2sdl -0xc(%rbp),%xmm1
movsd  0xe8f(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
sub    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
add    %ecx,%eax
cvtsi2sd %eax,%xmm0
movsd  0xe5b(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<JulianDay0FromGregorian>:
lea    -0x76d(%rdi),%eax
add    $0xffffffff,%edi
cmp    $0xc6,%eax
ja     112a <JulianDay0FromGregorian+0x2a>
cvtsi2sd %edi,%xmm0
mulsd  0xee4(%rip),%xmm0
cvttsd2si %xmm0,%eax
movsd  0xee8(%rip),%xmm1
jmp    1171 <JulianDay0FromGregorian+0x71>
movslq %edi,%rax
imul   $0xffffffffae147ae1,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
cvtsi2sd %eax,%xmm0
mulsd  0xeb5(%rip),%xmm0
cvttsd2si %xmm0,%esi
add    %edx,%ecx
imul   $0x51eb851f,%rax,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x27,%rax
add    %edx,%eax
add    %ecx,%eax
add    %esi,%eax
movsd  0xe97(%rip),%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
addsd  %xmm1,%xmm0
ret

LLVM IR (-O0):
define double @JulianDay0FromGregorian(i32 %0) {
%2 = alloca double
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = icmp sge i32 %5, 1901
br i1 %6, label %7, label %18
7: ; preds = %1
%8 = load i32, i32* %3
%9 = icmp sle i32 %8, 2099
br i1 %9, label %10, label %18
10: ; preds = %7
%11 = load i32, i32* %3
%12 = sub nsw i32 %11, 1
%13 = sitofp i32 %12 to double
%14 = fmul double 3.652500e+02, %13
%15 = fptosi double %14 to i32
%16 = sitofp i32 %15 to double
%17 = fadd double 0x413A444180000000, %16
store double %17, double* %2
br label %34
18: ; preds = %7, %1
%19 = load i32, i32* %3
%20 = add nsw i32 %19, -1
store i32 %20, i32* %3
%21 = load i32, i32* %3
%22 = sdiv i32 %21, 100
store i32 %22, i32* %4
%23 = load i32, i32* %3
%24 = sitofp i32 %23 to double
%25 = fmul double 3.652500e+02, %24
%26 = fptosi double %25 to i32
%27 = load i32, i32* %4
%28 = sub nsw i32 %26, %27
%29 = load i32, i32* %4
%30 = sdiv i32 %29, 4
%31 = add nsw i32 %28, %30
%32 = sitofp i32 %31 to double
%33 = fadd double %32, 0x413A445080000000
store double %33, double* %2
br label %34
34: ; preds = %18, %10
%35 = load double, double* %2
ret double %35
}

LLVM IR (-O2):
define double @JulianDay0FromGregorian(i32 %0) {
%2 = add i32 %0, -1901
%3 = icmp ult i32 %2, 199
%4 = add nsw i32 %0, -1
br i1 %3, label %5, label %9
5: ; preds = %1
%6 = sitofp i32 %4 to double
%7 = fmul double %6, 3.652500e+02
%8 = fptosi double %7 to i32
br label %17
9: ; preds = %1
%10 = sdiv i32 %4, -100
%11 = sitofp i32 %4 to double
%12 = fmul double %11, 3.652500e+02
%13 = fptosi double %12 to i32
%14 = sdiv i32 %4, 400
%15 = add nsw i32 %14, %10
%16 = add i32 %15, %13
br label %17
17: ; preds = %9, %5
%18 = phi i32 [ %16, %9 ], [ %8, %5 ]
%19 = phi double [ 0x413A445080000000, %9 ], [ 0x413A444180000000, %5 ]
%20 = sitofp i32 %18 to double
%21 = fadd double %19, %20
ret double %21
}