int ymd2doy(int yr, int mo, int day) {
  int monstart1[] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
  int monstart2[] = {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335};
  int L2;
  L2 = yr / 4 - (yr + 7) / 4 - yr / 100 + (yr + 99) / 100 + yr / 400 -
       (yr + 399) / 400;
  if (L2 == -1) {
    return day + monstart2[mo - 1];
  } else {
    return day + monstart1[mo - 1];
  }
}


x86 assembly (clang, -O0):
<ymd2doy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xed1(%rip),%rsi
mov    $0x30,%edx
call   1030 <memcpy@plt>
lea    -0x70(%rbp),%rdi
lea    0xeec(%rip),%rsi
mov    $0x30,%edx
call   1030 <memcpy@plt>
mov    -0x8(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,-0x88(%rbp)
mov    -0x8(%rbp),%eax
add    $0x7,%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x88(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x84(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x84(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x80(%rbp)
mov    -0x8(%rbp),%eax
add    $0x63,%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x80(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x7c(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x190,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x7c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x78(%rbp)
mov    -0x8(%rbp),%eax
add    $0x18f,%eax
mov    $0x190,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x78(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x74(%rbp)
cmpl   $0xffffffff,-0x74(%rbp)
jne    11fe <ymd2doy+0xee>
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
add    -0x70(%rbp,%rcx,4),%eax
mov    %eax,-0x4(%rbp)
jmp    1211 <ymd2doy+0x101>
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
add    -0x40(%rbp,%rcx,4),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ymd2doy>:
lea    0x3(%rdi),%ecx
test   %edi,%edi
cmovns %edi,%ecx
sar    $0x2,%ecx
lea    0x7(%rdi),%eax
lea    0xa(%rdi),%r8d
test   %eax,%eax
cmovns %eax,%r8d
mov    %edx,%eax
sar    $0x2,%r8d
movslq %edi,%r9
imul   $0xffffffffae147ae1,%r9,%rdi
mov    %rdi,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rdi
add    %edx,%edi
add    %ecx,%edi
lea    0x63(%r9),%ecx
movslq %ecx,%rcx
imul   $0x51eb851f,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
imul   $0x51eb851f,%r9,%rdx
mov    %rdx,%r10
shr    $0x3f,%r10
sar    $0x27,%rdx
add    %r10d,%edx
add    %edi,%edx
sub    %r8d,%edx
add    %ecx,%edx
lea    0x18f(%r9),%ecx
movslq %ecx,%rcx
imul   $0xffffffffae147ae1,%rcx,%rcx
mov    %rcx,%rdi
shr    $0x3f,%rdi
sar    $0x27,%rcx
add    %edi,%ecx
add    %edx,%ecx
cmp    $0xffffffff,%ecx
movslq %esi,%rcx
lea    0xe95(%rip),%rdx
lea    0xe5e(%rip),%rsi
cmove  %rdx,%rsi
add    -0x4(%rsi,%rcx,4),%eax
ret

LLVM IR (-O0):
@__const.ymd2doy.monstart1 = [12 x i32] [i32 0, i32 31, i32 59, i32 90, i32 120, i32 151, i32 181, i32 212, i32 243, i32 273, i32 304, i32 334]
@__const.ymd2doy.monstart2 = [12 x i32] [i32 0, i32 31, i32 60, i32 91, i32 121, i32 152, i32 182, i32 213, i32 244, i32 274, i32 305, i32 335]
define i32 @ymd2doy(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [12 x i32]
%9 = alloca [12 x i32]
%10 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%11 = bitcast [12 x i32]* %8 to i8*
%12 = bitcast [12 x i32]* %9 to i8*
%13 = load i32, i32* %5
%14 = sdiv i32 %13, 4
%15 = load i32, i32* %5
%16 = add nsw i32 %15, 7
%17 = sdiv i32 %16, 4
%18 = sub nsw i32 %14, %17
%19 = load i32, i32* %5
%20 = sdiv i32 %19, 100
%21 = sub nsw i32 %18, %20
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 99
%24 = sdiv i32 %23, 100
%25 = add nsw i32 %21, %24
%26 = load i32, i32* %5
%27 = sdiv i32 %26, 400
%28 = add nsw i32 %25, %27
%29 = load i32, i32* %5
%30 = add nsw i32 %29, 399
%31 = sdiv i32 %30, 400
%32 = sub nsw i32 %28, %31
store i32 %32, i32* %10
%33 = load i32, i32* %10
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %43
35: ; preds = %3
%36 = load i32, i32* %7
%37 = load i32, i32* %6
%38 = sub nsw i32 %37, 1
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [12 x i32], [12 x i32]* %9, i64 0, i64 %39
%41 = load i32, i32* %40
%42 = add nsw i32 %36, %41
store i32 %42, i32* %4
br label %51
43: ; preds = %3
%44 = load i32, i32* %7
%45 = load i32, i32* %6
%46 = sub nsw i32 %45, 1
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [12 x i32], [12 x i32]* %8, i64 0, i64 %47
%49 = load i32, i32* %48
%50 = add nsw i32 %44, %49
store i32 %50, i32* %4
br label %51
51: ; preds = %43, %35
%52 = load i32, i32* %4
ret i32 %52
}

LLVM IR (-O2):
@__const.ymd2doy.monstart1 = [12 x i32] [i32 0, i32 31, i32 59, i32 90, i32 120, i32 151, i32 181, i32 212, i32 243, i32 273, i32 304, i32 334]
@__const.ymd2doy.monstart2 = [12 x i32] [i32 0, i32 31, i32 60, i32 91, i32 121, i32 152, i32 182, i32 213, i32 244, i32 274, i32 305, i32 335]
define i32 @ymd2doy(i32 %0, i32 %1, i32 %2) {
%4 = sdiv i32 %0, 4
%5 = add nsw i32 %0, 7
%6 = sdiv i32 %5, -4
%7 = sdiv i32 %0, -100
%8 = add nsw i32 %0, 99
%9 = sdiv i32 %8, 100
%10 = sdiv i32 %0, 400
%11 = add nsw i32 %0, 399
%12 = sdiv i32 %11, -400
%13 = add nsw i32 %7, %4
%14 = add nsw i32 %13, %10
%15 = add nsw i32 %14, %6
%16 = add nsw i32 %15, %9
%17 = add nsw i32 %16, %12
%18 = icmp eq i32 %17, -1
%19 = add nsw i32 %1, -1
%20 = sext i32 %19 to i64
%21 = select i1 %18, [12 x i32]* @__const.ymd2doy.monstart2, [12 x i32]* @__const.ymd2doy.monstart1
%22 = getelementptr inbounds [12 x i32], [12 x i32]* %21, i64 0, i64 %20
%23 = load i32, i32* %22
%24 = add nsw i32 %23, %2
ret i32 %24
}