#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 /*<<< orphan*/ assert(int /*<<< orphan*/);
scalar_t__ is_valid_date(long);
int /*<<< orphan*/ long_to_date(long, int *, int *, int *);
int /*<<< orphan*/ printf(char *, long);
int get_day_of_week(long l) {
  if (is_valid_date(l)) {
    int y, m, d;
    long_to_date(l, &y, &m, &d);
    if (m < 3) {
      m += 12;
      y -= 1;
    }
    return (d + 2 * m + (int)(6 * (m + 1) / 10) + y + (int)(y / 4) -
            (int)(y / 100) + (int)(y / 400) + 1) %
           7;
  }
  printf("Invalid date: %ld\n", l);
  assert(0);
  return -1;
}


x86 assembly (clang, -O0):
<get_day_of_week>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <is_valid_date@plt>
cmp    $0x0,%rax
je     120b <get_day_of_week+0xcb>
mov    -0x10(%rbp),%rdi
lea    -0x14(%rbp),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x1c(%rbp),%rcx
call   1060 <long_to_date@plt>
cmpl   $0x3,-0x18(%rbp)
jge    1190 <get_day_of_week+0x50>
mov    -0x18(%rbp),%eax
add    $0xc,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x18(%rbp),%ecx
shl    $0x1,%ecx
add    %ecx,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
imul   $0x6,%eax,%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
add    %ecx,%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x190,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
mov    %edx,-0x4(%rbp)
jmp    1229 <get_day_of_week+0xe9>
mov    -0x10(%rbp),%rsi
lea    0xdea(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <assert@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_day_of_week>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
call   1040 <is_valid_date@plt>
test   %rax,%rax
je     1230 <get_day_of_week+0xf0>
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
lea    0x4(%rsp),%rcx
mov    %rbx,%rdi
call   1060 <long_to_date@plt>
mov    0x8(%rsp),%eax
lea    0xc(%rax),%ecx
xor    %edx,%edx
cmp    $0x3,%eax
setl   %dl
mov    0xc(%rsp),%esi
cmovge %eax,%ecx
mov    %esi,%edi
sub    %edx,%edi
lea    (%rcx,%rcx,2),%eax
mov    %ecx,%r8d
add    %ecx,%r8d
add    %eax,%eax
add    $0x6,%eax
cltq
imul   $0x66666667,%rax,%rax
mov    %rax,%rbx
shr    $0x3f,%rbx
shr    $0x20,%rax
sar    $0x2,%eax
add    %ebx,%eax
neg    %edx
add    %edx,%esi
add    $0x3,%esi
test   %edi,%edi
cmovns %edi,%esi
sar    $0x2,%esi
movslq %edi,%rdx
imul   $0xffffffffae147ae1,%rdx,%rdi
mov    %rdi,%rbx
shr    $0x3f,%rbx
shr    $0x20,%rdi
sar    $0x5,%edi
add    %ebx,%edi
imul   $0x51eb851f,%rdx,%rbx
mov    %rbx,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rbx
sar    $0x7,%ebx
add    %ecx,%ebx
add    0x4(%rsp),%r8d
add    %r8d,%edx
add    %esi,%edx
add    %edi,%edx
add    %ebx,%edx
lea    (%rdx,%rax,1),%ecx
add    %edx,%eax
add    $0x1,%eax
cltq
imul   $0xffffffff92492493,%rax,%rax
shr    $0x20,%rax
add    %ecx,%eax
add    $0x1,%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    $0x1,%eax
jmp    124b <get_day_of_week+0x10b>
lea    0xdc9(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <assert@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Invalid date: %ld\0A\00"
define i32 @get_day_of_week(i64 %0) {
%2 = alloca i32
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i64 %0, i64* %3
%7 = load i64, i64* %3
%8 = call i64 @is_valid_date(i64 %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %43
10: ; preds = %1
%11 = load i64, i64* %3
%12 = call i32 @long_to_date(i64 %11, i32* %4, i32* %5, i32* %6)
%13 = load i32, i32* %5
%14 = icmp slt i32 %13, 3
br i1 %14, label %15, label %20
15: ; preds = %10
%16 = load i32, i32* %5
%17 = add nsw i32 %16, 12
store i32 %17, i32* %5
%18 = load i32, i32* %4
%19 = sub nsw i32 %18, 1
store i32 %19, i32* %4
br label %20
20: ; preds = %15, %10
%21 = load i32, i32* %6
%22 = load i32, i32* %5
%23 = mul nsw i32 2, %22
%24 = add nsw i32 %21, %23
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 1
%27 = mul nsw i32 6, %26
%28 = sdiv i32 %27, 10
%29 = add nsw i32 %24, %28
%30 = load i32, i32* %4
%31 = add nsw i32 %29, %30
%32 = load i32, i32* %4
%33 = sdiv i32 %32, 4
%34 = add nsw i32 %31, %33
%35 = load i32, i32* %4
%36 = sdiv i32 %35, 100
%37 = sub nsw i32 %34, %36
%38 = load i32, i32* %4
%39 = sdiv i32 %38, 400
%40 = add nsw i32 %37, %39
%41 = add nsw i32 %40, 1
%42 = srem i32 %41, 7
store i32 %42, i32* %2
br label %47
43: ; preds = %1
%44 = load i64, i64* %3
%45 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i64 %44)
%46 = call i32 @assert(i32 0)
store i32 -1, i32* %2
br label %47
47: ; preds = %43, %20
%48 = load i32, i32* %2
ret i32 %48
}

LLVM IR (-O2):
@.str = [19 x i8] c"Invalid date: %ld\0A\00"
define i32 @get_day_of_week(i64 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = tail call i64 @is_valid_date(i64 %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %35, label %7
7: ; preds = %1
%8 = bitcast i32* %2 to i8*
%9 = bitcast i32* %3 to i8*
%10 = bitcast i32* %4 to i8*
%11 = call i32 @long_to_date(i64 %0, i32* %2, i32* %3, i32* %4)
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 3
%14 = add nsw i32 %12, 12
%15 = load i32, i32* %2
%16 = sext i1 %13 to i32
%17 = add nsw i32 %15, %16
%18 = select i1 %13, i32 %14, i32 %12
%19 = load i32, i32* %4
%20 = shl nsw i32 %18, 1
%21 = mul i32 %18, 6
%22 = add i32 %21, 6
%23 = sdiv i32 %22, 10
%24 = sdiv i32 %17, 4
%25 = sdiv i32 %17, -100
%26 = sdiv i32 %17, 400
%27 = add i32 %19, 1
%28 = add i32 %27, %20
%29 = add i32 %28, %17
%30 = add i32 %29, %24
%31 = add i32 %30, %25
%32 = add i32 %31, %26
%33 = add i32 %32, %23
%34 = srem i32 %33, 7
br label %38
35: ; preds = %1
%36 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i64 %0)
%37 = tail call i32 @assert(i32 0)
br label %38
38: ; preds = %35, %7
%39 = phi i32 [ %34, %7 ], [ -1, %35 ]
ret i32 %39
}