#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 */
long day_in_year(int, int, int);
int day_in_week(int day, int month, int year) {
  long temp;
  temp = (long)(year - 1) * 365 +
         ((year - 1) / 4 - ((year - 1) > 1700 ? (year - 1) / 100 - 17 : 0) +
          ((year - 1) > 1600 ? ((year - 1) - 1600) / 400 : 0)) +
         day_in_year(day, month, year);
  if (temp < 639799)
    return ((temp - 1 + 6) % 7);
  if (temp >= (639799 + 11))
    return (((temp - 1 + 6) - 11) % 7);
  return (4);
}


x86 assembly (clang, -O0):
<day_in_week>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
cltq
imul   $0x16d,%rax,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
cmp    $0x6a4,%eax
jle    116f <day_in_week+0x5f>
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
sub    $0x11,%eax
mov    %eax,-0x2c(%rbp)
jmp    1179 <day_in_week+0x69>
xor    %eax,%eax
mov    %eax,-0x2c(%rbp)
jmp    1179 <day_in_week+0x69>
mov    -0x1c(%rbp),%eax
mov    -0x2c(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
cmp    $0x640,%eax
jle    11b0 <day_in_week+0xa0>
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
sub    $0x640,%eax
mov    $0x190,%ecx
cltd
idiv   %ecx
mov    %eax,-0x34(%rbp)
jmp    11ba <day_in_week+0xaa>
xor    %eax,%eax
mov    %eax,-0x34(%rbp)
jmp    11ba <day_in_week+0xaa>
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%ecx
mov    -0x34(%rbp),%edx
add    %edx,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <day_in_year@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x9c337,-0x18(%rbp)
jge    121a <day_in_week+0x10a>
mov    -0x18(%rbp),%rax
sub    $0x1,%rax
add    $0x6,%rax
mov    $0x7,%ecx
cqto
idiv   %rcx
mov    %edx,%eax
mov    %eax,-0x4(%rbp)
jmp    1253 <day_in_week+0x143>
cmpq   $0x9c342,-0x18(%rbp)
jl     124c <day_in_week+0x13c>
mov    -0x18(%rbp),%rax
sub    $0x1,%rax
add    $0x6,%rax
sub    $0xb,%rax
mov    $0x7,%ecx
cqto
idiv   %rcx
mov    %edx,%eax
mov    %eax,-0x4(%rbp)
jmp    1253 <day_in_week+0x143>
movl   $0x4,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<day_in_week>:
push   %r14
push   %rbx
push   %rax
lea    -0x1(%rdx),%ecx
movslq %ecx,%rbx
imul   $0x16d,%rbx,%r14
lea    0x2(%rdx),%eax
test   %ebx,%ebx
cmovns %ecx,%eax
sar    $0x2,%eax
cmp    $0x6a6,%edx
jl     1148 <day_in_week+0x38>
mov    %ecx,%ecx
imul   $0x51eb851f,%rcx,%rcx
shr    $0x25,%rcx
sub    %ecx,%eax
add    $0x11,%eax
jmp    1152 <day_in_week+0x42>
xor    %ecx,%ecx
cmp    $0x642,%edx
jl     1163 <day_in_week+0x53>
lea    -0x641(%rdx),%ecx
imul   $0x51eb851f,%rcx,%rcx
shr    $0x27,%rcx
add    %ecx,%eax
movslq %eax,%rbx
call   1030 <day_in_year@plt>
mov    %rax,%rcx
add    %r14,%rcx
add    %rbx,%rcx
cmp    $0x9c336,%rcx
jg     11ac <day_in_week+0x9c>
add    $0x5,%rcx
movabs $0x4924924924924925,%rdx
92 24 49
mov    %rcx,%rax
imul   %rdx
mov    %rdx,%rax
shr    $0x3f,%rax
shr    %rdx
add    %eax,%edx
lea    0x0(,%rdx,8),%eax
sub    %eax,%edx
add    %edx,%ecx
jmp    11e9 <day_in_week+0xd9>
mov    $0x4,%eax
cmp    $0x9c342,%rcx
jb     11eb <day_in_week+0xdb>
add    $0xfffffffffffffffa,%rcx
movabs $0x2492492492492493,%rdx
49 92 24
mov    %rcx,%rax
mul    %rdx
mov    %rcx,%rax
sub    %rdx,%rax
shr    %rax
add    %rdx,%rax
shr    $0x2,%rax
lea    0x0(,%rax,8),%edx
sub    %edx,%eax
add    %eax,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @day_in_week(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%9 = load i32, i32* %7
%10 = sub nsw i32 %9, 1
%11 = sext i32 %10 to i64
%12 = mul nsw i64 %11, 365
%13 = load i32, i32* %7
%14 = sub nsw i32 %13, 1
%15 = sdiv i32 %14, 4
%16 = load i32, i32* %7
%17 = sub nsw i32 %16, 1
%18 = icmp sgt i32 %17, 1700
br i1 %18, label %19, label %24
19: ; preds = %3
%20 = load i32, i32* %7
%21 = sub nsw i32 %20, 1
%22 = sdiv i32 %21, 100
%23 = sub nsw i32 %22, 17
br label %25
24: ; preds = %3
br label %25
25: ; preds = %24, %19
%26 = phi i32 [ %23, %19 ], [ 0, %24 ]
%27 = sub nsw i32 %15, %26
%28 = load i32, i32* %7
%29 = sub nsw i32 %28, 1
%30 = icmp sgt i32 %29, 1600
br i1 %30, label %31, label %36
31: ; preds = %25
%32 = load i32, i32* %7
%33 = sub nsw i32 %32, 1
%34 = sub nsw i32 %33, 1600
%35 = sdiv i32 %34, 400
br label %37
36: ; preds = %25
br label %37
37: ; preds = %36, %31
%38 = phi i32 [ %35, %31 ], [ 0, %36 ]
%39 = add nsw i32 %27, %38
%40 = sext i32 %39 to i64
%41 = add nsw i64 %12, %40
%42 = load i32, i32* %5
%43 = load i32, i32* %6
%44 = load i32, i32* %7
%45 = call i64 @day_in_year(i32 %42, i32 %43, i32 %44)
%46 = add nsw i64 %41, %45
store i64 %46, i64* %8
%47 = load i64, i64* %8
%48 = icmp slt i64 %47, 639799
br i1 %48, label %49, label %55
49: ; preds = %37
%50 = load i64, i64* %8
%51 = sub nsw i64 %50, 1
%52 = add nsw i64 %51, 6
%53 = srem i64 %52, 7
%54 = trunc i64 %53 to i32
store i32 %54, i32* %4
br label %66
55: ; preds = %37
%56 = load i64, i64* %8
%57 = icmp sge i64 %56, 639810
br i1 %57, label %58, label %65
58: ; preds = %55
%59 = load i64, i64* %8
%60 = sub nsw i64 %59, 1
%61 = add nsw i64 %60, 6
%62 = sub nsw i64 %61, 11
%63 = srem i64 %62, 7
%64 = trunc i64 %63 to i32
store i32 %64, i32* %4
br label %66
65: ; preds = %55
store i32 4, i32* %4
br label %66
66: ; preds = %65, %58, %49
%67 = load i32, i32* %4
ret i32 %67
}

LLVM IR (-O2):
define i32 @day_in_week(i32 %0, i32 %1, i32 %2) {
%4 = add nsw i32 %2, -1
%5 = sext i32 %4 to i64
%6 = mul nsw i64 %5, 365
%7 = sdiv i32 %4, 4
%8 = icmp sgt i32 %2, 1701
br i1 %8, label %9, label %13
9: ; preds = %3
%10 = udiv i32 %4, 100
%11 = sub nsw i32 17, %10
%12 = add nsw i32 %11, %7
br label %15
13: ; preds = %3
%14 = icmp sgt i32 %2, 1601
br i1 %14, label %15, label %19
15: ; preds = %9, %13
%16 = phi i32 [ %12, %9 ], [ %7, %13 ]
%17 = add nsw i32 %2, -1601
%18 = udiv i32 %17, 400
br label %19
19: ; preds = %13, %15
%20 = phi i32 [ %16, %15 ], [ %7, %13 ]
%21 = phi i32 [ %18, %15 ], [ 0, %13 ]
%22 = add nsw i32 %21, %20
%23 = sext i32 %22 to i64
%24 = tail call i64 @day_in_year(i32 %0, i32 %1, i32 %2)
%25 = add i64 %24, %6
%26 = add i64 %25, %23
%27 = icmp slt i64 %26, 639799
br i1 %27, label %28, label %32
28: ; preds = %19
%29 = add nsw i64 %26, 5
%30 = srem i64 %29, 7
%31 = trunc i64 %30 to i32
br label %38
32: ; preds = %19
%33 = icmp ugt i64 %26, 639809
br i1 %33, label %34, label %38
34: ; preds = %32
%35 = add nsw i64 %26, -6
%36 = urem i64 %35, 7
%37 = trunc i64 %36 to i32
br label %38
38: ; preds = %32, %34, %28
%39 = phi i32 [ %31, %28 ], [ %37, %34 ], [ 4, %32 ]
ret i32 %39
}