#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 floor(double);
int fb_Weekday(double serial, int first_day_of_week) {
  int dow = ((int)(floor(serial) - 1) % 7) + 1;
  if (first_day_of_week == 0) {
    first_day_of_week = 1;
  }
  dow -= first_day_of_week - 1;
  if (dow < 1) {
    dow += 7;
  } else if (dow > 7) {
    dow -= 7;
  }
  return dow;
}


x86 assembly (clang, -O0):
<fb_Weekday>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1030 <floor@plt>
sub    $0x1,%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    114c <fb_Weekday+0x3c>
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
mov    -0x10(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x1,-0x10(%rbp)
jge    1172 <fb_Weekday+0x62>
mov    -0x10(%rbp),%eax
add    $0x7,%eax
mov    %eax,-0x10(%rbp)
jmp    118a <fb_Weekday+0x7a>
cmpl   $0x7,-0x10(%rbp)
jle    1185 <fb_Weekday+0x75>
mov    -0x10(%rbp),%eax
sub    $0x7,%eax
mov    %eax,-0x10(%rbp)
jmp    118a <fb_Weekday+0x7a>
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fb_Weekday>:
push   %rbx
mov    %edi,%ebx
call   1030 <floor@plt>
mov    %eax,%ecx
add    $0xffffffff,%ecx
movslq %ecx,%rcx
imul   $0xffffffff92492493,%rcx,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
add    $0xffffffff,%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    $0xffffffff,%eax
mov    $0x2,%ecx
sub    %ebx,%ecx
test   %ebx,%ebx
mov    $0x1,%edx
cmovne %ecx,%edx
lea    (%rdx,%rax,1),%ecx
cmp    $0x8,%ecx
lea    -0x7(%rdx,%rax,1),%esi
cmovl  %ecx,%esi
test   %ecx,%ecx
lea    0x7(%rdx,%rax,1),%eax
cmovg  %esi,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @fb_Weekday(double %0, i32 %1) {
%3 = alloca double
%4 = alloca i32
%5 = alloca i32
store double %0, double* %3
store i32 %1, i32* %4
%6 = load double, double* %3
%7 = call i32 @floor(double %6)
%8 = sub nsw i32 %7, 1
%9 = srem i32 %8, 7
%10 = add nsw i32 %9, 1
store i32 %10, i32* %5
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 1, i32* %4
br label %14
14: ; preds = %13, %2
%15 = load i32, i32* %4
%16 = sub nsw i32 %15, 1
%17 = load i32, i32* %5
%18 = sub nsw i32 %17, %16
store i32 %18, i32* %5
%19 = load i32, i32* %5
%20 = icmp slt i32 %19, 1
br i1 %20, label %21, label %24
21: ; preds = %14
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 7
store i32 %23, i32* %5
br label %31
24: ; preds = %14
%25 = load i32, i32* %5
%26 = icmp sgt i32 %25, 7
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = load i32, i32* %5
%29 = sub nsw i32 %28, 7
store i32 %29, i32* %5
br label %30
30: ; preds = %27, %24
br label %31
31: ; preds = %30, %21
%32 = load i32, i32* %5
ret i32 %32
}

LLVM IR (-O2):
define i32 @fb_Weekday(double %0, i32 %1) {
%3 = tail call i32 @floor(double %0)
%4 = add nsw i32 %3, -1
%5 = srem i32 %4, 7
%6 = icmp eq i32 %1, 0
%7 = sub i32 2, %1
%8 = select i1 %6, i32 1, i32 %7
%9 = add i32 %8, %5
%10 = icmp slt i32 %9, 1
%11 = add nsw i32 %9, 7
%12 = icmp sgt i32 %9, 7
%13 = add nsw i32 %9, -7
%14 = select i1 %12, i32 %13, i32 %9
%15 = select i1 %10, i32 %11, i32 %14
ret i32 %15
}