#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 */
float NAN;
scalar_t__ isnan(long double const);
float sgn(long double const x) {
  return isnan(x) ? NAN : ((x > 0) ? 1.0 : ((x < 0) ? -1.0 : 0.0));
}


x86 assembly (clang, -O0):
<sgn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
fldt   0x10(%rbp)
fstpt  -0x10(%rbp)
fldt   -0x10(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
call   1030 <isnan@plt>
cmp    $0x0,%rax
je     114e <sgn+0x3e>
mov    0x2ebc(%rip),%rax
movss  (%rax),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11ba <sgn+0xaa>
fldt   -0x10(%rbp)
fldz
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jbe    1176 <sgn+0x66>
jmp    1164 <sgn+0x54>
movsd  0xe9c(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11b0 <sgn+0xa0>
xor    %eax,%eax
fldt   -0x10(%rbp)
fldz
fucomip %st(1),%st
fstp   %st(0)
movsd  0xe77(%rip),%xmm0
xorps  %xmm1,%xmm1
movsd  %xmm1,-0x30(%rbp)
movsd  %xmm0,-0x28(%rbp)
ja     11a6 <sgn+0x96>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sgn>:
sub    $0x28,%rsp
fldt   0x30(%rsp)
fld    %st(0)
fstpt  0x1c(%rsp)
fstpt  (%rsp)
call   1030 <isnan@plt>
test   %rax,%rax
je     113c <sgn+0x2c>
mov    0x2ec6(%rip),%rax
movss  (%rax),%xmm0
cvtss2sd %xmm0,%xmm0
jmp    1169 <sgn+0x59>
fldz
fldt   0x1c(%rsp)
fucomi %st(1),%st
jbe    1154 <sgn+0x44>
fstp   %st(1)
fstp   %st(0)
movsd  0xeae(%rip),%xmm0
jmp    1169 <sgn+0x59>
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
ja     1161 <sgn+0x51>
xorps  %xmm0,%xmm0
jmp    1169 <sgn+0x59>
movsd  0xe9f(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
@NAN = global float 0.000000e+00
define float @sgn(x86_fp80 %0) {
%2 = alloca x86_fp80
store x86_fp80 %0, x86_fp80* %2
%3 = load x86_fp80, x86_fp80* %2
%4 = call i64 @isnan(x86_fp80 %3)
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = load float, float* @NAN
%8 = fpext float %7 to double
br label %20
9: ; preds = %1
%10 = load x86_fp80, x86_fp80* %2
%11 = fcmp ogt x86_fp80 %10, 0xK00000000000000000000
br i1 %11, label %12, label %13
12: ; preds = %9
br label %18
13: ; preds = %9
%14 = load x86_fp80, x86_fp80* %2
%15 = fcmp olt x86_fp80 %14, 0xK00000000000000000000
%16 = zext i1 %15 to i64
%17 = select i1 %15, double -1.000000e+00, double 0.000000e+00
br label %18
18: ; preds = %13, %12
%19 = phi double [ 1.000000e+00, %12 ], [ %17, %13 ]
br label %20
20: ; preds = %18, %6
%21 = phi double [ %8, %6 ], [ %19, %18 ]
%22 = fptrunc double %21 to float
ret float %22
}

LLVM IR (-O2):
@NAN = global float 0.000000e+00
define float @sgn(x86_fp80 %0) {
%2 = tail call i64 @isnan(x86_fp80 %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %7, label %4
4: ; preds = %1
%5 = load float, float* @NAN
%6 = fpext float %5 to double
br label %12
7: ; preds = %1
%8 = fcmp ogt x86_fp80 %0, 0xK00000000000000000000
br i1 %8, label %12, label %9
9: ; preds = %7
%10 = fcmp olt x86_fp80 %0, 0xK00000000000000000000
%11 = select i1 %10, double -1.000000e+00, double 0.000000e+00
br label %12
12: ; preds = %9, %7, %4
%13 = phi double [ %6, %4 ], [ %11, %9 ], [ 1.000000e+00, %7 ]
%14 = fptrunc double %13 to float
ret float %14
}