#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 */
double fabs(double);
scalar_t__ isnan(double);
double fsign(double x, double y) {
  if (isnan(x) || isnan(y))
    return x + y;
  return ((y >= 0) ? fabs(x) : -fabs(x));
}


x86 assembly (clang, -O0):
<fsign>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <isnan@plt>
cmp    $0x0,%rax
jne    114a <fsign+0x3a>
movsd  -0x18(%rbp),%xmm0
call   1030 <isnan@plt>
cmp    $0x0,%rax
je     115e <fsign+0x4e>
movsd  -0x10(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11c0 <fsign+0xb0>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     118a <fsign+0x7a>
movsd  -0x10(%rbp),%xmm0
movaps 0xe84(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11b6 <fsign+0xa6>
movsd  -0x10(%rbp),%xmm0
movaps 0xe6a(%rip),%xmm1
pand   %xmm1,%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fsign>:
sub    $0x28,%rsp
movsd  %xmm1,0x8(%rsp)
movapd %xmm0,0x10(%rsp)
call   1030 <isnan@plt>
test   %rax,%rax
jne    113a <fsign+0x2a>
movsd  0x8(%rsp),%xmm0
call   1030 <isnan@plt>
test   %rax,%rax
je     114b <fsign+0x3b>
movapd 0x10(%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
add    $0x28,%rsp
ret
xorpd  %xmm0,%xmm0
movsd  0x8(%rsp),%xmm1
ucomisd %xmm0,%xmm1
movaps 0x10(%rsp),%xmm0
andps  0xe9b(%rip),%xmm0
jae    116e <fsign+0x5e>
xorps  0xea2(%rip),%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
define double @fsign(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 = call i64 @isnan(double %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %2
%10 = load double, double* %5
%11 = call i64 @isnan(double %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %9, %2
%14 = load double, double* %4
%15 = load double, double* %5
%16 = fadd double %14, %15
store double %16, double* %3
br label %29
17: ; preds = %9
%18 = load double, double* %5
%19 = fcmp oge double %18, 0.000000e+00
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load double, double* %4
%22 = call double @llvm.fabs.f64(double %21)
br label %27
23: ; preds = %17
%24 = load double, double* %4
%25 = call double @llvm.fabs.f64(double %24)
%26 = fneg double %25
br label %27
27: ; preds = %23, %20
%28 = phi double [ %22, %20 ], [ %26, %23 ]
store double %28, double* %3
br label %29
29: ; preds = %27, %13
%30 = load double, double* %3
ret double %30
}

LLVM IR (-O2):
define double @fsign(double %0, double %1) {
%3 = tail call i64 @isnan(double %0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i64 @isnan(double %1)
%7 = icmp eq i64 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %5, %2
%9 = fadd double %0, %1
br label %15
10: ; preds = %5
%11 = fcmp ult double %1, 0.000000e+00
%12 = tail call double @llvm.fabs.f64(double %0)
br i1 %11, label %13, label %15
13: ; preds = %10
%14 = fneg double %12
br label %15
15: ; preds = %10, %13, %8
%16 = phi double [ %9, %8 ], [ %14, %13 ], [ %12, %10 ]
ret double %16
}