#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 */
int ymd2doy(int, int, int);
int ymd2mjd(int yr, int mo, int day) {
  int doy;
  int yr1 = yr - 1;
  doy = ymd2doy(yr, mo, day);
  return doy - 678576 + 365 * yr1 + yr1 / 4 - yr1 / 100 + yr1 / 400;
}


x86 assembly (clang, -O0):
<ymd2mjd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1030 <ymd2doy@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
sub    $0xa5ab0,%eax
imul   $0x16d,-0x14(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x190,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
add    %ecx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ymd2mjd>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
lea    -0x1(%rbx),%ebp
call   1030 <ymd2doy@plt>
imul   $0x16d,%ebp,%ecx
add    $0x2,%ebx
test   %ebp,%ebp
cmovns %ebp,%ebx
sar    $0x2,%ebx
add    %ecx,%ebx
movslq %ebp,%rcx
imul   $0xffffffffae147ae1,%rcx,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
sar    $0x25,%rdx
add    %esi,%edx
add    %ebx,%edx
imul   $0x51eb851f,%rcx,%rcx
mov    %rcx,%rsi
shr    $0x3f,%rsi
sar    $0x27,%rcx
add    %esi,%ecx
add    %edx,%ecx
add    %ecx,%eax
add    $0xfff5a550,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @ymd2mjd(i32 %0, i32 %1, i32 %2) {
%4 = add nsw i32 %0, -1
%5 = tail call i32 @ymd2doy(i32 %0, i32 %1, i32 %2)
%6 = mul nsw i32 %4, 365
%7 = sdiv i32 %4, 4
%8 = sdiv i32 %4, -100
%9 = sdiv i32 %4, 400
%10 = add i32 %6, -678576
%11 = add i32 %10, %7
%12 = add i32 %11, %8
%13 = add i32 %12, %9
%14 = add i32 %13, %5
ret i32 %14
}