int day_of_week(long date) {
  int year = (int)((date) / 10000L), month = (int)(((date) % 10000L) / 100),
      day = (int)((date) % 100);
  if (month > 2)
    month -= 2;
  else {
    month += 10;
    year--;
  }
  day = ((13 * month - 1) / 5) + day + (year % 100) + ((year % 100) / 4) +
        ((year / 100) / 4) - 2 * (year / 100) + 77;
  return (day - 7 * (day / 7));
}


x86 assembly (clang, -O0):
<day_of_week>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    $0x2710,%ecx
cqto
idiv   %rcx
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    $0x2710,%ecx
cqto
idiv   %rcx
mov    %rdx,%rax
mov    $0x64,%ecx
cqto
idiv   %rcx
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    $0x64,%ecx
cqto
idiv   %rcx
mov    %edx,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x2,-0x10(%rbp)
jle    1162 <day_of_week+0x62>
mov    -0x10(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x10(%rbp)
jmp    1174 <day_of_week+0x74>
mov    -0x10(%rbp),%eax
add    $0xa,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
imul   $0xd,-0x10(%rbp),%eax
sub    $0x1,%eax
mov    $0x5,%ecx
cltd
idiv   %ecx
add    -0x14(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    -0x28(%rbp),%eax
add    %edx,%eax
mov    %eax,-0x24(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
shl    $0x1,%ecx
sub    %ecx,%eax
add    $0x4d,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
imul   $0x7,%ecx,%ecx
sub    %ecx,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<day_of_week>:
mov    %rdi,%r8
movabs $0x346dc5d63886594b,%rcx
c5 6d 34
mov    %rdi,%rax
imul   %rcx
mov    %rdx,%rcx
mov    %rdx,%rax
shr    $0x3f,%rax
shr    $0xb,%rcx
add    %eax,%ecx
imul   $0x2710,%ecx,%eax
mov    %r8d,%edx
sub    %eax,%edx
movswl %dx,%eax
imul   $0x147b,%eax,%edx
mov    %edx,%esi
sar    $0x13,%esi
shr    $0x1f,%edx
xor    %edi,%edi
cmp    $0x12c,%eax
setl   %dil
lea    0xfffe(%rsi,%rdx,1),%eax
lea    0xa(%rsi,%rdx,1),%esi
cmovge %eax,%esi
sub    %edi,%ecx
movabs $0xa3d70a3d70a3d70b,%rdx
0a d7 a3
mov    %r8,%rax
imul   %rdx
add    %r8,%rdx
mov    %rdx,%rax
shr    $0x3f,%rax
shr    $0x6,%rdx
add    %eax,%edx
imul   $0x64,%edx,%eax
sub    %eax,%r8d
lea    (%rsi,%rsi,2),%eax
lea    (%rsi,%rax,4),%eax
add    $0xffffffff,%eax
cwtl
imul   $0x6667,%eax,%r10d
mov    %r10d,%edx
shr    $0x1f,%edx
sar    $0x11,%r10d
add    %edx,%r10d
movslq %ecx,%rsi
imul   $0x51eb851f,%rsi,%rdx
mov    %rdx,%rcx
shr    $0x20,%rcx
mov    %ecx,%edi
sar    $0x5,%edi
shr    $0x3f,%rdx
add    %edx,%edi
imul   $0x64,%edi,%r9d
imul   $0xffffffffae147ae1,%rsi,%rdi
sub    %r9d,%esi
mov    %esi,%eax
sar    $0x7,%al
shr    $0x6,%al
add    %sil,%al
sar    $0x2,%al
movsbl %al,%r9d
mov    %rdi,%rax
shr    $0x3f,%rax
shr    $0x20,%rdi
sar    $0x5,%edi
add    %eax,%edi
sar    $0x7,%ecx
add    %edx,%ecx
add    %r8d,%esi
add    %ecx,%esi
lea    (%rsi,%rdi,2),%eax
add    %r10d,%eax
lea    (%r9,%rax,1),%ecx
add    $0x4d,%ecx
add    %r9d,%eax
movslq %ecx,%rcx
imul   $0xffffffff92492493,%rcx,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
add    $0x4d,%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    $0x4d,%eax
ret

LLVM IR (-O0):
define i32 @day_of_week(i64 %0) {
%2 = alloca i64
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i64 %0, i64* %2
%6 = load i64, i64* %2
%7 = sdiv i64 %6, 10000
%8 = trunc i64 %7 to i32
store i32 %8, i32* %3
%9 = load i64, i64* %2
%10 = srem i64 %9, 10000
%11 = sdiv i64 %10, 100
%12 = trunc i64 %11 to i32
store i32 %12, i32* %4
%13 = load i64, i64* %2
%14 = srem i64 %13, 100
%15 = trunc i64 %14 to i32
store i32 %15, i32* %5
%16 = load i32, i32* %4
%17 = icmp sgt i32 %16, 2
br i1 %17, label %18, label %21
18: ; preds = %1
%19 = load i32, i32* %4
%20 = sub nsw i32 %19, 2
store i32 %20, i32* %4
br label %26
21: ; preds = %1
%22 = load i32, i32* %4
%23 = add nsw i32 %22, 10
store i32 %23, i32* %4
%24 = load i32, i32* %3
%25 = add nsw i32 %24, -1
store i32 %25, i32* %3
br label %26
26: ; preds = %21, %18
%27 = load i32, i32* %4
%28 = mul nsw i32 13, %27
%29 = sub nsw i32 %28, 1
%30 = sdiv i32 %29, 5
%31 = load i32, i32* %5
%32 = add nsw i32 %30, %31
%33 = load i32, i32* %3
%34 = srem i32 %33, 100
%35 = add nsw i32 %32, %34
%36 = load i32, i32* %3
%37 = srem i32 %36, 100
%38 = sdiv i32 %37, 4
%39 = add nsw i32 %35, %38
%40 = load i32, i32* %3
%41 = sdiv i32 %40, 100
%42 = sdiv i32 %41, 4
%43 = add nsw i32 %39, %42
%44 = load i32, i32* %3
%45 = sdiv i32 %44, 100
%46 = mul nsw i32 2, %45
%47 = sub nsw i32 %43, %46
%48 = add nsw i32 %47, 77
store i32 %48, i32* %5
%49 = load i32, i32* %5
%50 = load i32, i32* %5
%51 = sdiv i32 %50, 7
%52 = mul nsw i32 7, %51
%53 = sub nsw i32 %49, %52
ret i32 %53
}

LLVM IR (-O2):
define i32 @day_of_week(i64 %0) {
%2 = sdiv i64 %0, 10000
%3 = trunc i64 %2 to i32
%4 = srem i64 %0, 10000
%5 = trunc i64 %4 to i16
%6 = sdiv i16 %5, 100
%7 = icmp sgt i16 %5, 299
%8 = xor i1 %7, true
%9 = sext i1 %8 to i32
%10 = add nsw i32 %9, %3
%11 = select i1 %7, i16 -2, i16 10
%12 = add nsw i16 %11, %6
%13 = srem i64 %0, 100
%14 = trunc i64 %13 to i32
%15 = mul nsw i16 %12, 13
%16 = add nsw i16 %15, -1
%17 = sdiv i16 %16, 5
%18 = sext i16 %17 to i32
%19 = srem i32 %10, 100
%20 = trunc i32 %19 to i8
%21 = sdiv i8 %20, 4
%22 = sext i8 %21 to i32
%23 = sdiv i32 %10, -100
%24 = sdiv i32 %10, 400
%25 = shl nsw i32 %23, 1
%26 = add nsw i32 %14, 77
%27 = add nsw i32 %26, %19
%28 = add nsw i32 %27, %24
%29 = add i32 %28, %25
%30 = add i32 %29, %18
%31 = add i32 %30, %22
%32 = srem i32 %31, 7
ret i32 %32
}