#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 calendar_dpy(int);
int /*<<< orphan*/ cdiDecodeDate(int, int *, int *, int *);
int encode_day(int, int, int, int);
int encode_julday(int, int, int, int);
int date_to_calday(int calendar, int date) {
  int calday;
  int dpy;
  int year, month, day;
  dpy = calendar_dpy(calendar);
  cdiDecodeDate(date, &year, &month, &day);
  if (dpy == 360 || dpy == 365 || dpy == 366)
    calday = encode_day(dpy, year, month, day);
  else
    calday = encode_julday(calendar, year, month, day);
  return (calday);
}


x86 assembly (clang, -O0):
<date_to_calday>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
call   1060 <calendar_dpy@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x14(%rbp),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x1c(%rbp),%rcx
call   1040 <cdiDecodeDate@plt>
cmpl   $0x168,-0x10(%rbp)
je     1194 <date_to_calday+0x54>
cmpl   $0x16d,-0x10(%rbp)
je     1194 <date_to_calday+0x54>
cmpl   $0x16e,-0x10(%rbp)
jne    11ad <date_to_calday+0x6d>
mov    -0x10(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
call   1050 <encode_day@plt>
mov    %eax,-0xc(%rbp)
jmp    11c1 <date_to_calday+0x81>
mov    -0x4(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
call   1030 <encode_julday@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<date_to_calday>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
mov    %edi,%r14d
call   1060 <calendar_dpy@plt>
mov    %eax,%ebx
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
lea    0x4(%rsp),%rcx
mov    %ebp,%edi
call   1040 <cdiDecodeDate@plt>
lea    -0x168(%rbx),%eax
cmp    $0x6,%eax
ja     1194 <date_to_calday+0x54>
mov    $0x61,%ecx
bt     %eax,%ecx
jae    1194 <date_to_calday+0x54>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
mov    0x4(%rsp),%ecx
mov    %ebx,%edi
call   1050 <encode_day@plt>
jmp    11a8 <date_to_calday+0x68>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
mov    0x4(%rsp),%ecx
mov    %r14d,%edi
call   1030 <encode_julday@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @date_to_calday(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%10 = load i32, i32* %3
%11 = call i32 @calendar_dpy(i32 %10)
store i32 %11, i32* %6
%12 = load i32, i32* %4
%13 = call i32 @cdiDecodeDate(i32 %12, i32* %7, i32* %8, i32* %9)
%14 = load i32, i32* %6
%15 = icmp eq i32 %14, 360
br i1 %15, label %22, label %16
16: ; preds = %2
%17 = load i32, i32* %6
%18 = icmp eq i32 %17, 365
br i1 %18, label %22, label %19
19: ; preds = %16
%20 = load i32, i32* %6
%21 = icmp eq i32 %20, 366
br i1 %21, label %22, label %28
22: ; preds = %19, %16, %2
%23 = load i32, i32* %6
%24 = load i32, i32* %7
%25 = load i32, i32* %8
%26 = load i32, i32* %9
%27 = call i32 @encode_day(i32 %23, i32 %24, i32 %25, i32 %26)
store i32 %27, i32* %5
br label %34
28: ; preds = %19
%29 = load i32, i32* %3
%30 = load i32, i32* %7
%31 = load i32, i32* %8
%32 = load i32, i32* %9
%33 = call i32 @encode_julday(i32 %29, i32 %30, i32 %31, i32 %32)
store i32 %33, i32* %5
br label %34
34: ; preds = %28, %22
%35 = load i32, i32* %5
ret i32 %35
}

LLVM IR (-O2):
define i32 @date_to_calday(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = tail call i32 @calendar_dpy(i32 %0)
%10 = call i32 @cdiDecodeDate(i32 %1, i32* %3, i32* %4, i32* %5)
switch i32 %9, label %16 [
i32 366, label %11
i32 365, label %11
i32 360, label %11
]
11: ; preds = %2, %2, %2
%12 = load i32, i32* %3
%13 = load i32, i32* %4
%14 = load i32, i32* %5
%15 = call i32 @encode_day(i32 %9, i32 %12, i32 %13, i32 %14)
br label %21
16: ; preds = %2
%17 = load i32, i32* %3
%18 = load i32, i32* %4
%19 = load i32, i32* %5
%20 = call i32 @encode_julday(i32 %0, i32 %17, i32 %18, i32 %19)
br label %21
21: ; preds = %16, %11
%22 = phi i32 [ %15, %11 ], [ %20, %16 ]
ret i32 %22
}