#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 */
char *day_label(int);
char *month_label(int);
scalar_t__ num_days(int, int);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  int first_sunday_count = 0;
  int cur_weekday = 1;
  for (int year = 1900; year <= 2000; ++year) {
    for (int month = 0; month < 12; ++month) {
      printf("%s %d: %s\n", month_label(month), year,
             day_label(cur_weekday % 7));
      cur_weekday += num_days(year, month);
      if (cur_weekday % 7 == 0 && year >= 1901) {
        ++first_sunday_count;
      }
    }
  }
  printf("first sundays: %d\n", first_sunday_count);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
movl   $0x76c,-0x10(%rbp)
cmpl   $0x7d0,-0x10(%rbp)
jg     1226 <main+0xe6>
movl   $0x0,-0x14(%rbp)
cmpl   $0xc,-0x14(%rbp)
jge    1213 <main+0xd3>
mov    -0x14(%rbp),%edi
call   1050 <month_label@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
call   1030 <day_label@plt>
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    %rax,%rcx
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1060 <num_days@plt>
mov    %rax,%rcx
movslq -0xc(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1200 <main+0xc0>
cmpl   $0x76d,-0x10(%rbp)
jl     1200 <main+0xc0>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1205 <main+0xc5>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1178 <main+0x38>
jmp    1218 <main+0xd8>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1164 <main+0x24>
mov    -0x8(%rbp),%esi
lea    0xddb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x1,%ebx
mov    $0x76c,%r15d
xor    %r12d,%r12d
nopl   0x0(%rax)
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    $0x76d,%r15d
setae  0x7(%rsp)
mov    %ebp,%edi
call   1050 <month_label@plt>
mov    %rax,%r13
movslq %ebx,%r14
imul   $0xffffffff92492493,%r14,%rdi
shr    $0x20,%rdi
add    %r14d,%edi
mov    %edi,%eax
shr    $0x1f,%eax
sar    $0x2,%edi
add    %eax,%edi
lea    0x0(,%rdi,8),%eax
sub    %eax,%edi
add    %r14d,%edi
call   1030 <day_label@plt>
lea    0xe47(%rip),%rdi
mov    %r13,%rsi
mov    %r15d,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15d,%edi
mov    %ebp,%esi
call   1060 <num_days@plt>
mov    %rax,%rbx
add    %r14d,%ebx
imul   $0xb6db6db7,%ebx,%eax
add    $0x12492492,%eax
cmp    $0x24924925,%eax
setb   %al
and    0x7(%rsp),%al
movzbl %al,%eax
add    %eax,%r12d
add    $0x1,%ebp
cmp    $0xc,%ebp
jne    1170 <main+0x30>
add    $0x1,%r15d
cmp    $0x7d1,%r15d
jne    1160 <main+0x20>
lea    0xdf1(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [11 x i8] c"%s %d: %s\0A\00"
@.str.1 = [19 x i8] c"first sundays: %d\0A\00"
define i32 @main() {
br label %1
1: ; preds = %0, %8
%2 = phi i32 [ 1900, %0 ], [ %9, %8 ]
%3 = phi i32 [ 1, %0 ], [ %21, %8 ]
%4 = phi i32 [ 0, %0 ], [ %26, %8 ]
%5 = icmp ugt i32 %2, 1900
br label %11
6: ; preds = %8
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %26)
ret i32 0
8: ; preds = %11
%9 = add nuw nsw i32 %2, 1
%10 = icmp eq i32 %9, 2001
br i1 %10, label %6, label %1
11: ; preds = %1, %11
%12 = phi i32 [ 0, %1 ], [ %27, %11 ]
%13 = phi i32 [ %3, %1 ], [ %21, %11 ]
%14 = phi i32 [ %4, %1 ], [ %26, %11 ]
%15 = tail call i8* @month_label(i32 %12)
%16 = srem i32 %13, 7
%17 = tail call i8* @day_label(i32 %16)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %15, i32 %2, i8* %17)
%19 = tail call i64 @num_days(i32 %2, i32 %12)
%20 = trunc i64 %19 to i32
%21 = add i32 %13, %20
%22 = srem i32 %21, 7
%23 = icmp eq i32 %22, 0
%24 = select i1 %23, i1 %5, i1 false
%25 = zext i1 %24 to i32
%26 = add nsw i32 %14, %25
%27 = add nuw nsw i32 %12, 1
%28 = icmp eq i32 %27, 12
br i1 %28, label %8, label %11
}