#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__ isnan(double);
int /*<<< orphan*/ printf(char *);
double mod_double(double t, double period) {
  if (t >= period)
    return mod_double(t - period, period);
  if (t < 0)
    return mod_double(t + period, period);
  if (isnan(t)) {
    printf("IS NAN!!!\n");
    t = 0;
  }
  return t;
}


x86 assembly (clang, -O0):
<mod_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jb     1170 <mod_double+0x40>
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
call   1040 <mod_double@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    11ce <mod_double+0x9e>
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    119c <mod_double+0x6c>
movsd  -0x10(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
call   1040 <mod_double@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    11ce <mod_double+0x9e>
movsd  -0x10(%rbp),%xmm0
call   1050 <isnan@plt>
cmp    $0x0,%rax
je     11c4 <mod_double+0x94>
lea    0xe49(%rip),%rdi
call   1030 <printf@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mod_double>:
xorpd  %xmm2,%xmm2
ucomisd %xmm1,%xmm0
jb     113a <mod_double+0x1a>
nopw   0x0(%rax,%rax,1)
subsd  %xmm1,%xmm0
ucomisd %xmm1,%xmm0
jae    1130 <mod_double+0x10>
ucomisd %xmm0,%xmm2
jbe    114c <mod_double+0x2c>
addsd  %xmm1,%xmm0
ucomisd %xmm1,%xmm0
jae    1130 <mod_double+0x10>
jmp    113a <mod_double+0x1a>
push   %rax
movsd  %xmm0,(%rsp)
call   1040 <isnan@plt>
movsd  (%rsp),%xmm0
test   %rax,%rax
je     1170 <mod_double+0x50>
lea    0xe98(%rip),%rdi
call   1030 <puts@plt>
xorps  %xmm0,%xmm0
pop    %rax
ret

LLVM IR (-O0):
@.str = [11 x i8] c"IS NAN!!!\0A\00"
define double @mod_double(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
store double %0, double* %4
store double %1, double* %5
%6 = load double, double* %4
%7 = load double, double* %5
%8 = fcmp oge double %6, %7
br i1 %8, label %9, label %15
9: ; preds = %2
%10 = load double, double* %4
%11 = load double, double* %5
%12 = fsub double %10, %11
%13 = load double, double* %5
%14 = call double @mod_double(double %12, double %13)
store double %14, double* %3
br label %32
15: ; preds = %2
%16 = load double, double* %4
%17 = fcmp olt double %16, 0.000000e+00
br i1 %17, label %18, label %24
18: ; preds = %15
%19 = load double, double* %4
%20 = load double, double* %5
%21 = fadd double %19, %20
%22 = load double, double* %5
%23 = call double @mod_double(double %21, double %22)
store double %23, double* %3
br label %32
24: ; preds = %15
%25 = load double, double* %4
%26 = call i64 @isnan(double %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store double 0.000000e+00, double* %4
br label %30
30: ; preds = %28, %24
%31 = load double, double* %4
store double %31, double* %3
br label %32
32: ; preds = %30, %18, %9
%33 = load double, double* %3
ret double %33
}

LLVM IR (-O2):
@str = [10 x i8] c"IS NAN!!!\00"
define double @mod_double(double %0, double %1) {
br label %3
3: ; preds = %8, %2
%4 = phi double [ %0, %2 ], [ %9, %8 ]
%5 = fcmp ult double %4, %1
br i1 %5, label %10, label %6
6: ; preds = %3
%7 = fsub double %4, %1
br label %8
8: ; preds = %6, %12
%9 = phi double [ %7, %6 ], [ %13, %12 ]
br label %3
10: ; preds = %3
%11 = fcmp olt double %4, 0.000000e+00
br i1 %11, label %12, label %14
12: ; preds = %10
%13 = fadd double %4, %1
br label %8
14: ; preds = %10
%15 = tail call i64 @isnan(double %4)
%16 = icmp eq i64 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
br label %19
19: ; preds = %14, %17
%20 = phi double [ 0.000000e+00, %17 ], [ %4, %14 ]
ret double %20
}