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


x86 assembly (clang, -O0):
<calday_to_date>:
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)
cmpl   $0x168,-0x10(%rbp)
je     1180 <calday_to_date+0x40>
cmpl   $0x16d,-0x10(%rbp)
je     1180 <calday_to_date+0x40>
cmpl   $0x16e,-0x10(%rbp)
jne    119c <calday_to_date+0x5c>
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%esi
lea    -0x14(%rbp),%rdx
lea    -0x18(%rbp),%rcx
lea    -0x1c(%rbp),%r8
call   1050 <decode_day@plt>
jmp    11b3 <calday_to_date+0x73>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
lea    -0x14(%rbp),%rdx
lea    -0x18(%rbp),%rcx
lea    -0x1c(%rbp),%r8
call   1030 <decode_julday@plt>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1040 <cdiEncodeDate@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calday_to_date>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebx
mov    %edi,%ebp
call   1060 <calendar_dpy@plt>
lea    -0x168(%rax),%ecx
cmp    $0x6,%ecx
ja     117e <calday_to_date+0x3e>
mov    $0x61,%edx
bt     %ecx,%edx
jae    117e <calday_to_date+0x3e>
lea    0x14(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0xc(%rsp),%r8
mov    %eax,%edi
mov    %ebx,%esi
call   1050 <decode_day@plt>
jmp    1196 <calday_to_date+0x56>
lea    0x14(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0xc(%rsp),%r8
mov    %ebp,%edi
mov    %ebx,%esi
call   1030 <decode_julday@plt>
mov    0x14(%rsp),%edi
mov    0x10(%rsp),%esi
mov    0xc(%rsp),%edx
call   1040 <cdiEncodeDate@plt>
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @calday_to_date(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* %6
%13 = icmp eq i32 %12, 360
br i1 %13, label %20, label %14
14: ; preds = %2
%15 = load i32, i32* %6
%16 = icmp eq i32 %15, 365
br i1 %16, label %20, label %17
17: ; preds = %14
%18 = load i32, i32* %6
%19 = icmp eq i32 %18, 366
br i1 %19, label %20, label %24
20: ; preds = %17, %14, %2
%21 = load i32, i32* %6
%22 = load i32, i32* %4
%23 = call i32 @decode_day(i32 %21, i32 %22, i32* %7, i32* %8, i32* %9)
br label %28
24: ; preds = %17
%25 = load i32, i32* %3
%26 = load i32, i32* %4
%27 = call i32 @decode_julday(i32 %25, i32 %26, i32* %7, i32* %8, i32* %9)
br label %28
28: ; preds = %24, %20
%29 = load i32, i32* %7
%30 = load i32, i32* %8
%31 = load i32, i32* %9
%32 = call i32 @cdiEncodeDate(i32 %29, i32 %30, i32 %31)
store i32 %32, i32* %5
%33 = load i32, i32* %5
ret i32 %33
}

LLVM IR (-O2):
define i32 @calday_to_date(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)
switch i32 %9, label %12 [
i32 366, label %10
i32 365, label %10
i32 360, label %10
]
10: ; preds = %2, %2, %2
%11 = call i32 @decode_day(i32 %9, i32 %1, i32* %3, i32* %4, i32* %5)
br label %14
12: ; preds = %2
%13 = call i32 @decode_julday(i32 %0, i32 %1, i32* %3, i32* %4, i32* %5)
br label %14
14: ; preds = %12, %10
%15 = load i32, i32* %3
%16 = load i32, i32* %4
%17 = load i32, i32* %5
%18 = call i32 @cdiEncodeDate(i32 %15, i32 %16, i32 %17)
ret i32 %18
}