#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 EXIT_SUCCESS;
int monthLength(int, int);
int /*<<< orphan*/ printf(char *, int);
int main(int argc, char *argv[]) {
  int day = 6, month = 1, year = 1901, sundays = 0;
  while (year <= 2000) {
    if (day == 1) {
      sundays++;
    }
    int remaining = monthLength(month, year) - day;
    if (remaining >= 7) {
      day += 7;
    } else {
      day = 7 - remaining;
      if (++month > 12) {
        month = 1;
        year++;
      }
    }
  }
  printf("Solution: %d.\n", sundays);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x6,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
movl   $0x76d,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x7d0,-0x1c(%rbp)
jg     11d2 <main+0xb2>
cmpl   $0x1,-0x14(%rbp)
jne    1172 <main+0x52>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1030 <monthLength@plt>
sub    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x7,-0x24(%rbp)
jl     119b <main+0x7b>
mov    -0x14(%rbp),%eax
add    $0x7,%eax
mov    %eax,-0x14(%rbp)
jmp    11cd <main+0xad>
mov    $0x7,%eax
sub    -0x24(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmp    $0xc,%eax
jle    11c8 <main+0xa8>
movl   $0x1,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11cd <main+0xad>
jmp    1152 <main+0x32>
mov    -0x20(%rbp),%esi
lea    0xe24(%rip),%rdi
call   1040 <printf@plt>
mov    0x2df8(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x76d,%r12d
xor    %ebx,%ebx
mov    $0x6,%r13d
mov    $0x1,%r14d
jmp    1182 <main+0x62>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x7,%r13d
sub    %eax,%r13d
xor    %eax,%eax
cmp    $0xc,%r14d
lea    0x1(%r14),%ecx
setge  %al
mov    $0x1,%edx
cmovge %edx,%ecx
add    %eax,%r12d
mov    %ecx,%r14d
mov    %r15b,%bpl
add    %ebp,%ebx
cmp    $0x7d1,%r12d
jge    11a5 <main+0x85>
xor    %ebp,%ebp
cmp    $0x1,%r13d
sete   %r15b
mov    %r14d,%edi
mov    %r12d,%esi
call   1030 <monthLength@plt>
sub    %r13d,%eax
cmp    $0x7,%eax
jl     1150 <main+0x30>
add    $0x7,%r13d
jmp    1174 <main+0x54>
lea    0xe54(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
mov    0x2e26(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"Solution: %d.\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 6, i32* %6
store i32 1, i32* %7
store i32 1901, i32* %8
store i32 0, i32* %9
br label %11
11: ; preds = %41, %2
%12 = load i32, i32* %8
%13 = icmp sle i32 %12, 2000
br i1 %13, label %14, label %42
14: ; preds = %11
%15 = load i32, i32* %6
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i32, i32* %9
%19 = add nsw i32 %18, 1
store i32 %19, i32* %9
br label %20
20: ; preds = %17, %14
%21 = load i32, i32* %7
%22 = load i32, i32* %8
%23 = call i32 @monthLength(i32 %21, i32 %22)
%24 = load i32, i32* %6
%25 = sub nsw i32 %23, %24
store i32 %25, i32* %10
%26 = load i32, i32* %10
%27 = icmp sge i32 %26, 7
br i1 %27, label %28, label %31
28: ; preds = %20
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 7
store i32 %30, i32* %6
br label %41
31: ; preds = %20
%32 = load i32, i32* %10
%33 = sub nsw i32 7, %32
store i32 %33, i32* %6
%34 = load i32, i32* %7
%35 = add nsw i32 %34, 1
store i32 %35, i32* %7
%36 = icmp sgt i32 %35, 12
br i1 %36, label %37, label %40
37: ; preds = %31
store i32 1, i32* %7
%38 = load i32, i32* %8
%39 = add nsw i32 %38, 1
store i32 %39, i32* %8
br label %40
40: ; preds = %37, %31
br label %41
41: ; preds = %40, %28
br label %11
42: ; preds = %11
%43 = load i32, i32* %9
%44 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %43)
%45 = load i32, i32* @EXIT_SUCCESS
ret i32 %45
}

LLVM IR (-O2):
@.str = [15 x i8] c"Solution: %d.\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
br label %3
3: ; preds = %2, %23
%4 = phi i32 [ 6, %2 ], [ %26, %23 ]
%5 = phi i32 [ 0, %2 ], [ %10, %23 ]
%6 = phi i32 [ 1901, %2 ], [ %25, %23 ]
%7 = phi i32 [ 1, %2 ], [ %24, %23 ]
%8 = icmp eq i32 %4, 1
%9 = zext i1 %8 to i32
%10 = add nuw nsw i32 %5, %9
%11 = tail call i32 @monthLength(i32 %7, i32 %6)
%12 = sub nsw i32 %11, %4
%13 = icmp sgt i32 %12, 6
br i1 %13, label %14, label %16
14: ; preds = %3
%15 = add nsw i32 %4, 7
br label %23
16: ; preds = %3
%17 = sub nsw i32 7, %12
%18 = add nsw i32 %7, 1
%19 = icmp sgt i32 %7, 11
%20 = select i1 %19, i32 1, i32 %18
%21 = zext i1 %19 to i32
%22 = add nsw i32 %6, %21
br label %23
23: ; preds = %16, %14
%24 = phi i32 [ %7, %14 ], [ %20, %16 ]
%25 = phi i32 [ %6, %14 ], [ %22, %16 ]
%26 = phi i32 [ %15, %14 ], [ %17, %16 ]
%27 = icmp slt i32 %25, 2001
br i1 %27, label %3, label %28
28: ; preds = %23
%29 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %10)
%30 = load i32, i32* @EXIT_SUCCESS
ret i32 %30
}