int dayOfWeek(int date, int month, int year) {
  static const int table[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
  if (month < 2)
    year--;
  return (year + year / 4 - year / 100 + year / 400 + table[month] + date) % 7;
}


x86 assembly (clang, -O0):
<dayOfWeek>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1120 <dayOfWeek+0x20>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x190,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
add    %ecx,%eax
movslq -0x8(%rbp),%rdx
lea    0xe93(%rip),%rcx
add    (%rcx,%rdx,4),%eax
add    -0x4(%rbp),%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<dayOfWeek>:
xor    %eax,%eax
cmp    $0x2,%esi
setl   %al
sub    %eax,%edx
lea    0x3(%rdx),%r8d
test   %edx,%edx
cmovns %edx,%r8d
sar    $0x2,%r8d
movslq %edx,%rax
imul   $0xffffffffae147ae1,%rax,%rdx
mov    %rdx,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rdx
sar    $0x5,%edx
add    %ecx,%edx
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%r9
shr    $0x3f,%r9
shr    $0x20,%rcx
sar    $0x7,%ecx
add    %r9d,%ecx
movslq %esi,%rsi
lea    0xeac(%rip),%r9
add    %edi,%eax
add    %r8d,%eax
add    %edx,%eax
add    %ecx,%eax
add    (%r9,%rsi,4),%eax
movslq %eax,%rcx
imul   $0xffffffff92492493,%rcx,%rax
shr    $0x20,%rax
add    %ecx,%eax
mov    %eax,%edx
shr    $0x1f,%edx
sar    $0x2,%eax
add    %edx,%eax
lea    0x0(,%rax,8),%edx
sub    %edx,%eax
add    %ecx,%eax
ret

LLVM IR (-O0):
@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
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%7 = load i32, i32* %5
%8 = icmp slt i32 %7, 2
br i1 %8, label %9, label %12
9: ; preds = %3
%10 = load i32, i32* %6
%11 = add nsw i32 %10, -1
store i32 %11, i32* %6
br label %12
12: ; preds = %9, %3
%13 = load i32, i32* %6
%14 = load i32, i32* %6
%15 = sdiv i32 %14, 4
%16 = add nsw i32 %13, %15
%17 = load i32, i32* %6
%18 = sdiv i32 %17, 100
%19 = sub nsw i32 %16, %18
%20 = load i32, i32* %6
%21 = sdiv i32 %20, 400
%22 = add nsw i32 %19, %21
%23 = load i32, i32* %5
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [12 x i32], [12 x i32]* @dayOfWeek.table, i64 0, i64 %24
%26 = load i32, i32* %25
%27 = add nsw i32 %22, %26
%28 = load i32, i32* %4
%29 = add nsw i32 %27, %28
%30 = srem i32 %29, 7
ret i32 %30
}

LLVM IR (-O2):
@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, 2
%5 = sext i1 %4 to i32
%6 = add nsw i32 %5, %2
%7 = sdiv i32 %6, 4
%8 = sdiv i32 %6, -100
%9 = sdiv i32 %6, 400
%10 = sext i32 %1 to i64
%11 = getelementptr inbounds [12 x i32], [12 x i32]* @dayOfWeek.table, i64 0, i64 %10
%12 = load i32, i32* %11
%13 = add i32 %6, %0
%14 = add i32 %13, %7
%15 = add i32 %14, %8
%16 = add i32 %15, %9
%17 = add i32 %16, %12
%18 = srem i32 %17, 7
ret i32 %18
}