#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 daynumber(int, int, int);
char calc_week(int day_of_week, int day_of_year, int year, int isBissec) {
  int jref;
  int jder;
  int jactu;
  int nweek;
  jref = daynumber(1, 1, year);
  jder = daynumber(31, 12, year);
  jactu = day_of_week;
  if (!jref)
    jref = 7;
  if (!jder)
    jder = 7;
  if (!jactu)
    jactu = 7;
  nweek = (day_of_year - 1) / 7;
  if (jref <= 4)
    nweek++;
  if (jactu < jref)
    nweek++;
  if (nweek == 53 && jder >= 1 && jder <= 3)
    nweek = 1;
  if (nweek == 0) {
    if (jref == 5 || (jref == 6 && isBissec))
      nweek = 53;
    else
      nweek = 52;
  }
  return ((char)nweek);
}


x86 assembly (clang, -O0):
<calc_week>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    -0xc(%rbp),%edx
mov    $0x1,%esi
mov    %esi,%edi
call   1030 <daynumber@plt>
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%edx
mov    $0x1f,%edi
mov    $0xc,%esi
call   1030 <daynumber@plt>
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1162 <calc_week+0x52>
movl   $0x7,-0x14(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    1173 <calc_week+0x63>
movl   $0x7,-0x18(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1184 <calc_week+0x74>
movl   $0x7,-0x1c(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
cmpl   $0x4,-0x14(%rbp)
jg     11a8 <calc_week+0x98>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11bd <calc_week+0xad>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x35,-0x20(%rbp)
jne    11e2 <calc_week+0xd2>
cmpl   $0x1,-0x18(%rbp)
jl     11e2 <calc_week+0xd2>
cmpl   $0x3,-0x18(%rbp)
jg     11e2 <calc_week+0xd2>
movl   $0x1,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    1222 <calc_week+0x112>
cmpl   $0x5,-0x14(%rbp)
je     120a <calc_week+0xfa>
cmpl   $0x6,-0x14(%rbp)
jne    1216 <calc_week+0x106>
cmpl   $0x0,-0x10(%rbp)
je     1216 <calc_week+0x106>
movl   $0x35,-0x20(%rbp)
jmp    121d <calc_week+0x10d>
movl   $0x34,-0x20(%rbp)
jmp    1222 <calc_week+0x112>
mov    -0x20(%rbp),%eax
movsbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_week>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %edx,%ebx
mov    %esi,%r12d
mov    %edi,%r15d
mov    $0x1,%ebp
mov    $0x1,%edi
mov    $0x1,%esi
call   1030 <daynumber@plt>
mov    %eax,%r13d
mov    $0x1f,%edi
mov    $0xc,%esi
mov    %ebx,%edx
call   1030 <daynumber@plt>
test   %r13d,%r13d
mov    $0x7,%ecx
cmove  %ecx,%r13d
test   %eax,%eax
cmove  %ecx,%eax
test   %r15d,%r15d
cmove  %ecx,%r15d
mov    %r12d,%ecx
add    $0xffffffff,%ecx
movslq %ecx,%rcx
imul   $0xffffffff92492493,%rcx,%rcx
shr    $0x20,%rcx
add    %r12d,%ecx
add    $0xffffffff,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x2,%ecx
add    %edx,%ecx
xor    %edx,%edx
cmp    $0x5,%r13d
setl   %dl
add    %ecx,%edx
xor    %ecx,%ecx
cmp    %r13d,%r15d
setl   %cl
add    %edx,%ecx
cmp    $0x4,%eax
cmovge %ecx,%ebp
test   %eax,%eax
cmovle %ecx,%ebp
cmp    $0x35,%ecx
cmovne %ecx,%ebp
test   %ebp,%ebp
jne    11d4 <calc_week+0xc4>
mov    $0x35,%ebp
cmp    $0x5,%r13d
je     11d4 <calc_week+0xc4>
cmp    $0x6,%r13d
sete   %al
test   %r14d,%r14d
setne  %cl
and    %al,%cl
movzbl %cl,%ebp
or     $0x34,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define signext i8 @calc_week(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = tail call i32 @daynumber(i32 1, i32 1, i32 %2)
%6 = tail call i32 @daynumber(i32 31, i32 12, i32 %2)
%7 = icmp eq i32 %5, 0
%8 = select i1 %7, i32 7, i32 %5
%9 = icmp eq i32 %6, 0
%10 = select i1 %9, i32 7, i32 %6
%11 = icmp eq i32 %0, 0
%12 = select i1 %11, i32 7, i32 %0
%13 = add nsw i32 %1, -1
%14 = sdiv i32 %13, 7
%15 = icmp slt i32 %8, 5
%16 = zext i1 %15 to i32
%17 = add nsw i32 %14, %16
%18 = icmp slt i32 %12, %8
%19 = zext i1 %18 to i32
%20 = add nsw i32 %17, %19
%21 = icmp eq i32 %20, 53
%22 = icmp sgt i32 %10, 0
%23 = select i1 %21, i1 %22, i1 false
%24 = icmp slt i32 %10, 4
%25 = select i1 %23, i1 %24, i1 false
%26 = select i1 %25, i32 1, i32 %20
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %35
28: ; preds = %4
%29 = icmp eq i32 %8, 5
br i1 %29, label %35, label %30
30: ; preds = %28
%31 = icmp eq i32 %8, 6
%32 = icmp ne i32 %3, 0
%33 = and i1 %32, %31
%34 = select i1 %33, i32 53, i32 52
br label %35
35: ; preds = %30, %28, %4
%36 = phi i32 [ %26, %4 ], [ 53, %28 ], [ %34, %30 ]
%37 = trunc i32 %36 to i8
ret i8 %37
}