#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int get_doomsday(unsigned int);
scalar_t__ leapyear(unsigned int);
int get_weekday(unsigned int day, unsigned int month, unsigned int year) {
  int doomsday = get_doomsday(year);
  int months_doomsday[] = {
      3, 28, 0, 4, 9, 6, 11, 8, 5, 10, 7, 12,
  };
  int weekday = (day - months_doomsday[month - 1] + doomsday);
  if (weekday < 0)
    weekday += 7;
  if (leapyear(year) && (month == 2 || month == 1))
    weekday++;
  weekday %= 7;
  return weekday;
}


x86 assembly (clang, -O0):
<get_weekday>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <get_doomsday@plt>
mov    %eax,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xea9(%rip),%rsi
mov    $0x30,%edx
call   1040 <memcpy@plt>
mov    -0x4(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
mov    %ecx,%ecx
sub    -0x40(%rbp,%rcx,4),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jge    1189 <get_weekday+0x59>
mov    -0x44(%rbp),%eax
add    $0x7,%eax
mov    %eax,-0x44(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <leapyear@plt>
cmp    $0x0,%rax
je     11b8 <get_weekday+0x88>
cmpl   $0x2,-0x8(%rbp)
je     11af <get_weekday+0x7f>
cmpl   $0x1,-0x8(%rbp)
jne    11b8 <get_weekday+0x88>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
mov    %edx,-0x44(%rbp)
mov    -0x44(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_weekday>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %esi,%ebx
mov    %edi,%ebp
mov    %edx,%edi
call   1030 <get_doomsday@plt>
add    $0xffffffff,%ebx
lea    0xec4(%rip),%rcx
sub    (%rcx,%rbx,4),%ebp
mov    %ebp,%ecx
add    %eax,%ecx
lea    0x7(%rbp,%rax,1),%ebp
cmovns %ecx,%ebp
mov    %r14d,%edi
call   1040 <leapyear@plt>
test   %rax,%rax
setne  %al
cmp    $0x2,%ebx
setb   %cl
and    %al,%cl
movzbl %cl,%eax
add    %ebp,%eax
movslq %eax,%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
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@__const.get_weekday.months_doomsday = [12 x i32] [i32 3, i32 28, i32 0, i32 4, i32 9, i32 6, i32 11, i32 8, i32 5, i32 10, i32 7, i32 12]
define i32 @get_weekday(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [12 x i32]
%9 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = load i32, i32* %6
%11 = call i32 @get_doomsday(i32 %10)
store i32 %11, i32* %7
%12 = bitcast [12 x i32]* %8 to i8*
%13 = load i32, i32* %4
%14 = load i32, i32* %5
%15 = sub i32 %14, 1
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds [12 x i32], [12 x i32]* %8, i64 0, i64 %16
%18 = load i32, i32* %17
%19 = sub i32 %13, %18
%20 = load i32, i32* %7
%21 = add i32 %19, %20
store i32 %21, i32* %9
%22 = load i32, i32* %9
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %3
%25 = load i32, i32* %9
%26 = add nsw i32 %25, 7
store i32 %26, i32* %9
br label %27
27: ; preds = %24, %3
%28 = load i32, i32* %6
%29 = call i64 @leapyear(i32 %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %40
31: ; preds = %27
%32 = load i32, i32* %5
%33 = icmp eq i32 %32, 2
br i1 %33, label %37, label %34
34: ; preds = %31
%35 = load i32, i32* %5
%36 = icmp eq i32 %35, 1
br i1 %36, label %37, label %40
37: ; preds = %34, %31
%38 = load i32, i32* %9
%39 = add nsw i32 %38, 1
store i32 %39, i32* %9
br label %40
40: ; preds = %37, %34, %27
%41 = load i32, i32* %9
%42 = srem i32 %41, 7
store i32 %42, i32* %9
%43 = load i32, i32* %9
ret i32 %43
}

LLVM IR (-O2):
@__const.get_weekday.months_doomsday = [12 x i32] [i32 3, i32 28, i32 0, i32 4, i32 9, i32 6, i32 11, i32 8, i32 5, i32 10, i32 7, i32 12]
define i32 @get_weekday(i32 %0, i32 %1, i32 %2) {
%4 = tail call i32 @get_doomsday(i32 %2)
%5 = add i32 %1, -1
%6 = zext i32 %5 to i64
%7 = getelementptr inbounds [12 x i32], [12 x i32]* @__const.get_weekday.months_doomsday, i64 0, i64 %6
%8 = load i32, i32* %7
%9 = sub i32 %0, %8
%10 = add i32 %9, %4
%11 = icmp slt i32 %10, 0
%12 = add nsw i32 %10, 7
%13 = select i1 %11, i32 %12, i32 %10
%14 = tail call i64 @leapyear(i32 %2)
%15 = icmp ne i64 %14, 0
%16 = icmp ult i32 %5, 2
%17 = and i1 %16, %15
%18 = zext i1 %17 to i32
%19 = add nsw i32 %13, %18
%20 = srem i32 %19, 7
ret i32 %20
}