#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 /*<<< orphan*/ _compass_jdate(int, int *, int /*<<< orphan*/ *,
                                  int /*<<< orphan*/ *);
int _compass_jday(int d, int m, int y) {
  int c, ya, j, dd;
  if (!(1 <= d && d <= 31 && 1 <= m && m <= 12 && 1 <= y && y <= 4000))
    return -1;
  if (m >= 3)
    m -= 3;
  else
    m += 9, y--;
  c = y / 100;
  ya = y - 100 * c;
  j = (146097 * c) / 4 + (1461 * ya) / 4 + (153 * m + 2) / 5 + d + 1721119;
  _compass_jdate(j, &dd, NULL, NULL);
  if (d != dd)
    return -1;
  return j;
}


x86 assembly (clang, -O0):
<_compass_jday>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    $0x1,%eax
cmp    -0x8(%rbp),%eax
jg     116c <_compass_jday+0x5c>
cmpl   $0x1f,-0x8(%rbp)
jg     116c <_compass_jday+0x5c>
mov    $0x1,%eax
cmp    -0xc(%rbp),%eax
jg     116c <_compass_jday+0x5c>
cmpl   $0xc,-0xc(%rbp)
jg     116c <_compass_jday+0x5c>
mov    $0x1,%eax
cmp    -0x10(%rbp),%eax
jg     116c <_compass_jday+0x5c>
cmpl   $0xfa0,-0x10(%rbp)
jle    1178 <_compass_jday+0x68>
movl   $0xffffffff,-0x4(%rbp)
jmp    123c <_compass_jday+0x12c>
cmpl   $0x3,-0xc(%rbp)
jl     1190 <_compass_jday+0x80>
mov    -0xc(%rbp),%eax
sub    $0x3,%eax
mov    %eax,-0xc(%rbp)
jmp    11a2 <_compass_jday+0x92>
mov    -0xc(%rbp),%eax
add    $0x9,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
imul   $0x64,-0x14(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x18(%rbp)
imul   $0x23ab1,-0x14(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,-0x28(%rbp)
imul   $0x5b5,-0x18(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x24(%rbp)
imul   $0x99,-0xc(%rbp),%eax
add    $0x2,%eax
mov    $0x5,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
add    -0x8(%rbp),%eax
add    $0x1a431f,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   1030 <_compass_jdate@plt>
mov    -0x8(%rbp),%eax
cmp    -0x20(%rbp),%eax
je     1236 <_compass_jday+0x126>
movl   $0xffffffff,-0x4(%rbp)
jmp    123c <_compass_jday+0x12c>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_compass_jday>:
push   %rbp
push   %rbx
push   %rax
lea    -0x1(%rdx),%ecx
mov    $0xffffffff,%eax
cmp    $0xf9f,%ecx
ja     11bb <_compass_jday+0xab>
mov    %edi,%ebx
lea    -0x1(%rbx),%edi
cmp    $0x1e,%edi
ja     11bb <_compass_jday+0xab>
lea    -0x1(%rsi),%edi
cmp    $0xb,%edi
ja     11bb <_compass_jday+0xab>
lea    0x9(%rsi),%eax
lea    0xfffd(%rsi),%edi
cmp    $0x3,%esi
cmovae %edx,%ecx
cmovb  %eax,%edi
movzwl %cx,%eax
shr    $0x2,%eax
imul   $0x147b,%eax,%eax
shr    $0x11,%eax
imul   $0xffffff9c,%eax,%edx
add    %ecx,%edx
imul   $0x23ab1,%eax,%eax
shr    $0x2,%eax
imul   $0x5b5,%edx,%ecx
lea    0x3(%rcx),%edx
test   %ecx,%ecx
cmovns %ecx,%edx
sar    $0x2,%edx
imul   $0x99,%edi,%ecx
add    $0x2,%ecx
movzwl %cx,%ecx
imul   $0xcccd,%ecx,%ecx
shr    $0x12,%ecx
add    %ebx,%eax
add    %ecx,%eax
lea    (%rdx,%rax,1),%ebp
add    $0x1a431f,%ebp
lea    0x4(%rsp),%rsi
mov    %ebp,%edi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <_compass_jdate@plt>
cmp    %ebx,0x4(%rsp)
mov    $0xffffffff,%eax
cmove  %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @_compass_jday(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%12 = load i32, i32* %5
%13 = icmp sle i32 1, %12
br i1 %13, label %14, label %29
14: ; preds = %3
%15 = load i32, i32* %5
%16 = icmp sle i32 %15, 31
br i1 %16, label %17, label %29
17: ; preds = %14
%18 = load i32, i32* %6
%19 = icmp sle i32 1, %18
br i1 %19, label %20, label %29
20: ; preds = %17
%21 = load i32, i32* %6
%22 = icmp sle i32 %21, 12
br i1 %22, label %23, label %29
23: ; preds = %20
%24 = load i32, i32* %7
%25 = icmp sle i32 1, %24
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i32, i32* %7
%28 = icmp sle i32 %27, 4000
br i1 %28, label %30, label %29
29: ; preds = %26, %23, %20, %17, %14, %3
store i32 -1, i32* %4
br label %71
30: ; preds = %26
%31 = load i32, i32* %6
%32 = icmp sge i32 %31, 3
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = load i32, i32* %6
%35 = sub nsw i32 %34, 3
store i32 %35, i32* %6
br label %41
36: ; preds = %30
%37 = load i32, i32* %6
%38 = add nsw i32 %37, 9
store i32 %38, i32* %6
%39 = load i32, i32* %7
%40 = add nsw i32 %39, -1
store i32 %40, i32* %7
br label %41
41: ; preds = %36, %33
%42 = load i32, i32* %7
%43 = sdiv i32 %42, 100
store i32 %43, i32* %8
%44 = load i32, i32* %7
%45 = load i32, i32* %8
%46 = mul nsw i32 100, %45
%47 = sub nsw i32 %44, %46
store i32 %47, i32* %9
%48 = load i32, i32* %8
%49 = mul nsw i32 146097, %48
%50 = sdiv i32 %49, 4
%51 = load i32, i32* %9
%52 = mul nsw i32 1461, %51
%53 = sdiv i32 %52, 4
%54 = add nsw i32 %50, %53
%55 = load i32, i32* %6
%56 = mul nsw i32 153, %55
%57 = add nsw i32 %56, 2
%58 = sdiv i32 %57, 5
%59 = add nsw i32 %54, %58
%60 = load i32, i32* %5
%61 = add nsw i32 %59, %60
%62 = add nsw i32 %61, 1721119
store i32 %62, i32* %10
%63 = load i32, i32* %10
%64 = call i32 @_compass_jdate(i32 %63, i32* %11, i32* null, i32* null)
%65 = load i32, i32* %5
%66 = load i32, i32* %11
%67 = icmp ne i32 %65, %66
br i1 %67, label %68, label %69
68: ; preds = %41
store i32 -1, i32* %4
br label %71
69: ; preds = %41
%70 = load i32, i32* %10
store i32 %70, i32* %4
br label %71
71: ; preds = %69, %68, %29
%72 = load i32, i32* %4
ret i32 %72
}

LLVM IR (-O2):
define i32 @_compass_jday(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = add i32 %0, -1
%7 = icmp ult i32 %6, 31
%8 = add i32 %1, -1
%9 = icmp ult i32 %8, 12
%10 = and i1 %7, %9
%11 = add i32 %2, -1
%12 = icmp ult i32 %11, 4000
%13 = and i1 %12, %10
br i1 %13, label %14, label %41
14: ; preds = %3
%15 = icmp ugt i32 %1, 2
%16 = select i1 %15, i32 %2, i32 %11
%17 = select i1 %15, i32 65533, i32 9
%18 = add nuw nsw i32 %17, %1
%19 = trunc i32 %16 to i16
%20 = udiv i16 %19, 100
%21 = zext i16 %20 to i32
%22 = mul nsw i32 %21, -100
%23 = add nsw i32 %22, %16
%24 = mul nuw nsw i32 %21, 146097
%25 = lshr i32 %24, 2
%26 = mul nsw i32 %23, 1461
%27 = sdiv i32 %26, 4
%28 = trunc i32 %18 to i16
%29 = mul i16 %28, 153
%30 = add i16 %29, 2
%31 = udiv i16 %30, 5
%32 = zext i16 %31 to i32
%33 = add nuw nsw i32 %0, 1721119
%34 = add nuw nsw i32 %33, %25
%35 = add nuw nsw i32 %34, %32
%36 = add nsw i32 %35, %27
%37 = call i32 @_compass_jdate(i32 %36, i32* %4, i32* null, i32* null)
%38 = load i32, i32* %4
%39 = icmp eq i32 %38, %0
%40 = select i1 %39, i32 %36, i32 -1
br label %41
41: ; preds = %14, %3
%42 = phi i32 [ -1, %3 ], [ %40, %14 ]
ret i32 %42
}