#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 */
unsigned long gregdate_to_julday(int const, int const, int const);
unsigned long day_of_year(int date) {
  const int year = date / 10000;
  const int month = (date - year * 10000) / 100;
  const int day = date - year * 10000 - month * 100;
  return gregdate_to_julday(year, month, day) - gregdate_to_julday(year, 1, 1) +
         1;
}


x86 assembly (clang, -O0):
<day_of_year>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x2710,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
imul   $0x2710,-0x8(%rbp),%ecx
sub    %ecx,%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
imul   $0x2710,-0x8(%rbp),%ecx
sub    %ecx,%eax
imul   $0x64,-0xc(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <gregdate_to_julday@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <gregdate_to_julday@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
add    $0x1,%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<day_of_year>:
push   %r14
push   %rbx
push   %rax
movslq %edi,%rax
imul   $0x68db8bad,%rax,%r14
mov    %r14,%rcx
shr    $0x3f,%rcx
sar    $0x2c,%r14
add    %ecx,%r14d
imul   $0xffffd8f0,%r14d,%ecx
add    %ecx,%eax
movslq %eax,%rdx
imul   $0x51eb851f,%rdx,%rsi
mov    %rsi,%rax
shr    $0x3f,%rax
sar    $0x25,%rsi
add    %eax,%esi
imul   $0xffffff9c,%esi,%eax
add    %eax,%edx
mov    %r14d,%edi
call   1030 <gregdate_to_julday@plt>
mov    %rax,%rbx
mov    %r14d,%edi
mov    $0x1,%esi
mov    $0x1,%edx
call   1030 <gregdate_to_julday@plt>
sub    %rax,%rbx
add    $0x1,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i64 @day_of_year(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = sdiv i32 %6, 10000
store i32 %7, i32* %3
%8 = load i32, i32* %2
%9 = load i32, i32* %3
%10 = mul nsw i32 %9, 10000
%11 = sub nsw i32 %8, %10
%12 = sdiv i32 %11, 100
store i32 %12, i32* %4
%13 = load i32, i32* %2
%14 = load i32, i32* %3
%15 = mul nsw i32 %14, 10000
%16 = sub nsw i32 %13, %15
%17 = load i32, i32* %4
%18 = mul nsw i32 %17, 100
%19 = sub nsw i32 %16, %18
store i32 %19, i32* %5
%20 = load i32, i32* %3
%21 = load i32, i32* %4
%22 = load i32, i32* %5
%23 = call i64 @gregdate_to_julday(i32 %20, i32 %21, i32 %22)
%24 = load i32, i32* %3
%25 = call i64 @gregdate_to_julday(i32 %24, i32 1, i32 1)
%26 = sub i64 %23, %25
%27 = add i64 %26, 1
ret i64 %27
}

LLVM IR (-O2):
define i64 @day_of_year(i32 %0) {
%2 = sdiv i32 %0, 10000
%3 = mul nsw i32 %2, -10000
%4 = add i32 %3, %0
%5 = sdiv i32 %4, 100
%6 = mul nsw i32 %5, -100
%7 = add i32 %6, %4
%8 = tail call i64 @gregdate_to_julday(i32 %2, i32 %5, i32 %7)
%9 = tail call i64 @gregdate_to_julday(i32 %2, i32 1, i32 1)
%10 = add i64 %8, 1
%11 = sub i64 %10, %9
ret i64 %11
}