#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 hc_get_heb_year_type(int const);
int heb_is_leap_year(int const);
long heb_to_abs_date(int const, int, int);
long rosh_hashana_abs_date(int const);
int hc_compute_keviut(const int year, int *rosh_hashana_dow,
                      int *pesach_begin_dow, int *ck, int *leap) {
  long rosh, pesach;
  if (year < 1)
    return -1;
  rosh = rosh_hashana_abs_date(year);
  if (rosh_hashana_dow != NULL)
    *rosh_hashana_dow = (rosh + 1) % 7;
  pesach = heb_to_abs_date(year, 1, 15);
  if (pesach_begin_dow != NULL)
    *pesach_begin_dow = (pesach + 1) % 7;
  if (ck != NULL)
    *ck = hc_get_heb_year_type(year);
  if (leap != NULL)
    *leap = heb_is_leap_year(year);
  return 0;
}


x86 assembly (clang, -O0):
<hc_compute_keviut>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
cmpl   $0x1,-0x8(%rbp)
jge    1171 <hc_compute_keviut+0x31>
movl   $0xffffffff,-0x4(%rbp)
jmp    121a <hc_compute_keviut+0xda>
mov    -0x8(%rbp),%edi
call   1040 <rosh_hashana_abs_date@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11a2 <hc_compute_keviut+0x62>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    $0x7,%ecx
cqto
idiv   %rcx
mov    %edx,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
mov    $0xf,%edx
call   1050 <heb_to_abs_date@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11dd <hc_compute_keviut+0x9d>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    $0x7,%ecx
cqto
idiv   %rcx
mov    %edx,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
cmpq   $0x0,-0x20(%rbp)
je     11f8 <hc_compute_keviut+0xb8>
mov    -0x8(%rbp),%edi
call   1060 <hc_get_heb_year_type@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
cmpq   $0x0,-0x28(%rbp)
je     1213 <hc_compute_keviut+0xd3>
mov    -0x8(%rbp),%edi
call   1030 <heb_is_leap_year@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hc_compute_keviut>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edi,%edi
jle    11fb <hc_compute_keviut+0xbb>
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%rbx
mov    %edi,%ebp
call   1040 <rosh_hashana_abs_date@plt>
movabs $0x4924924924924925,%r13
92 24 49
test   %rbx,%rbx
je     119b <hc_compute_keviut+0x5b>
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,%rax
imul   %r13
mov    %rdx,%rax
shr    $0x3f,%rax
shr    %rdx
add    %eax,%edx
lea    0x0(,%rdx,8),%eax
sub    %eax,%edx
add    %edx,%ecx
mov    %ecx,(%rbx)
mov    %ebp,%edi
mov    $0x1,%esi
mov    $0xf,%edx
call   1050 <heb_to_abs_date@plt>
test   %r12,%r12
je     11d9 <hc_compute_keviut+0x99>
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,%rax
imul   %r13
mov    %rdx,%rax
shr    $0x3f,%rax
shr    %rdx
add    %eax,%edx
lea    0x0(,%rdx,8),%eax
sub    %eax,%edx
add    %edx,%ecx
mov    %ecx,(%r12)
test   %r15,%r15
je     11e8 <hc_compute_keviut+0xa8>
mov    %ebp,%edi
call   1060 <hc_get_heb_year_type@plt>
mov    %eax,(%r15)
xor    %ebx,%ebx
test   %r14,%r14
je     1200 <hc_compute_keviut+0xc0>
mov    %ebp,%edi
call   1030 <heb_is_leap_year@plt>
mov    %eax,(%r14)
jmp    1200 <hc_compute_keviut+0xc0>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @hc_compute_keviut(i32 %0, i32* %1, i32* %2, i32* %3, i32* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i64
%13 = alloca i64
store i32 %0, i32* %7
store i32* %1, i32** %8
store i32* %2, i32** %9
store i32* %3, i32** %10
store i32* %4, i32** %11
%14 = load i32, i32* %7
%15 = icmp slt i32 %14, 1
br i1 %15, label %16, label %17
16: ; preds = %5
store i32 -1, i32* %6
br label %54
17: ; preds = %5
%18 = load i32, i32* %7
%19 = call i64 @rosh_hashana_abs_date(i32 %18)
store i64 %19, i64* %12
%20 = load i32*, i32** %8
%21 = icmp ne i32* %20, null
br i1 %21, label %22, label %28
22: ; preds = %17
%23 = load i64, i64* %12
%24 = add nsw i64 %23, 1
%25 = srem i64 %24, 7
%26 = trunc i64 %25 to i32
%27 = load i32*, i32** %8
store i32 %26, i32* %27
br label %28
28: ; preds = %22, %17
%29 = load i32, i32* %7
%30 = call i64 @heb_to_abs_date(i32 %29, i32 1, i32 15)
store i64 %30, i64* %13
%31 = load i32*, i32** %9
%32 = icmp ne i32* %31, null
br i1 %32, label %33, label %39
33: ; preds = %28
%34 = load i64, i64* %13
%35 = add nsw i64 %34, 1
%36 = srem i64 %35, 7
%37 = trunc i64 %36 to i32
%38 = load i32*, i32** %9
store i32 %37, i32* %38
br label %39
39: ; preds = %33, %28
%40 = load i32*, i32** %10
%41 = icmp ne i32* %40, null
br i1 %41, label %42, label %46
42: ; preds = %39
%43 = load i32, i32* %7
%44 = call i32 @hc_get_heb_year_type(i32 %43)
%45 = load i32*, i32** %10
store i32 %44, i32* %45
br label %46
46: ; preds = %42, %39
%47 = load i32*, i32** %11
%48 = icmp ne i32* %47, null
br i1 %48, label %49, label %53
49: ; preds = %46
%50 = load i32, i32* %7
%51 = call i32 @heb_is_leap_year(i32 %50)
%52 = load i32*, i32** %11
store i32 %51, i32* %52
br label %53
53: ; preds = %49, %46
store i32 0, i32* %6
br label %54
54: ; preds = %53, %16
%55 = load i32, i32* %6
ret i32 %55
}

