int hdate_get_day_of_year(int day, int month, int year) {
  int jd;
  jd = (1461 * (year + 4800 + (month - 14) / 12)) / 4 +
       (367 * (month - 2 - 12 * ((month - 14) / 12))) / 12 -
       (3 * ((year + 4900 + (month - 14) / 12) / 100)) / 4 + day;
  jd = jd - ((1461 * (year + 4799)) / 4 + 367 * 11 / 12 -
             (3 * ((year + 4899) / 100)) / 4);
  return jd;
}


x86 assembly (clang, -O0):
<hdate_get_day_of_year>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x12c0,%eax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%eax
sub    $0xe,%eax
mov    $0xc,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
add    %ecx,%eax
imul   $0x5b5,%eax,%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%eax
sub    $0xe,%eax
mov    $0xc,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
imul   $0xc,%ecx,%ecx
sub    %ecx,%eax
imul   $0x16f,%eax,%eax
mov    $0xc,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1324,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%eax
sub    $0xe,%eax
mov    $0xc,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
add    %ecx,%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
imul   $0x3,%eax,%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
sub    %ecx,%eax
add    -0x4(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
add    $0x12bf,%eax
imul   $0x5b5,%eax,%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
add    $0x150,%ecx
mov    -0xc(%rbp),%eax
add    $0x1323,%eax
mov    $0x64,%esi
cltd
idiv   %esi
imul   $0x3,%eax,%eax
mov    $0x4,%esi
cltd
idiv   %esi
mov    %eax,%edx
mov    -0x14(%rbp),%eax
sub    %edx,%ecx
sub    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<hdate_get_day_of_year>:
lea    -0xe(%rsi),%eax
cltq
imul   $0x2aaaaaab,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x21,%rax
add    %ecx,%eax
lea    (%rax,%rdx,1),%ecx
imul   $0x5b5,%ecx,%r9d
lea    0x6b01c0(%r9),%ecx
add    $0x6b01c3,%r9d
test   %ecx,%ecx
cmovns %ecx,%r9d
sar    $0x2,%r9d
lea    0x0(,%rax,4),%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%esi
imul   $0x16f,%esi,%ecx
add    $0xfffffd22,%ecx
movslq %ecx,%rcx
imul   $0x2aaaaaab,%rcx,%r8
mov    %r8,%rcx
shr    $0x3f,%rcx
sar    $0x21,%r8
add    %ecx,%r8d
add    %edx,%eax
add    $0x1324,%eax
cltq
imul   $0x51eb851f,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
add    %ecx,%eax
lea    (%rax,%rax,2),%ecx
lea    (%rax,%rax,2),%esi
add    $0x3,%esi
test   %ecx,%ecx
cmovns %ecx,%esi
sar    $0x2,%esi
imul   $0x5b5,%edx,%ecx
lea    0x6afc0b(%rcx),%eax
add    $0x6afc0e,%ecx
test   %eax,%eax
cmovns %eax,%ecx
sar    $0x2,%ecx
add    $0x1323,%edx
movslq %edx,%rax
imul   $0x51eb851f,%rax,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rax
add    %edx,%eax
lea    (%rax,%rax,2),%edx
lea    (%rax,%rax,2),%eax
add    $0x3,%eax
test   %edx,%edx
cmovns %edx,%eax
sar    $0x2,%eax
sub    %ecx,%edi
add    %edi,%eax
add    %r9d,%eax
add    %r8d,%eax
sub    %esi,%eax
add    $0xfffffeb0,%eax
ret

LLVM IR (-O0):
define i32 @hdate_get_day_of_year(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32, i32* %6
%9 = add nsw i32 %8, 4800
%10 = load i32, i32* %5
%11 = sub nsw i32 %10, 14
%12 = sdiv i32 %11, 12
%13 = add nsw i32 %9, %12
%14 = mul nsw i32 1461, %13
%15 = sdiv i32 %14, 4
%16 = load i32, i32* %5
%17 = sub nsw i32 %16, 2
%18 = load i32, i32* %5
%19 = sub nsw i32 %18, 14
%20 = sdiv i32 %19, 12
%21 = mul nsw i32 12, %20
%22 = sub nsw i32 %17, %21
%23 = mul nsw i32 367, %22
%24 = sdiv i32 %23, 12
%25 = add nsw i32 %15, %24
%26 = load i32, i32* %6
%27 = add nsw i32 %26, 4900
%28 = load i32, i32* %5
%29 = sub nsw i32 %28, 14
%30 = sdiv i32 %29, 12
%31 = add nsw i32 %27, %30
%32 = sdiv i32 %31, 100
%33 = mul nsw i32 3, %32
%34 = sdiv i32 %33, 4
%35 = sub nsw i32 %25, %34
%36 = load i32, i32* %4
%37 = add nsw i32 %35, %36
store i32 %37, i32* %7
%38 = load i32, i32* %7
%39 = load i32, i32* %6
%40 = add nsw i32 %39, 4799
%41 = mul nsw i32 1461, %40
%42 = sdiv i32 %41, 4
%43 = add nsw i32 %42, 336
%44 = load i32, i32* %6
%45 = add nsw i32 %44, 4899
%46 = sdiv i32 %45, 100
%47 = mul nsw i32 3, %46
%48 = sdiv i32 %47, 4
%49 = sub nsw i32 %43, %48
%50 = sub nsw i32 %38, %49
store i32 %50, i32* %7
%51 = load i32, i32* %7
ret i32 %51
}

LLVM IR (-O2):
define i32 @hdate_get_day_of_year(i32 %0, i32 %1, i32 %2) {
%4 = add nsw i32 %1, -14
%5 = sdiv i32 %4, 12
%6 = add i32 %5, %2
%7 = mul i32 %6, 1461
%8 = add i32 %7, 7012800
%9 = sdiv i32 %8, 4
%10 = add nsw i32 %1, -2
%11 = mul nsw i32 %5, -12
%12 = add i32 %10, %11
%13 = mul nsw i32 %12, 367
%14 = sdiv i32 %13, 12
%15 = add i32 %6, 4900
%16 = sdiv i32 %15, 100
%17 = mul nsw i32 %16, 3
%18 = sdiv i32 %17, -4
%19 = mul i32 %2, 1461
%20 = add i32 %19, 7011339
%21 = sdiv i32 %20, -4
%22 = add nsw i32 %2, 4899
%23 = sdiv i32 %22, 100
%24 = mul nsw i32 %23, 3
%25 = sdiv i32 %24, 4
%26 = add i32 %0, -336
%27 = add i32 %26, %21
%28 = add i32 %27, %25
%29 = add i32 %28, %9
%30 = add i32 %29, %14
%31 = add i32 %30, %18
ret i32 %31
}