#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__ is_leap(int);
int get_first(int year) {
  int i;
  int sum = 0;
  for (i = 1900; i < year; ++i) {
    if (is_leap(i))
      sum += 366;
    else
      sum += 365;
  }
  return (sum + 1) % 7;
}


x86 assembly (clang, -O0):
<get_first>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x76c,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1175 <get_first+0x65>
mov    -0x8(%rbp),%edi
call   1030 <is_leap@plt>
cmp    $0x0,%rax
je     1157 <get_first+0x47>
mov    -0xc(%rbp),%eax
add    $0x16e,%eax
mov    %eax,-0xc(%rbp)
jmp    1162 <get_first+0x52>
mov    -0xc(%rbp),%eax
add    $0x16d,%eax
mov    %eax,-0xc(%rbp)
jmp    1167 <get_first+0x57>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1129 <get_first+0x19>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_first>:
mov    $0x1,%eax
cmp    $0x76d,%edi
jl     1175 <get_first+0x65>
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
mov    $0x76c,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1030 <is_leap@plt>
cmp    $0x1,%rax
sbb    $0x0,%ebx
add    $0x16e,%ebx
add    $0x1,%ebp
cmp    %ebp,%r14d
jne    1130 <get_first+0x20>
lea    0x1(%rbx),%eax
imul   $0x24924925,%rax,%rcx
shr    $0x20,%rcx
sub    %ecx,%eax
shr    %eax
add    %ecx,%eax
shr    $0x2,%eax
lea    0x0(,%rax,8),%ecx
sub    %ecx,%eax
add    %ebx,%eax
add    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @get_first(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %4
store i32 1900, i32* %3
br label %5
5: ; preds = %20, %1
%6 = load i32, i32* %3
%7 = load i32, i32* %2
%8 = icmp slt i32 %6, %7
br i1 %8, label %9, label %23
9: ; preds = %5
%10 = load i32, i32* %3
%11 = call i64 @is_leap(i32 %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = load i32, i32* %4
%15 = add nsw i32 %14, 366
store i32 %15, i32* %4
br label %19
16: ; preds = %9
%17 = load i32, i32* %4
%18 = add nsw i32 %17, 365
store i32 %18, i32* %4
br label %19
19: ; preds = %16, %13
br label %20
20: ; preds = %19
%21 = load i32, i32* %3
%22 = add nsw i32 %21, 1
store i32 %22, i32* %3
br label %5
23: ; preds = %5
%24 = load i32, i32* %4
%25 = add nsw i32 %24, 1
%26 = srem i32 %25, 7
ret i32 %26
}

LLVM IR (-O2):
define i32 @get_first(i32 %0) {
%2 = icmp sgt i32 %0, 1900
br i1 %2, label %3, label %15
3: ; preds = %1, %3
%4 = phi i32 [ %9, %3 ], [ 0, %1 ]
%5 = phi i32 [ %10, %3 ], [ 1900, %1 ]
%6 = tail call i64 @is_leap(i32 %5)
%7 = icmp eq i64 %6, 0
%8 = select i1 %7, i32 365, i32 366
%9 = add nuw nsw i32 %8, %4
%10 = add nuw nsw i32 %5, 1
%11 = icmp eq i32 %10, %0
br i1 %11, label %12, label %3
12: ; preds = %3
%13 = add nuw i32 %9, 1
%14 = urem i32 %13, 7
br label %15
15: ; preds = %12, %1
%16 = phi i32 [ 1, %1 ], [ %14, %12 ]
ret i32 %16
}