LLVM IR (-O2):
define i32 @hc_compute_keviut(i32 %0, i32* writeonly %1, i32* writeonly %2, i32* writeonly %3, i32* writeonly %4) {
%6 = icmp slt i32 %0, 1
br i1 %6, label %29, label %7
7: ; preds = %5
%8 = tail call i64 @rosh_hashana_abs_date(i32 %0)
%9 = icmp eq i32* %1, null
br i1 %9, label %14, label %10
10: ; preds = %7
%11 = add nsw i64 %8, 1
%12 = srem i64 %11, 7
%13 = trunc i64 %12 to i32
store i32 %13, i32* %1
br label %14
14: ; preds = %10, %7
%15 = tail call i64 @heb_to_abs_date(i32 %0, i32 1, i32 15)
%16 = icmp eq i32* %2, null
br i1 %16, label %21, label %17
17: ; preds = %14
%18 = add nsw i64 %15, 1
%19 = srem i64 %18, 7
%20 = trunc i64 %19 to i32
store i32 %20, i32* %2
br label %21
21: ; preds = %17, %14
%22 = icmp eq i32* %3, null
br i1 %22, label %25, label %23
23: ; preds = %21
%24 = tail call i32 @hc_get_heb_year_type(i32 %0)
store i32 %24, i32* %3
br label %25
25: ; preds = %23, %21
%26 = icmp eq i32* %4, null
br i1 %26, label %29, label %27
27: ; preds = %25
%28 = tail call i32 @heb_is_leap_year(i32 %0)
store i32 %28, i32* %4
br label %29
29: ; preds = %25, %27, %5
%30 = phi i32 [ -1, %5 ], [ 0, %27 ], [ 0, %25 ]
ret i32 %30
}