#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 */
typedef int /*<<< orphan*/ uint8_t;
typedef scalar_t__ uint32_t;
typedef int uint16_t;

/* Variables and functions */
scalar_t__ datetime_is_leap_year(int);
scalar_t__ datetime_ymd_is_valid(int, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ day_of_year(int, int /*<<< orphan*/, int /*<<< orphan*/);
uint32_t days_since_epoch(uint16_t year, uint8_t month, uint8_t day) {
  uint32_t days = 0;
  uint16_t years = 0;
  if (datetime_ymd_is_valid(year, month, day)) {
    for (years = 1900; years < year; years++) {
      days += 365;
      if (datetime_is_leap_year(years))
        days++;
    }
    days += day_of_year(year, month, day);
    days -= 1;
  }
  return (days);
}


x86 assembly (clang, -O0):
<days_since_epoch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1050 <datetime_ymd_is_valid@plt>
cmp    $0x0,%rax
je     11dc <days_since_epoch+0xac>
movl   $0x76c,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11ba <days_since_epoch+0x8a>
mov    -0x18(%rbp),%rax
add    $0x16d,%rax
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <datetime_is_leap_year@plt>
cmp    $0x0,%rax
je     11a7 <days_since_epoch+0x77>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11ac <days_since_epoch+0x7c>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    116f <days_since_epoch+0x3f>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1040 <day_of_year@plt>
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<days_since_epoch>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %esi,%r15d
mov    %edi,%r12d
call   1050 <datetime_ymd_is_valid@plt>
test   %rax,%rax
je     11a5 <days_since_epoch+0x75>
mov    $0xffffffffffffffff,%rbx
cmp    $0x76d,%r12d
jl     1192 <days_since_epoch+0x62>
mov    $0x76c,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebp,%edi
call   1030 <datetime_is_leap_year@plt>
cmp    $0x1,%rax
sbb    $0x0,%rbx
add    $0x16e,%rbx
add    $0x1,%ebp
cmp    %ebp,%r12d
jne    1170 <days_since_epoch+0x40>
add    $0xffffffffffffffff,%rbx
mov    %r12d,%edi
mov    %r15d,%esi
mov    %r14d,%edx
call   1040 <day_of_year@plt>
add    %rbx,%rax
jmp    11a7 <days_since_epoch+0x77>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i64 @days_since_epoch(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i64 0, i64* %7
store i32 0, i32* %8
%9 = load i32, i32* %4
%10 = load i32, i32* %5
%11 = load i32, i32* %6
%12 = call i64 @datetime_ymd_is_valid(i32 %9, i32 %10, i32 %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %41
14: ; preds = %3
store i32 1900, i32* %8
br label %15
15: ; preds = %29, %14
%16 = load i32, i32* %8
%17 = load i32, i32* %4
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %32
19: ; preds = %15
%20 = load i64, i64* %7
%21 = add nsw i64 %20, 365
store i64 %21, i64* %7
%22 = load i32, i32* %8
%23 = call i64 @datetime_is_leap_year(i32 %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %19
%26 = load i64, i64* %7
%27 = add nsw i64 %26, 1
store i64 %27, i64* %7
br label %28
28: ; preds = %25, %19
br label %29
29: ; preds = %28
%30 = load i32, i32* %8
%31 = add nsw i32 %30, 1
store i32 %31, i32* %8
br label %15
32: ; preds = %15
%33 = load i32, i32* %4
%34 = load i32, i32* %5
%35 = load i32, i32* %6
%36 = call i64 @day_of_year(i32 %33, i32 %34, i32 %35)
%37 = load i64, i64* %7
%38 = add nsw i64 %37, %36
store i64 %38, i64* %7
%39 = load i64, i64* %7
%40 = sub nsw i64 %39, 1
store i64 %40, i64* %7
br label %41
41: ; preds = %32, %3
%42 = load i64, i64* %7
ret i64 %42
}

LLVM IR (-O2):
define i64 @days_since_epoch(i32 %0, i32 %1, i32 %2) {
%4 = tail call i64 @datetime_ymd_is_valid(i32 %0, i32 %1, i32 %2)
%5 = icmp eq i64 %4, 0
br i1 %5, label %23, label %6
6: ; preds = %3
%7 = icmp sgt i32 %0, 1900
br i1 %7, label %8, label %19
8: ; preds = %6, %8
%9 = phi i32 [ %15, %8 ], [ 1900, %6 ]
%10 = phi i64 [ %14, %8 ], [ 0, %6 ]
%11 = tail call i64 @datetime_is_leap_year(i32 %9)
%12 = icmp eq i64 %11, 0
%13 = select i1 %12, i64 365, i64 366
%14 = add nuw nsw i64 %13, %10
%15 = add nuw nsw i32 %9, 1
%16 = icmp eq i32 %15, %0
br i1 %16, label %17, label %8
17: ; preds = %8
%18 = add nsw i64 %14, -1
br label %19
19: ; preds = %17, %6
%20 = phi i64 [ -1, %6 ], [ %18, %17 ]
%21 = tail call i64 @day_of_year(i32 %0, i32 %1, i32 %2)
%22 = add i64 %20, %21
br label %23
23: ; preds = %19, %3
%24 = phi i64 [ %22, %19 ], [ 0, %3 ]
ret i64 %24
}