#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__ copysignl(double, long double);
scalar_t__ isnan(long double);
int fpequal(long double d1, long double d2) {
  if (d1 != d2)
    return (isnan(d1) && isnan(d2));
  return (copysignl(1.0, d1) == copysignl(1.0, d2));
}


x86 assembly (clang, -O0):
<fpequal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
fldt   0x20(%rbp)
fldt   0x10(%rbp)
fstpt  -0x20(%rbp)
fstpt  -0x30(%rbp)
fldt   -0x20(%rbp)
fldt   -0x30(%rbp)
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jne    1151 <fpequal+0x31>
jp     1151 <fpequal+0x31>
jmp    1197 <fpequal+0x77>
fldt   -0x20(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
call   1040 <isnan@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x31(%rbp)
je     1187 <fpequal+0x67>
fldt   -0x30(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
call   1040 <isnan@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    11da <fpequal+0xba>
fldt   -0x20(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
movsd  0xe59(%rip),%xmm0
call   1030 <copysignl@plt>
mov    %rax,-0x40(%rbp)
fldt   -0x30(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
movsd  0xe40(%rip),%xmm0
call   1030 <copysignl@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fpequal>:
push   %rbx
sub    $0x20,%rsp
fldt   0x40(%rsp)
fldt   0x30(%rsp)
fucomi %st(1),%st
fxch   %st(1)
fstpt  0x14(%rsp)
jne    1139 <fpequal+0x19>
jnp    115a <fpequal+0x3a>
fstpt  (%rsp)
call   1040 <isnan@plt>
test   %rax,%rax
je     1189 <fpequal+0x69>
fldt   0x14(%rsp)
fstpt  (%rsp)
call   1040 <isnan@plt>
test   %rax,%rax
setne  %al
jmp    118b <fpequal+0x6b>
fstpt  (%rsp)
movsd  0xe9b(%rip),%xmm0
call   1030 <copysignl@plt>
mov    %rax,%rbx
fldt   0x14(%rsp)
fstpt  (%rsp)
movsd  0xe84(%rip),%xmm0
call   1030 <copysignl@plt>
cmp    %rax,%rbx
sete   %al
jmp    118b <fpequal+0x6b>
xor    %eax,%eax
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @fpequal(x86_fp80 %0, x86_fp80 %1) {
%3 = alloca i32
%4 = alloca x86_fp80
%5 = alloca x86_fp80
store x86_fp80 %0, x86_fp80* %4
store x86_fp80 %1, x86_fp80* %5
%6 = load x86_fp80, x86_fp80* %4
%7 = load x86_fp80, x86_fp80* %5
%8 = fcmp une x86_fp80 %6, %7
br i1 %8, label %9, label %20
9: ; preds = %2
%10 = load x86_fp80, x86_fp80* %4
%11 = call i64 @isnan(x86_fp80 %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %9
%14 = load x86_fp80, x86_fp80* %5
%15 = call i64 @isnan(x86_fp80 %14)
%16 = icmp ne i64 %15, 0
br label %17
17: ; preds = %13, %9
%18 = phi i1 [ false, %9 ], [ %16, %13 ]
%19 = zext i1 %18 to i32
store i32 %19, i32* %3
br label %27
20: ; preds = %2
%21 = load x86_fp80, x86_fp80* %4
%22 = call i64 @copysignl(double 1.000000e+00, x86_fp80 %21)
%23 = load x86_fp80, x86_fp80* %5
%24 = call i64 @copysignl(double 1.000000e+00, x86_fp80 %23)
%25 = icmp eq i64 %22, %24
%26 = zext i1 %25 to i32
store i32 %26, i32* %3
br label %27
27: ; preds = %20, %17
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
define i32 @fpequal(x86_fp80 %0, x86_fp80 %1) {
%3 = fcmp une x86_fp80 %0, %1
br i1 %3, label %4, label %10
4: ; preds = %2
%5 = tail call i64 @isnan(x86_fp80 %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %14, label %7
7: ; preds = %4
%8 = tail call i64 @isnan(x86_fp80 %1)
%9 = icmp ne i64 %8, 0
br label %14
10: ; preds = %2
%11 = tail call i64 @copysignl(double 1.000000e+00, x86_fp80 %0)
%12 = tail call i64 @copysignl(double 1.000000e+00, x86_fp80 %1)
%13 = icmp eq i64 %11, %12
br label %14
14: ; preds = %4, %7, %10
%15 = phi i1 [ %13, %10 ], [ false, %4 ], [ %9, %7 ]
%16 = zext i1 %15 to i32
ret i32 %16
}