#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);
double find_next(double JD, double jd1, double jd2, double jd3) {
  if (isnan(jd1) && isnan(jd2))
    return jd3;
  if (JD < jd1)
    return jd1;
  if (JD < jd2)
    return jd2;
  return jd3;
}


x86 assembly (clang, -O0):
<find_next>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  %xmm3,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1030 <isnan@plt>
cmp    $0x0,%rax
je     1163 <find_next+0x53>
movsd  -0x20(%rbp),%xmm0
call   1030 <isnan@plt>
cmp    $0x0,%rax
je     1163 <find_next+0x53>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11b3 <find_next+0xa3>
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1186 <find_next+0x76>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11b3 <find_next+0xa3>
movsd  -0x10(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11a9 <find_next+0x99>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11b3 <find_next+0xa3>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_next>:
sub    $0x48,%rsp
movaps %xmm3,0x10(%rsp)
movaps %xmm2,0x20(%rsp)
movaps %xmm0,0x30(%rsp)
movsd  %xmm1,0x8(%rsp)
movaps %xmm1,%xmm0
call   1030 <isnan@plt>
test   %rax,%rax
je     114f <find_next+0x3f>
movaps 0x20(%rsp),%xmm0
call   1030 <isnan@plt>
test   %rax,%rax
je     114f <find_next+0x3f>
movaps 0x10(%rsp),%xmm0
add    $0x48,%rsp
ret
movapd 0x20(%rsp),%xmm1
movapd 0x30(%rsp),%xmm2
movsd  0x8(%rsp),%xmm0
ucomisd %xmm2,%xmm0
ja     117e <find_next+0x6e>
cmpltsd %xmm1,%xmm2
andpd  %xmm2,%xmm1
andnpd 0x10(%rsp),%xmm2
orpd   %xmm1,%xmm2
movapd %xmm2,%xmm0
add    $0x48,%rsp
ret

LLVM IR (-O0):
define double @find_next(double %0, double %1, double %2, double %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
store double %0, double* %6
store double %1, double* %7
store double %2, double* %8
store double %3, double* %9
%10 = load double, double* %7
%11 = call i64 @isnan(double %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %4
%14 = load double, double* %8
%15 = call i64 @isnan(double %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = load double, double* %9
store double %18, double* %5
br label %33
19: ; preds = %13, %4
%20 = load double, double* %6
%21 = load double, double* %7
%22 = fcmp olt double %20, %21
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = load double, double* %7
store double %24, double* %5
br label %33
25: ; preds = %19
%26 = load double, double* %6
%27 = load double, double* %8
%28 = fcmp olt double %26, %27
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = load double, double* %8
store double %30, double* %5
br label %33
31: ; preds = %25
%32 = load double, double* %9
store double %32, double* %5
br label %33
33: ; preds = %31, %29, %23, %17
%34 = load double, double* %5
ret double %34
}

LLVM IR (-O2):
define double @find_next(double %0, double %1, double %2, double %3) {
%5 = tail call i64 @isnan(double %1)
%6 = icmp eq i64 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %4
%8 = tail call i64 @isnan(double %2)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %7, %4
%11 = fcmp olt double %0, %1
br i1 %11, label %15, label %12
12: ; preds = %10
%13 = fcmp olt double %0, %2
%14 = select i1 %13, double %2, double %3
br label %15
15: ; preds = %12, %10, %7
%16 = phi double [ %3, %7 ], [ %1, %10 ], [ %14, %12 ]
ret double %16
}