int dayofweek(int y, int m, int d) {
  static int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
  y -= m < 3;
  return (y + y / 4 - y / 100 + y / 400 + t[m - 1] + d) % 7;
}


x86 assembly (clang, -O0):
<dayofweek>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
cmpl   $0x3,-0x8(%rbp)
setl   %al
and    $0x1,%al
movzbl %al,%ecx
mov    -0x4(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x190,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
add    %ecx,%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rdx
lea    0x2ebd(%rip),%rcx
add    (%rcx,%rdx,4),%eax
add    -0xc(%rbp),%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<dayofweek>:
xor    %eax,%eax
cmp    $0x3,%esi
setl   %al
sub    %eax,%edi
lea    0x3(%rdi),%r8d
test   %edi,%edi
cmovns %edi,%r8d
sar    $0x2,%r8d
movslq %edi,%rax
imul   $0xffffffffae147ae1,%rax,%rdi
mov    %rdi,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rdi
sar    $0x5,%edi
add    %ecx,%edi
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    %edx,%eax
add    %r8d,%eax
add    %edi,%eax
add    %ecx,%eax
add    -0x4(%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.t = internal global [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, 3
%9 = zext i1 %8 to i32
%10 = load i32, i32* %4
%11 = sub nsw i32 %10, %9
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = load i32, i32* %4
%14 = sdiv i32 %13, 4
%15 = add nsw i32 %12, %14
%16 = load i32, i32* %4
%17 = sdiv i32 %16, 100
%18 = sub nsw i32 %15, %17
%19 = load i32, i32* %4
%20 = sdiv i32 %19, 400
%21 = add nsw i32 %18, %20
%22 = load i32, i32* %5
%23 = sub nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [12 x i32], [12 x i32]* @dayofweek.t, i64 0, i64 %24
%26 = load i32, i32* %25
%27 = add nsw i32 %21, %26
%28 = load i32, i32* %6
%29 = add nsw i32 %27, %28
%30 = srem i32 %29, 7
ret i32 %30
}

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