#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    1191 <FirstDayOfMonth+0x71>
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     117e <FirstDayOfMonth+0x5e>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
jmp    1183 <FirstDayOfMonth+0x63>
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    11d5 <FirstDayOfMonth+0xb5>
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    1198 <FirstDayOfMonth+0x78>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FirstDayOfMonth>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %edi,%r14d
mov    $0x1,%ebp
cmp    $0x76d,%esi
jl     11c7 <FirstDayOfMonth+0xa7>
mov    $0x1,%ebp
mov    $0x76c,%ebx
jmp    1158 <FirstDayOfMonth+0x38>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebx
cmp    %ebx,%r15d
je     11c7 <FirstDayOfMonth+0xa7>
mov    %ebp,%eax
add    $0x16d,%eax
cltq
imul   $0xffffffff92492493,%rax,%rax
shr    $0x20,%rax
add    %ebp,%eax
add    $0x16d,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
sar    $0x2,%eax
add    %ecx,%eax
lea    0x0(,%rax,8),%ecx
sub    %ecx,%eax
add    %eax,%ebp
add    $0x16d,%ebp
mov    %ebx,%edi
call   1030 <IsLeapYear@plt>
test   %rax,%rax
je     1150 <FirstDayOfMonth+0x30>
add    $0x1,%bpl
movsbl %bpl,%eax
imul   $0xffffff93,%eax,%ecx
shr    $0x8,%ecx
add    %al,%cl
mov    %ecx,%edx
shr    $0x7,%dl
sar    $0x2,%cl
add    %dl,%cl
movzbl %cl,%ecx
lea    0x0(,%rcx,8),%edx
sub    %ecx,%edx
sub    %dl,%al
movzbl %al,%ebp
jmp    1150 <FirstDayOfMonth+0x30>
cmp    $0x2,%r14d
jl     1218 <FirstDayOfMonth+0xf8>
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %r15d,%esi
call   1040 <MonthDays@plt>
add    %ebp,%eax
cltq
imul   $0xffffffff92492493,%rax,%rbp
shr    $0x20,%rbp
add    %eax,%ebp
mov    %ebp,%ecx
shr    $0x1f,%ecx
sar    $0x2,%ebp
add    %ecx,%ebp
lea    0x0(,%rbp,8),%ecx
sub    %ecx,%ebp
add    %eax,%ebp
add    $0x1,%ebx
cmp    %ebx,%r14d
jne    11e0 <FirstDayOfMonth+0xc0>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
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 = srem 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 = %19, %2
%5 = phi i32 [ 1, %2 ], [ %20, %19 ]
%6 = icmp sgt i32 %0, 1
br i1 %6, label %23, label %31
7: ; preds = %2, %19
%8 = phi i32 [ %21, %19 ], [ 1900, %2 ]
%9 = phi i32 [ %20, %19 ], [ 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
br i1 %13, label %19, label %14
14: ; preds = %7
%15 = trunc i32 %11 to i8
%16 = add nsw i8 %15, 1
%17 = srem i8 %16, 7
%18 = zext i8 %17 to i32
br label %19
19: ; preds = %7, %14
%20 = phi i32 [ %18, %14 ], [ %11, %7 ]
%21 = add nuw nsw i32 %8, 1
%22 = icmp eq i32 %21, %1
br i1 %22, label %4, label %7
23: ; preds = %4, %23
%24 = phi i32 [ %29, %23 ], [ 1, %4 ]
%25 = phi i32 [ %28, %23 ], [ %5, %4 ]
%26 = tail call i32 @MonthDays(i32 %24, i32 %1)
%27 = add nsw i32 %26, %25
%28 = srem i32 %27, 7
%29 = add nuw nsw i32 %24, 1
%30 = icmp eq i32 %29, %0
br i1 %30, label %31, label %23
31: ; preds = %23, %4
%32 = phi i32 [ %5, %4 ], [ %28, %23 ]
ret i32 %32
}