#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 */
scalar_t__ floor(double);
int mjd_dow(double mj, int *dow) {
  if (mj < -53798.5) {
    return (-1);
  }
  *dow = ((long)floor(mj - .5) + 1) % 7;
  if (*dow < 0)
    *dow += 7;
  return (0);
}


x86 assembly (clang, -O0):
<mjd_dow>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
movsd  0xed7(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1140 <mjd_dow+0x30>
movl   $0xffffffff,-0x4(%rbp)
jmp    118b <mjd_dow+0x7b>
movsd  -0x10(%rbp),%xmm0
movsd  0xebb(%rip),%xmm1
subsd  %xmm1,%xmm0
call   1030 <floor@plt>
add    $0x1,%rax
mov    $0x7,%ecx
cqto
idiv   %rcx
mov    %edx,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
jge    1184 <mjd_dow+0x74>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x7,%ecx
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mjd_dow>:
push   %rbx
mov    $0xffffffff,%eax
movsd  0xee2(%rip),%xmm1
ucomisd %xmm0,%xmm1
ja     116f <mjd_dow+0x5f>
mov    %rdi,%rbx
addsd  0xed9(%rip),%xmm0
call   1030 <floor@plt>
mov    %rax,%rcx
add    $0x1,%rcx
movabs $0x4924924924924925,%rdx
92 24 49
mov    %rcx,%rax
imul   %rdx
mov    %rdx,%rax
shr    $0x3f,%rax
shr    %rdx
add    %eax,%edx
lea    0x0(,%rdx,8),%eax
sub    %eax,%edx
lea    (%rcx,%rdx,1),%eax
add    $0x7,%eax
add    %edx,%ecx
cmovns %ecx,%eax
mov    %eax,(%rbx)
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @mjd_dow(double %0, i32* %1) {
%3 = alloca i32
%4 = alloca double
%5 = alloca i32*
store double %0, double* %4
store i32* %1, i32** %5
%6 = load double, double* %4
%7 = fcmp olt double %6, -5.379850e+04
br i1 %7, label %8, label %9
8: ; preds = %2
store i32 -1, i32* %3
br label %25
9: ; preds = %2
%10 = load double, double* %4
%11 = fsub double %10, 5.000000e-01
%12 = call i64 @floor(double %11)
%13 = add nsw i64 %12, 1
%14 = srem i64 %13, 7
%15 = trunc i64 %14 to i32
%16 = load i32*, i32** %5
store i32 %15, i32* %16
%17 = load i32*, i32** %5
%18 = load i32, i32* %17
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %9
%21 = load i32*, i32** %5
%22 = load i32, i32* %21
%23 = add nsw i32 %22, 7
store i32 %23, i32* %21
br label %24
24: ; preds = %20, %9
store i32 0, i32* %3
br label %25
25: ; preds = %24, %8
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
define i32 @mjd_dow(double %0, i32* nocapture writeonly %1) {
%3 = fcmp olt double %0, -5.379850e+04
br i1 %3, label %13, label %4
4: ; preds = %2
%5 = fadd double %0, -5.000000e-01
%6 = tail call i64 @floor(double %5)
%7 = add nsw i64 %6, 1
%8 = srem i64 %7, 7
%9 = trunc i64 %8 to i32
%10 = icmp slt i32 %9, 0
%11 = add nsw i32 %9, 7
%12 = select i1 %10, i32 %11, i32 %9
store i32 %12, i32* %1
br label %13
13: ; preds = %2, %4
%14 = phi i32 [ 0, %4 ], [ -1, %2 ]
ret i32 %14
}