int ydtowd(int year, int yday) {
  register int wday;
  --year;
  wday = 0 + year * (365 % 7) + yday % 7;
  wday += (year + 4) / 4;
  wday -= (year + 100) / 100;
  wday += (year + 400) / 400;
  wday %= 7;
  return (wday);
}


x86 assembly (clang, -O0):
<ydtowd>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
shl    $0x0,%eax
add    $0x0,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
mov    -0x10(%rbp),%eax
add    %edx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
add    $0x4,%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
add    $0x64,%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0xc(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
add    $0x190,%eax
mov    $0x190,%ecx
cltd
idiv   %ecx
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
mov    -0xc(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<ydtowd>:
movslq %esi,%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
add    %edi,%eax
lea    0x3(%rdi),%ecx
lea    0x6(%rdi),%edx
test   %ecx,%ecx
cmovns %ecx,%edx
sar    $0x2,%edx
add    %eax,%edx
lea    0x63(%rdi),%eax
cltq
imul   $0xffffffffae147ae1,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
sar    $0x5,%eax
add    %ecx,%eax
add    %edx,%eax
add    $0x18f,%edi
movslq %edi,%rcx
imul   $0x51eb851f,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
sar    $0x7,%ecx
add    %edx,%ecx
lea    (%rax,%rcx,1),%edx
add    $0xffffffff,%edx
add    %ecx,%eax
movslq %edx,%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):
define i32 @ydtowd(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %3
%7 = add nsw i32 %6, -1
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = mul nsw i32 %8, 1
%10 = add nsw i32 0, %9
%11 = load i32, i32* %4
%12 = srem i32 %11, 7
%13 = add nsw i32 %10, %12
store i32 %13, i32* %5
%14 = load i32, i32* %3
%15 = add nsw i32 %14, 4
%16 = sdiv i32 %15, 4
%17 = load i32, i32* %5
%18 = add nsw i32 %17, %16
store i32 %18, i32* %5
%19 = load i32, i32* %3
%20 = add nsw i32 %19, 100
%21 = sdiv i32 %20, 100
%22 = load i32, i32* %5
%23 = sub nsw i32 %22, %21
store i32 %23, i32* %5
%24 = load i32, i32* %3
%25 = add nsw i32 %24, 400
%26 = sdiv i32 %25, 400
%27 = load i32, i32* %5
%28 = add nsw i32 %27, %26
store i32 %28, i32* %5
%29 = load i32, i32* %5
%30 = srem i32 %29, 7
store i32 %30, i32* %5
%31 = load i32, i32* %5
ret i32 %31
}

LLVM IR (-O2):
define i32 @ydtowd(i32 %0, i32 %1) {
%3 = add nsw i32 %0, -1
%4 = srem i32 %1, 7
%5 = add nsw i32 %3, %4
%6 = add nsw i32 %0, 3
%7 = sdiv i32 %6, 4
%8 = add nsw i32 %5, %7
%9 = add nsw i32 %0, 99
%10 = sdiv i32 %9, -100
%11 = add i32 %8, %10
%12 = add nsw i32 %0, 399
%13 = sdiv i32 %12, 400
%14 = add nsw i32 %11, %13
%15 = srem i32 %14, 7
ret i32 %15
}