int calculateweekindex(int y, int m, int d) {
  if (m == 1 || m == 2) {
    m += 12;
    y--;
  }
  int iweek = (d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400) % 7;
  switch (iweek) {
  case 0:
    return 2;
  case 1:
    return 3;
  case 2:
    return 4;
  case 3:
    return 5;
  case 4:
    return 6;
  case 5:
    return 7;
  case 6:
    return 1;
  }
  return -1;
}


x86 assembly (clang, -O0):
<calculateweekindex>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpl   $0x1,-0xc(%rbp)
je     1121 <calculateweekindex+0x21>
cmpl   $0x2,-0xc(%rbp)
jne    1133 <calculateweekindex+0x33>
mov    -0xc(%rbp),%eax
add    $0xc,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%edx
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
mov    %edx,%eax
lea    (%rax,%rcx,2),%eax
lea    0x3(%rcx,%rcx,2),%ecx
movslq %ecx,%rcx
imul   $0x66666667,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
sar    %ecx
add    %edx,%ecx
add    %ecx,%eax
movslq -0x8(%rbp),%rcx
mov    %ecx,%edx
add    %edx,%eax
mov    %edx,%esi
add    $0x3,%esi
test   %edx,%edx
cmovs  %esi,%edx
sar    $0x2,%edx
add    %edx,%eax
imul   $0x51eb851f,%rcx,%rdx
mov    %rdx,%rcx
shr    $0x20,%rcx
mov    %ecx,%esi
sar    $0x5,%esi
shr    $0x3f,%rdx
add    %edx,%esi
sub    %esi,%eax
sar    $0x7,%ecx
add    %edx,%ecx
add    %ecx,%eax
movslq %eax,%rcx
imul   $0xffffffff92492493,%rcx,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x2,%ecx
add    %edx,%ecx
mov    %ecx,%edx
shl    $0x3,%edx
sub    %edx,%ecx
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %rax,-0x20(%rbp)
sub    $0x6,%rax
ja     1237 <calculateweekindex+0x137>
mov    -0x20(%rbp),%rax
lea    0xe26(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x2,-0x4(%rbp)
jmp    123e <calculateweekindex+0x13e>
movl   $0x3,-0x4(%rbp)
jmp    123e <calculateweekindex+0x13e>
movl   $0x4,-0x4(%rbp)
jmp    123e <calculateweekindex+0x13e>
movl   $0x5,-0x4(%rbp)
jmp    123e <calculateweekindex+0x13e>
movl   $0x6,-0x4(%rbp)
jmp    123e <calculateweekindex+0x13e>
movl   $0x7,-0x4(%rbp)
jmp    123e <calculateweekindex+0x13e>
movl   $0x1,-0x4(%rbp)
jmp    123e <calculateweekindex+0x13e>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<calculateweekindex>:
lea    -0x1(%rsi),%eax
lea    0xc(%rsi),%ecx
cmp    $0x2,%eax
cmovae %esi,%ecx
sbb    $0x0,%edi
lea    (%rdx,%rcx,2),%r8d
lea    (%rcx,%rcx,2),%eax
add    $0x3,%eax
cltq
imul   $0x66666667,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
sar    %eax
add    %ecx,%eax
lea    0x3(%rdi),%r9d
test   %edi,%edi
cmovns %edi,%r9d
sar    $0x2,%r9d
movslq %edi,%rdx
imul   $0xffffffffae147ae1,%rdx,%rcx
mov    %rcx,%rdi
shr    $0x3f,%rdi
shr    $0x20,%rcx
sar    $0x5,%ecx
add    %edi,%ecx
imul   $0x51eb851f,%rdx,%rdi
mov    %rdi,%rsi
shr    $0x3f,%rsi
shr    $0x20,%rdi
sar    $0x7,%edi
add    %esi,%edi
add    %r8d,%edx
add    %r9d,%edx
add    %ecx,%edx
add    %edi,%edx
add    %eax,%edx
movslq %edx,%rax
imul   $0xffffffff92492493,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x2,%ecx
add    %edx,%ecx
lea    0x0(,%rcx,8),%edx
sub    %edx,%ecx
add    %eax,%ecx
mov    $0xffffffff,%eax
cmp    $0x6,%ecx
ja     11b8 <calculateweekindex+0xb8>
movslq %ecx,%rax
lea    0xe4b(%rip),%rcx
mov    (%rcx,%rax,4),%eax
ret

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

LLVM IR (-O2):
@switch.table.calculateweekindex = [7 x i32] [i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 1]
define i32 @calculateweekindex(i32 %0, i32 %1, i32 %2) {
%4 = add i32 %1, -1
%5 = icmp ult i32 %4, 2
%6 = add nsw i32 %1, 12
%7 = select i1 %5, i32 %6, i32 %1
%8 = sext i1 %5 to i32
%9 = add nsw i32 %8, %0
%10 = shl nsw i32 %7, 1
%11 = add nsw i32 %10, %2
%12 = mul i32 %7, 3
%13 = add i32 %12, 3
%14 = sdiv i32 %13, 5
%15 = sdiv i32 %9, 4
%16 = sdiv i32 %9, -100
%17 = sdiv i32 %9, 400
%18 = add i32 %11, %9
%19 = add i32 %18, %15
%20 = add i32 %19, %16
%21 = add i32 %20, %17
%22 = add i32 %21, %14
%23 = srem i32 %22, 7
%24 = icmp ult i32 %23, 7
br i1 %24, label %25, label %29
25: ; preds = %3
%26 = sext i32 %23 to i64
%27 = getelementptr inbounds [7 x i32], [7 x i32]* @switch.table.calculateweekindex, i64 0, i64 %26
%28 = load i32, i32* %27
br label %29
29: ; preds = %3, %25
%30 = phi i32 [ %28, %25 ], [ -1, %3 ]
ret i32 %30
}