int weekDay(int d, int m, int a) {
  int x, res;
  if (m > 2) {
    m = m - 2;
    x = 8;
  } else {
    a = a - 1;
    x = 13;
  }
  res = (x + d + 2 * m + ((7 * m) / 12) + a % 7 + a / 4 % 7 -
         (3 * (1 + a / 100)) / 4 % 7) %
        7;
  if (res == 0)
    return 7;
  else
    return res;
}


x86 assembly (clang, -O0):
<weekDay>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpl   $0x2,-0xc(%rbp)
jle    112c <weekDay+0x2c>
mov    -0xc(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0xc(%rbp)
movl   $0x8,-0x14(%rbp)
jmp    113c <weekDay+0x3c>
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
movl   $0xd,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    -0x8(%rbp),%eax
mov    -0xc(%rbp),%ecx
shl    $0x1,%ecx
add    %ecx,%eax
mov    %eax,-0x28(%rbp)
imul   $0x7,-0xc(%rbp),%eax
mov    $0xc,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
mov    -0x24(%rbp),%eax
add    %edx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    $0x7,%ecx
cltd
idiv   %ecx
mov    -0x20(%rbp),%eax
add    %edx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
add    $0x1,%eax
imul   $0x3,%eax,%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    $0x7,%ecx
cltd
idiv   %ecx
mov    -0x1c(%rbp),%eax
sub    %edx,%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
mov    %edx,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    11d8 <weekDay+0xd8>
movl   $0x7,-0x4(%rbp)
jmp    11de <weekDay+0xde>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<weekDay>:
lea    -0x2(%rsi),%eax
xor    %ecx,%ecx
cmp    $0x3,%esi
setl   %cl
cmovl  %esi,%eax
sub    %ecx,%edx
lea    (%rcx,%rcx,4),%ecx
add    %edi,%ecx
lea    (%rcx,%rax,2),%ecx
lea    0x0(,%rax,8),%esi
sub    %eax,%esi
movslq %esi,%rax
imul   $0x2aaaaaab,%rax,%rax
mov    %rax,%rsi
shr    $0x3f,%rsi
shr    $0x20,%rax
sar    %eax
add    %esi,%eax
add    %ecx,%eax
movslq %edx,%rcx
imul   $0xffffffff92492493,%rcx,%rdx
shr    $0x20,%rdx
add    %ecx,%edx
mov    %edx,%esi
shr    $0x1f,%esi
sar    $0x2,%edx
add    %esi,%edx
lea    0x0(,%rdx,8),%esi
sub    %esi,%edx
add    %ecx,%edx
add    %eax,%edx
lea    0x3(%rcx),%eax
test   %ecx,%ecx
cmovns %ecx,%eax
sar    $0x2,%eax
movslq %eax,%rsi
imul   $0xffffffff92492493,%rsi,%rax
shr    $0x20,%rax
add    %esi,%eax
mov    %eax,%edi
shr    $0x1f,%edi
sar    $0x2,%eax
add    %edi,%eax
lea    0x0(,%rax,8),%edi
sub    %edi,%eax
add    %esi,%eax
add    %edx,%eax
imul   $0x51eb851f,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
sar    $0x5,%ecx
add    %edx,%ecx
lea    (%rcx,%rcx,2),%edx
add    $0x3,%edx
lea    (%rcx,%rcx,2),%ecx
add    $0x6,%ecx
test   %edx,%edx
cmovns %edx,%ecx
sar    $0x2,%ecx
movslq %ecx,%rcx
imul   $0xffffffff92492493,%rcx,%rdx
shr    $0x20,%rdx
add    %ecx,%edx
mov    %edx,%esi
shr    $0x1f,%esi
sar    $0x2,%edx
add    %esi,%edx
lea    0x0(,%rdx,8),%esi
sub    %edx,%esi
sub    %ecx,%esi
lea    (%rax,%rsi,1),%ecx
add    %esi,%eax
add    $0x8,%eax
cltq
imul   $0xffffffff92492493,%rax,%rax
shr    $0x20,%rax
add    %ecx,%eax
add    $0x8,%eax
mov    %eax,%edx
shr    $0x1f,%edx
sar    $0x2,%eax
add    %edx,%eax
lea    0x0(,%rax,8),%edx
sub    %edx,%eax
add    %eax,%ecx
add    $0x8,%ecx
test   %ecx,%ecx
mov    $0x7,%eax
cmovne %ecx,%eax
ret

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

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