int dayOfWeek(int doomsday, int leapYear, int month, int day) {
  int dayOfWeek = 0;
  int dateOfDoomsday = 0;
  if (month == 1 && leapYear == 1) {
    dateOfDoomsday = 4;
  } else if (month == 1 && leapYear == 0) {
    dateOfDoomsday = 3;
  } else if (month == 2 && leapYear == 1) {
    dateOfDoomsday = 29;
  } else if (month == 2 && leapYear == 0) {
    dateOfDoomsday = 28;
  } else if (month == 3) {
    dateOfDoomsday = 7;
  } else if (month == 4) {
    dateOfDoomsday = 4;
  } else if (month == 5) {
    dateOfDoomsday = 2;
  } else if (month == 6) {
    dateOfDoomsday = 6;
  } else if (month == 7) {
    dateOfDoomsday = 4;
  } else if (month == 8) {
    dateOfDoomsday = 8;
  } else if (month == 9) {
    dateOfDoomsday = 5;
  } else if (month == 10) {
    dateOfDoomsday = 3;
  } else if (month == 11) {
    dateOfDoomsday = 7;
  } else if (month == 12) {
    dateOfDoomsday = 5;
  }
  dayOfWeek = doomsday;
  if (day < dateOfDoomsday) {
    dayOfWeek = (((doomsday - (dateOfDoomsday - day)) + 42) % 7);
  } else if (day > dateOfDoomsday) {
    dayOfWeek = (((doomsday + (day - dateOfDoomsday)) + 42) % 7);
  }
  return (dayOfWeek);
}


