#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 nexttoward(double x, long double y) {
  union {
    double d;
    unsigned long long ll;
  } u;
  long double xx = x;
  if (isnan(y) || isnan(x))
    return x + y;
  if (xx == y)
    return y;
  u.d = x;
  if (x == 0.0) {
    u.ll = 1;
    return y > 0.0L ? u.d : -u.d;
  }
  if (((x > 0.0) ^ (y > xx)) == 0)
    u.ll++;
  else
    u.ll--;
  return u.d;
}


x86 assembly (clang, -O0):
<nexttoward>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
fldt   0x10(%rbp)
movsd  %xmm0,-0x10(%rbp)
fstpt  -0x20(%rbp)
fldl   -0x10(%rbp)
fstpt  -0x40(%rbp)
fldt   -0x20(%rbp)
fstpl  -0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
call   1030 <isnan@plt>
cmp    $0x0,%rax
jne    1157 <nexttoward+0x47>
movsd  -0x10(%rbp),%xmm0
call   1030 <isnan@plt>
cmp    $0x0,%rax
je     1171 <nexttoward+0x61>
fldl   -0x10(%rbp)
fldt   -0x20(%rbp)
faddp  %st,%st(1)
fstpl  -0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    127b <nexttoward+0x16b>
fldt   -0x40(%rbp)
fldt   -0x20(%rbp)
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jne    11a3 <nexttoward+0x93>
jp     11a3 <nexttoward+0x93>
jmp    118e <nexttoward+0x7e>
fldt   -0x20(%rbp)
fstpl  -0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    127b <nexttoward+0x16b>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1222 <nexttoward+0x112>
jp     1222 <nexttoward+0x112>
movq   $0x1,-0x28(%rbp)
fldt   -0x20(%rbp)
fldz
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jbe    11f2 <nexttoward+0xe2>
jmp    11e3 <nexttoward+0xd3>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
jmp    1213 <nexttoward+0x103>
movsd  -0x28(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    127b <nexttoward+0x16b>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
seta   %al
movzbl %al,%eax
fldt   -0x20(%rbp)
fldt   -0x40(%rbp)
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
seta   %cl
and    $0x1,%cl
movzbl %cl,%ecx
xor    %ecx,%eax
cmp    $0x0,%eax
jne    1265 <nexttoward+0x155>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1271 <nexttoward+0x161>
mov    -0x28(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nexttoward>:
sub    $0x48,%rsp
fldt   0x50(%rsp)
movsd  %xmm0,0x8(%rsp)
movsd  %xmm0,0x40(%rsp)
fldl   0x40(%rsp)
fstpt  0x10(%rsp)
fld    %st(0)
fstpt  0x1c(%rsp)
fstpl  0x38(%rsp)
movsd  0x38(%rsp),%xmm0
movsd  %xmm0,0x28(%rsp)
call   1030 <isnan@plt>
test   %rax,%rax
jne    115c <nexttoward+0x4c>
movsd  0x8(%rsp),%xmm0
call   1030 <isnan@plt>
test   %rax,%rax
je     117f <nexttoward+0x6f>
fldt   0x1c(%rsp)
fldt   0x10(%rsp)
faddp  %st,%st(1)
fstpl  0x30(%rsp)
movq   0x30(%rsp),%xmm0
fldz
fldz
fxch   %st(1)
fstp   %st(0)
fstp   %st(0)
add    $0x48,%rsp
ret
movsd  0x8(%rsp),%xmm1
fldt   0x1c(%rsp)
fldt   0x10(%rsp)
fucomi %st(1),%st
movsd  0x28(%rsp),%xmm0
jne    1199 <nexttoward+0x89>
jnp    1176 <nexttoward+0x66>
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    11c2 <nexttoward+0xb2>
jp     11c2 <nexttoward+0xb2>
fstp   %st(0)
fldz
xor    %eax,%eax
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
seta   %al
lea    0xe45(%rip),%rcx
movq   (%rcx,%rax,8),%xmm0
jmp    1170 <nexttoward+0x60>
movapd %xmm1,%xmm0
setbe  %al
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
seta   %cl
xor    %al,%cl
movq   %xmm1,%rax
movzbl %cl,%ecx
lea    (%rax,%rcx,2),%rax
add    $0xffffffffffffffff,%rax
movq   %rax,%xmm0
jmp    1170 <nexttoward+0x60>

LLVM IR (-O0):
%union.anon = type { double }
define double @nexttoward(double %0, x86_fp80 %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca x86_fp80
%6 = alloca %union.anon
%7 = alloca x86_fp80
store double %0, double* %4
store x86_fp80 %1, x86_fp80* %5
%8 = load double, double* %4
%9 = fpext double %8 to x86_fp80
store x86_fp80 %9, x86_fp80* %7
%10 = load x86_fp80, x86_fp80* %5
%11 = fptrunc x86_fp80 %10 to double
%12 = call i64 @isnan(double %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %2
%15 = load double, double* %4
%16 = call i64 @isnan(double %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %14, %2
%19 = load double, double* %4
%20 = fpext double %19 to x86_fp80
%21 = load x86_fp80, x86_fp80* %5
%22 = fadd x86_fp80 %20, %21
%23 = fptrunc x86_fp80 %22 to double
store double %23, double* %3
br label %70
24: ; preds = %14
%25 = load x86_fp80, x86_fp80* %7
%26 = load x86_fp80, x86_fp80* %5
%27 = fcmp oeq x86_fp80 %25, %26
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = load x86_fp80, x86_fp80* %5
%30 = fptrunc x86_fp80 %29 to double
store double %30, double* %3
br label %70
31: ; preds = %24
%32 = load double, double* %4
%33 = bitcast %union.anon* %6 to double*
store double %32, double* %33
%34 = load double, double* %4
%35 = fcmp oeq double %34, 0.000000e+00
br i1 %35, label %36, label %49
36: ; preds = %31
%37 = bitcast %union.anon* %6 to i64*
store i64 1, i64* %37
%38 = load x86_fp80, x86_fp80* %5
%39 = fcmp ogt x86_fp80 %38, 0xK00000000000000000000
br i1 %39, label %40, label %43
40: ; preds = %36
%41 = bitcast %union.anon* %6 to double*
%42 = load double, double* %41
br label %47
43: ; preds = %36
%44 = bitcast %union.anon* %6 to double*
%45 = load double, double* %44
%46 = fneg double %45
br label %47
47: ; preds = %43, %40
%48 = phi double [ %42, %40 ], [ %46, %43 ]
store double %48, double* %3
br label %70
49: ; preds = %31
%50 = load double, double* %4
%51 = fcmp ogt double %50, 0.000000e+00
%52 = zext i1 %51 to i32
%53 = load x86_fp80, x86_fp80* %5
%54 = load x86_fp80, x86_fp80* %7
%55 = fcmp ogt x86_fp80 %53, %54
%56 = zext i1 %55 to i32
%57 = xor i32 %52, %56
%58 = icmp eq i32 %57, 0
br i1 %58, label %59, label %63
59: ; preds = %49
%60 = bitcast %union.anon* %6 to i64*
%61 = load i64, i64* %60
%62 = add i64 %61, 1
store i64 %62, i64* %60
br label %67
63: ; preds = %49
%64 = bitcast %union.anon* %6 to i64*
%65 = load i64, i64* %64
%66 = add i64 %65, -1
store i64 %66, i64* %64
br label %67
67: ; preds = %63, %59
%68 = bitcast %union.anon* %6 to double*
%69 = load double, double* %68
store double %69, double* %3
br label %70
70: ; preds = %67, %47, %28, %18
%71 = load double, double* %3
ret double %71
}

LLVM IR (-O2):
define double @nexttoward(double %0, x86_fp80 %1) {
%3 = fpext double %0 to x86_fp80
%4 = fptrunc x86_fp80 %1 to double
%5 = tail call i64 @isnan(double %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = tail call i64 @isnan(double %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %7, %2
%11 = fadd x86_fp80 %3, %1
%12 = fptrunc x86_fp80 %11 to double
br label %28
13: ; preds = %7
%14 = fcmp oeq x86_fp80 %3, %1
br i1 %14, label %28, label %15
15: ; preds = %13
%16 = fcmp oeq double %0, 0.000000e+00
br i1 %16, label %17, label %20
17: ; preds = %15
%18 = fcmp ogt x86_fp80 %1, 0xK00000000000000000000
%19 = select i1 %18, double 4.940660e-324, double -4.940660e-324
br label %28
20: ; preds = %15
%21 = fcmp ule double %0, 0.000000e+00
%22 = fcmp olt x86_fp80 %3, %1
%23 = xor i1 %21, %22
%24 = bitcast double %0 to i64
%25 = select i1 %23, i64 1, i64 -1
%26 = add i64 %25, %24
%27 = bitcast i64 %26 to double
br label %28
28: ; preds = %13, %20, %17, %10
%29 = phi double [ %12, %10 ], [ %19, %17 ], [ %27, %20 ], [ %4, %13 ]
ret double %29
}