#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 */
typedef int uint8_t;

/* Variables and functions */
uint8_t dayofweek(uint8_t y, uint8_t m, uint8_t d) {
  static const uint8_t dayofweek_table[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
  y -= m < 3;
  d = (((y + 2000) + ((y + 2000) / 4) - ((y + 2000) / 100) + 2000 / 400 +
        dayofweek_table[m - 1] + d) %
       7);
  if (d == 0) {
    return 7;
  } else {
    return d;
  }
}


x86 assembly (clang, -O0):
<dayofweek>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpl   $0x3,-0xc(%rbp)
setl   %al
and    $0x1,%al
movzbl %al,%ecx
mov    -0x8(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0x7d0,%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
add    $0x7d0,%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
add    $0x7d0,%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
add    $0x5,%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rdx
lea    0xe90(%rip),%rcx
add    (%rcx,%rdx,4),%eax
add    -0x10(%rbp),%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
mov    %edx,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    1197 <dayofweek+0x97>
movl   $0x7,-0x4(%rbp)
jmp    119d <dayofweek+0x9d>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<dayofweek>:
xor    %eax,%eax
cmp    $0x3,%esi
setl   %al
sub    %eax,%edi
lea    0x7d0(%rdi),%eax
lea    0x7d3(%rdi),%ecx
test   %eax,%eax
cmovns %eax,%ecx
sar    $0x2,%ecx
cltq
imul   $0xffffffffae147ae1,%rax,%rax
mov    %rax,%r8
shr    $0x3f,%r8
shr    $0x20,%rax
sar    $0x5,%eax
add    %r8d,%eax
movslq %esi,%r8
lea    0xebe(%rip),%rsi
mov    -0x4(%rsi,%r8,4),%esi
add    %edi,%edx
add    $0x7d0,%edx
add    %ecx,%edx
add    %eax,%edx
lea    (%rsi,%rdx,1),%eax
add    $0x5,%eax
add    %esi,%edx
cltq
imul   $0xffffffff92492493,%rax,%rax
shr    $0x20,%rax
add    %edx,%eax
add    $0x5,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
sar    $0x2,%eax
add    %ecx,%eax
lea    0x0(,%rax,8),%ecx
sub    %ecx,%eax
lea    (%rax,%rdx,1),%ecx
add    $0x5,%ecx
test   %ecx,%ecx
mov    $0x7,%eax
cmovne %ecx,%eax
ret

LLVM IR (-O0):
@dayofweek.dayofweek_table = internal constant [12 x i32] [i32 0, i32 3, i32 2, i32 5, i32 0, i32 3, i32 5, i32 1, i32 4, i32 6, i32 2, i32 4]
define i32 @dayofweek(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%8 = load i32, i32* %6
%9 = icmp slt i32 %8, 3
%10 = zext i1 %9 to i32
%11 = load i32, i32* %5
%12 = sub nsw i32 %11, %10
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = add nsw i32 %13, 2000
%15 = load i32, i32* %5
%16 = add nsw i32 %15, 2000
%17 = sdiv i32 %16, 4
%18 = add nsw i32 %14, %17
%19 = load i32, i32* %5
%20 = add nsw i32 %19, 2000
%21 = sdiv i32 %20, 100
%22 = sub nsw i32 %18, %21
%23 = add nsw i32 %22, 5
%24 = load i32, i32* %6
%25 = sub nsw i32 %24, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [12 x i32], [12 x i32]* @dayofweek.dayofweek_table, i64 0, i64 %26
%28 = load i32, i32* %27
%29 = add nsw i32 %23, %28
%30 = load i32, i32* %7
%31 = add nsw i32 %29, %30
%32 = srem i32 %31, 7
store i32 %32, i32* %7
%33 = load i32, i32* %7
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %3
store i32 7, i32* %4
br label %38
36: ; preds = %3
%37 = load i32, i32* %7
store i32 %37, i32* %4
br label %38
38: ; preds = %36, %35
%39 = load i32, i32* %4
ret i32 %39
}

LLVM IR (-O2):
@dayofweek.dayofweek_table = internal unnamed_addr constant [12 x i32] [i32 0, i32 3, i32 2, i32 5, i32 0, i32 3, i32 5, i32 1, i32 4, i32 6, i32 2, i32 4]
define i32 @dayofweek(i32 %0, i32 %1, i32 %2) {
%4 = icmp slt i32 %1, 3
%5 = sext i1 %4 to i32
%6 = add i32 %0, 2000
%7 = add i32 %6, %5
%8 = sdiv i32 %7, 4
%9 = sdiv i32 %7, -100
%10 = add nsw i32 %1, -1
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [12 x i32], [12 x i32]* @dayofweek.dayofweek_table, i64 0, i64 %11
%13 = load i32, i32* %12
%14 = add i32 %2, 5
%15 = add i32 %14, %7
%16 = add i32 %15, %8
%17 = add i32 %16, %9
%18 = add i32 %17, %13
%19 = srem i32 %18, 7
%20 = icmp eq i32 %19, 0
%21 = select i1 %20, i32 7, i32 %19
ret i32 %21
}