#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 */
scalar_t__ IsLeapYear(int);
int MonthDays(int, int);
int FirstDayOfMonth(int month, int year) {
  int weekday, i;
  weekday = 1;
  for (i = 1900; i < year; i++) {
    weekday = (weekday + 365) % 7;
    if (IsLeapYear(i))
      weekday = (weekday + 1) & 7;
  }
  for (i = 1; i < month; i++) {
    weekday = (weekday + MonthDays(i, year)) % 7;
  }
  return (weekday);
}


x86 assembly (clang, -O0):
<FirstDayOfMonth>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
movl   $0x76c,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    118c <FirstDayOfMonth+0x6c>
mov    -0xc(%rbp),%eax
add    $0x16d,%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
mov    -0x10(%rbp),%edi
call   1030 <IsLeapYear@plt>
cmp    $0x0,%rax
je     1179 <FirstDayOfMonth+0x59>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
and    $0x7,%eax
mov    %eax,-0xc(%rbp)
jmp    117e <FirstDayOfMonth+0x5e>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    113c <FirstDayOfMonth+0x1c>
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11d0 <FirstDayOfMonth+0xb0>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <MonthDays@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
add    %ecx,%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1193 <FirstDayOfMonth+0x73>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FirstDayOfMonth>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %edi,%r14d
mov    $0x1,%ebx
cmp    $0x76d,%esi
jl     11ae <FirstDayOfMonth+0x8e>
mov    $0x1,%ebx
mov    $0x76c,%r12d
nopl   0x0(%rax)
mov    %ebx,%eax
add    $0x16d,%eax
cltq
imul   $0xffffffff92492493,%rax,%rax
shr    $0x20,%rax
lea    (%rax,%rbx,1),%ebp
add    $0x16d,%ebp
mov    %ebp,%eax
shr    $0x1f,%eax
sar    $0x2,%ebp
add    %eax,%ebp
lea    0x0(,%rbp,8),%eax
sub    %eax,%ebp
lea    (%rbx,%rbp,1),%r13d
add    $0x16d,%r13d
mov    %r12d,%edi
call   1030 <IsLeapYear@plt>
add    %ebp,%ebx
add    $0x16e,%ebx
and    $0x7,%ebx
test   %rax,%rax
cmove  %r13d,%ebx
add    $0x1,%r12d
cmp    %r12d,%r15d
jne    1150 <FirstDayOfMonth+0x30>
cmp    $0x2,%r14d
jl     11f8 <FirstDayOfMonth+0xd8>
mov    $0x1,%ebp
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %r15d,%esi
call   1040 <MonthDays@plt>
add    %ebx,%eax
cltq
imul   $0xffffffff92492493,%rax,%rbx
shr    $0x20,%rbx
add    %eax,%ebx
mov    %ebx,%ecx
shr    $0x1f,%ecx
sar    $0x2,%ebx
add    %ecx,%ebx
lea    0x0(,%rbx,8),%ecx
sub    %ecx,%ebx
add    %eax,%ebx
add    $0x1,%ebp
cmp    %ebp,%r14d
jne    11c0 <FirstDayOfMonth+0xa0>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @FirstDayOfMonth(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 1, i32* %5
store i32 1900, i32* %6
br label %7
7: ; preds = %23, %2
%8 = load i32, i32* %6
%9 = load i32, i32* %4
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %26
11: ; preds = %7
%12 = load i32, i32* %5
%13 = add nsw i32 %12, 365
%14 = srem i32 %13, 7
store i32 %14, i32* %5
%15 = load i32, i32* %6
%16 = call i64 @IsLeapYear(i32 %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %11
%19 = load i32, i32* %5
%20 = add nsw i32 %19, 1
%21 = and i32 %20, 7
store i32 %21, i32* %5
br label %22
22: ; preds = %18, %11
br label %23
23: ; preds = %22
%24 = load i32, i32* %6
%25 = add nsw i32 %24, 1
store i32 %25, i32* %6
br label %7
26: ; preds = %7
store i32 1, i32* %6
br label %27
27: ; preds = %38, %26
%28 = load i32, i32* %6
%29 = load i32, i32* %3
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %41
31: ; preds = %27
%32 = load i32, i32* %5
%33 = load i32, i32* %6
%34 = load i32, i32* %4
%35 = call i32 @MonthDays(i32 %33, i32 %34)
%36 = add nsw i32 %32, %35
%37 = srem i32 %36, 7
store i32 %37, i32* %5
br label %38
38: ; preds = %31
%39 = load i32, i32* %6
%40 = add nsw i32 %39, 1
store i32 %40, i32* %6
br label %27
41: ; preds = %27
%42 = load i32, i32* %5
ret i32 %42
}

LLVM IR (-O2):
define i32 @FirstDayOfMonth(i32 %0, i32 %1) {
%3 = icmp sgt i32 %1, 1900
br i1 %3, label %7, label %4
4: ; preds = %7, %2
%5 = phi i32 [ 1, %2 ], [ %16, %7 ]
%6 = icmp sgt i32 %0, 1
br i1 %6, label %19, label %27
7: ; preds = %2, %7
%8 = phi i32 [ %17, %7 ], [ 1900, %2 ]
%9 = phi i32 [ %16, %7 ], [ 1, %2 ]
%10 = add nsw i32 %9, 365
%11 = srem i32 %10, 7
%12 = tail call i64 @IsLeapYear(i32 %8)
%13 = icmp eq i64 %12, 0
%14 = add nsw i32 %11, 1
%15 = and i32 %14, 7
%16 = select i1 %13, i32 %11, i32 %15
%17 = add nuw nsw i32 %8, 1
%18 = icmp eq i32 %17, %1
br i1 %18, label %4, label %7
19: ; preds = %4, %19
%20 = phi i32 [ %25, %19 ], [ 1, %4 ]
%21 = phi i32 [ %24, %19 ], [ %5, %4 ]
%22 = tail call i32 @MonthDays(i32 %20, i32 %1)
%23 = add nsw i32 %22, %21
%24 = srem i32 %23, 7
%25 = add nuw nsw i32 %20, 1
%26 = icmp eq i32 %25, %0
br i1 %26, label %27, label %19
27: ; preds = %19, %4
%28 = phi i32 [ %5, %4 ], [ %24, %19 ]
ret i32 %28
}