x86 assembly (clang, -O0):
<dayOfWeek>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    113e <dayOfWeek+0x3e>
cmpl   $0x1,-0x8(%rbp)
jne    113e <dayOfWeek+0x3e>
movl   $0x4,-0x18(%rbp)
jmp    12b6 <dayOfWeek+0x1b6>
cmpl   $0x1,-0xc(%rbp)
jne    115e <dayOfWeek+0x5e>
cmpl   $0x0,-0x8(%rbp)
jne    115e <dayOfWeek+0x5e>
movl   $0x3,-0x18(%rbp)
jmp    12b1 <dayOfWeek+0x1b1>
cmpl   $0x2,-0xc(%rbp)
jne    117e <dayOfWeek+0x7e>
cmpl   $0x1,-0x8(%rbp)
jne    117e <dayOfWeek+0x7e>
movl   $0x1d,-0x18(%rbp)
jmp    12ac <dayOfWeek+0x1ac>
cmpl   $0x2,-0xc(%rbp)
jne    119e <dayOfWeek+0x9e>
cmpl   $0x0,-0x8(%rbp)
jne    119e <dayOfWeek+0x9e>
movl   $0x1c,-0x18(%rbp)
jmp    12a7 <dayOfWeek+0x1a7>
cmpl   $0x3,-0xc(%rbp)
jne    11b4 <dayOfWeek+0xb4>
movl   $0x7,-0x18(%rbp)
jmp    12a2 <dayOfWeek+0x1a2>
cmpl   $0x4,-0xc(%rbp)
jne    11ca <dayOfWeek+0xca>
movl   $0x4,-0x18(%rbp)
jmp    129d <dayOfWeek+0x19d>
cmpl   $0x5,-0xc(%rbp)
jne    11e0 <dayOfWeek+0xe0>
movl   $0x2,-0x18(%rbp)
jmp    1298 <dayOfWeek+0x198>
cmpl   $0x6,-0xc(%rbp)
jne    11f6 <dayOfWeek+0xf6>
movl   $0x6,-0x18(%rbp)
jmp    1293 <dayOfWeek+0x193>
cmpl   $0x7,-0xc(%rbp)
jne    120c <dayOfWeek+0x10c>
movl   $0x4,-0x18(%rbp)
jmp    128e <dayOfWeek+0x18e>
cmpl   $0x8,-0xc(%rbp)
jne    1222 <dayOfWeek+0x122>
movl   $0x8,-0x18(%rbp)
jmp    1289 <dayOfWeek+0x189>
cmpl   $0x9,-0xc(%rbp)
jne    1238 <dayOfWeek+0x138>
movl   $0x5,-0x18(%rbp)
jmp    1284 <dayOfWeek+0x184>
cmpl   $0xa,-0xc(%rbp)
jne    124e <dayOfWeek+0x14e>
movl   $0x3,-0x18(%rbp)
jmp    127f <dayOfWeek+0x17f>
cmpl   $0xb,-0xc(%rbp)
jne    1264 <dayOfWeek+0x164>
movl   $0x7,-0x18(%rbp)
jmp    127a <dayOfWeek+0x17a>
cmpl   $0xc,-0xc(%rbp)
jne    1275 <dayOfWeek+0x175>
movl   $0x5,-0x18(%rbp)
jmp    127a <dayOfWeek+0x17a>
jmp    127f <dayOfWeek+0x17f>
jmp    1284 <dayOfWeek+0x184>
jmp    1289 <dayOfWeek+0x189>
jmp    128e <dayOfWeek+0x18e>
jmp    1293 <dayOfWeek+0x193>
jmp    1298 <dayOfWeek+0x198>
jmp    129d <dayOfWeek+0x19d>
jmp    12a2 <dayOfWeek+0x1a2>
jmp    12a7 <dayOfWeek+0x1a7>
jmp    12ac <dayOfWeek+0x1ac>
jmp    12b1 <dayOfWeek+0x1b1>
jmp    12b6 <dayOfWeek+0x1b6>
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    12e6 <dayOfWeek+0x1e6>
mov    -0x4(%rbp),%eax
mov    -0x18(%rbp),%ecx
sub    -0x10(%rbp),%ecx
sub    %ecx,%eax
add    $0x2a,%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
jmp    1310 <dayOfWeek+0x210>
mov    -0x10(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    130b <dayOfWeek+0x20b>
mov    -0x4(%rbp),%eax
mov    -0x10(%rbp),%ecx
sub    -0x18(%rbp),%ecx
add    %ecx,%eax
add    $0x2a,%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
jmp    1310 <dayOfWeek+0x210>
mov    -0x14(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<dayOfWeek>:
mov    %edi,%eax
cmp    $0x1,%esi
jne    1111 <dayOfWeek+0x11>
mov    $0x4,%edi
cmp    $0x1,%edx
je     1153 <dayOfWeek+0x53>
test   %esi,%esi
jne    111f <dayOfWeek+0x1f>
mov    $0x3,%edi
cmp    $0x1,%edx
je     1153 <dayOfWeek+0x53>
cmp    $0x1,%esi
jne    112e <dayOfWeek+0x2e>
mov    $0x1d,%edi
cmp    $0x2,%edx
je     1153 <dayOfWeek+0x53>
test   %esi,%esi
jne    113c <dayOfWeek+0x3c>
mov    $0x1c,%edi
cmp    $0x2,%edx
je     1153 <dayOfWeek+0x53>
add    $0xfffffffd,%edx
xor    %edi,%edi
cmp    $0x9,%edx
ja     1153 <dayOfWeek+0x53>
movslq %edx,%rdx
lea    0xeb0(%rip),%rsi
mov    (%rsi,%rdx,4),%edi
cmp    %ecx,%edi
jg     1159 <dayOfWeek+0x59>
jge    118d <dayOfWeek+0x8d>
add    %ecx,%eax
sub    %edi,%eax
mov    %eax,%ecx
add    $0x2a,%ecx
movslq %ecx,%rcx
imul   $0xffffffff92492493,%rcx,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
add    $0x2a,%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    $0x2a,%eax
ret

LLVM IR (-O0):
define i32 @dayOfWeek(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
%11 = load i32, i32* %7
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %17
13: ; preds = %4
%14 = load i32, i32* %6
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %17
16: ; preds = %13
store i32 4, i32* %10
br label %91
17: ; preds = %13, %4
%18 = load i32, i32* %7
%19 = icmp eq i32 %18, 1
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = load i32, i32* %6
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %20
store i32 3, i32* %10
br label %90
24: ; preds = %20, %17
%25 = load i32, i32* %7
%26 = icmp eq i32 %25, 2
br i1 %26, label %27, label %31
27: ; preds = %24
%28 = load i32, i32* %6
%29 = icmp eq i32 %28, 1
br i1 %29, label %30, label %31
30: ; preds = %27
store i32 29, i32* %10
br label %89
31: ; preds = %27, %24
%32 = load i32, i32* %7
%33 = icmp eq i32 %32, 2
br i1 %33, label %34, label %38
34: ; preds = %31
%35 = load i32, i32* %6
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %34
store i32 28, i32* %10
br label %88
38: ; preds = %34, %31
%39 = load i32, i32* %7
%40 = icmp eq i32 %39, 3
br i1 %40, label %41, label %42
41: ; preds = %38
store i32 7, i32* %10
br label %87
42: ; preds = %38
%43 = load i32, i32* %7
%44 = icmp eq i32 %43, 4
br i1 %44, label %45, label %46
45: ; preds = %42
store i32 4, i32* %10
br label %86
46: ; preds = %42
%47 = load i32, i32* %7
%48 = icmp eq i32 %47, 5
br i1 %48, label %49, label %50
49: ; preds = %46
store i32 2, i32* %10
br label %85
50: ; preds = %46
%51 = load i32, i32* %7
%52 = icmp eq i32 %51, 6
br i1 %52, label %53, label %54
53: ; preds = %50
store i32 6, i32* %10
br label %84
54: ; preds = %50
%55 = load i32, i32* %7
%56 = icmp eq i32 %55, 7
br i1 %56, label %57, label %58
57: ; preds = %54
store i32 4, i32* %10
br label %83
58: ; preds = %54
%59 = load i32, i32* %7
%60 = icmp eq i32 %59, 8
br i1 %60, label %61, label %62
61: ; preds = %58
store i32 8, i32* %10
br label %82
62: ; preds = %58
%63 = load i32, i32* %7
%64 = icmp eq i32 %63, 9
br i1 %64, label %65, label %66
65: ; preds = %62
store i32 5, i32* %10
br label %81
66: ; preds = %62
%67 = load i32, i32* %7
%68 = icmp eq i32 %67, 10
br i1 %68, label %69, label %70
69: ; preds = %66
store i32 3, i32* %10
br label %80
70: ; preds = %66
%71 = load i32, i32* %7
%72 = icmp eq i32 %71, 11
br i1 %72, label %73, label %74
73: ; preds = %70
store i32 7, i32* %10
br label %79
74: ; preds = %70
%75 = load i32, i32* %7
%76 = icmp eq i32 %75, 12
br i1 %76, label %77, label %78
77: ; preds = %74
store i32 5, i32* %10
br label %78
78: ; preds = %77, %74
br label %79
79: ; preds = %78, %73
br label %80
80: ; preds = %79, %69
br label %81
81: ; preds = %80, %65
br label %82
82: ; preds = %81, %61
br label %83
83: ; preds = %82, %57
br label %84
84: ; preds = %83, %53
br label %85
85: ; preds = %84, %49
br label %86
86: ; preds = %85, %45
br label %87
87: ; preds = %86, %41
br label %88
88: ; preds = %87, %37
br label %89
89: ; preds = %88, %30
br label %90
90: ; preds = %89, %23
br label %91
91: ; preds = %90, %16
%92 = load i32, i32* %5
store i32 %92, i32* %9
%93 = load i32, i32* %8
%94 = load i32, i32* %10
%95 = icmp slt i32 %93, %94
br i1 %95, label %96, label %104
96: ; preds = %91
%97 = load i32, i32* %5
%98 = load i32, i32* %10
%99 = load i32, i32* %8
%100 = sub nsw i32 %98, %99
%101 = sub nsw i32 %97, %100
%102 = add nsw i32 %101, 42
%103 = srem i32 %102, 7
store i32 %103, i32* %9
br label %117
104: ; preds = %91
%105 = load i32, i32* %8
%106 = load i32, i32* %10
%107 = icmp sgt i32 %105, %106
br i1 %107, label %108, label %116
108: ; preds = %104
%109 = load i32, i32* %5
%110 = load i32, i32* %8
%111 = load i32, i32* %10
%112 = sub nsw i32 %110, %111
%113 = add nsw i32 %109, %112
%114 = add nsw i32 %113, 42
%115 = srem i32 %114, 7
store i32 %115, i32* %9
br label %116
116: ; preds = %108, %104
br label %117
117: ; preds = %116, %96
%118 = load i32, i32* %9
ret i32 %118
}

LLVM IR (-O2):
@switch.table.dayOfWeek = [10 x i32] [i32 7, i32 4, i32 2, i32 6, i32 4, i32 8, i32 5, i32 3, i32 7, i32 5]
define i32 @dayOfWeek(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = icmp eq i32 %2, 1
%6 = icmp eq i32 %1, 1
%7 = and i1 %6, %5
br i1 %7, label %23, label %8
8: ; preds = %4
%9 = icmp eq i32 %1, 0
%10 = and i1 %9, %5
br i1 %10, label %23, label %11
11: ; preds = %8
%12 = icmp eq i32 %2, 2
%13 = and i1 %6, %12
br i1 %13, label %23, label %14
14: ; preds = %11
%15 = and i1 %9, %12
br i1 %15, label %23, label %16
16: ; preds = %14
%17 = add i32 %2, -3
%18 = icmp ult i32 %17, 10
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = sext i32 %17 to i64
%21 = getelementptr inbounds [10 x i32], [10 x i32]* @switch.table.dayOfWeek, i64 0, i64 %20
%22 = load i32, i32* %21
br label %23
23: ; preds = %16, %19, %14, %11, %8, %4
%24 = phi i32 [ 4, %4 ], [ 3, %8 ], [ 29, %11 ], [ 28, %14 ], [ %22, %19 ], [ 0, %16 ]
%25 = icmp sgt i32 %24, %3
br i1 %25, label %26, label %31
26: ; preds = %23
%27 = add i32 %0, 42
%28 = add i32 %27, %3
%29 = sub i32 %28, %24
%30 = srem i32 %29, 7
br label %38
31: ; preds = %23
%32 = icmp slt i32 %24, %3
br i1 %32, label %33, label %38
33: ; preds = %31
%34 = add i32 %0, 42
%35 = add i32 %34, %3
%36 = sub i32 %35, %24
%37 = srem i32 %36, 7
br label %38
38: ; preds = %31, %33, %26
%39 = phi i32 [ %30, %26 ], [ %37, %33 ], [ %0, %31 ]
ret i32 %39
}