int get_day_of_week(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 - 1) % 7;
}


x86 assembly (clang, -O0):
<get_day_of_week>:
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
sub    $0x1,%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_day_of_week>:
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,%r9
lea    0xeac(%rip),%rsi
mov    -0x4(%rsi,%r9,4),%esi
add    %edx,%eax
add    %r8d,%eax
add    %edi,%eax
add    %ecx,%eax
lea    (%rsi,%rax,1),%ecx
add    $0xffffffff,%ecx
add    %esi,%eax
movslq %ecx,%rcx
imul   $0xffffffff92492493,%rcx,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x2,%ecx
add    %edx,%ecx
lea    0x0(,%rcx,8),%edx
sub    %edx,%ecx
add    %ecx,%eax
add    $0xffffffff,%eax
ret

LLVM IR (-O0):
@get_day_of_week.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 @get_day_of_week(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]* @get_day_of_week.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 = sub nsw i32 %29, 1
%31 = srem i32 %30, 7
ret i32 %31
}

LLVM IR (-O2):
@get_day_of_week.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 @get_day_of_week(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]* @get_day_of_week.t, i64 0, i64 %11
%13 = load i32, i32* %12
%14 = add i32 %2, -1
%15 = add i32 %14, %6
%16 = add i32 %15, %7
%17 = add i32 %16, %8
%18 = add i32 %17, %9
%19 = add i32 %18, %13
%20 = srem i32 %19, 7
ret i32 %20
}