#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 */
int /*<<< orphan*/ ERANGE;
int FP_INFINITE;
int FP_NAN;
int /*<<< orphan*/ __set_errno(int /*<<< orphan*/);
int fpclassify(double);
double __fdim(double x, double y) {
  int clsx = fpclassify(x);
  int clsy = fpclassify(y);
  if (clsx == FP_NAN || clsy == FP_NAN)
    return x - y;
  if (x <= y)
    return 0.0;
  double r = x - y;
  if (fpclassify(r) == FP_INFINITE && clsx != FP_INFINITE &&
      clsy != FP_INFINITE)
    __set_errno(ERANGE);
  return r;
}


x86 assembly (clang, -O0):
<__fdim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <fpclassify@plt>
mov    %eax,-0x1c(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1040 <fpclassify@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2e92(%rip),%rcx
cmp    (%rcx),%eax
je     1170 <__fdim+0x50>
mov    -0x20(%rbp),%eax
mov    0x2e80(%rip),%rcx
cmp    (%rcx),%eax
jne    1184 <__fdim+0x64>
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1209 <__fdim+0xe9>
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     11a5 <__fdim+0x85>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1209 <__fdim+0xe9>
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1040 <fpclassify@plt>
mov    0x2e1b(%rip),%rcx
cmp    (%rcx),%eax
jne    11ff <__fdim+0xdf>
mov    -0x1c(%rbp),%eax
mov    0x2e09(%rip),%rcx
cmp    (%rcx),%eax
je     11ff <__fdim+0xdf>
mov    -0x20(%rbp),%eax
mov    0x2df7(%rip),%rcx
cmp    (%rcx),%eax
je     11ff <__fdim+0xdf>
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__fdim>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
call   1040 <fpclassify@plt>
mov    %eax,%ebx
movsd  0x10(%rsp),%xmm0
call   1040 <fpclassify@plt>
mov    %eax,%ebp
mov    0x2e9b(%rip),%rax
mov    (%rax),%eax
cmp    %eax,%ebx
je     11ab <__fdim+0x8b>
cmp    %eax,%ebp
je     11ab <__fdim+0x8b>
xorpd  %xmm0,%xmm0
movsd  0x8(%rsp),%xmm1
movsd  0x10(%rsp),%xmm2
ucomisd %xmm1,%xmm2
jae    11b7 <__fdim+0x97>
subsd  %xmm2,%xmm1
movsd  %xmm1,0x8(%rsp)
movapd %xmm1,%xmm0
call   1040 <fpclassify@plt>
mov    0x2e59(%rip),%rcx
mov    (%rcx),%ecx
cmp    %ecx,%eax
jne    11a3 <__fdim+0x83>
cmp    %ecx,%ebx
je     11a3 <__fdim+0x83>
cmp    %ecx,%ebp
je     11a3 <__fdim+0x83>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
movsd  0x8(%rsp),%xmm0
jmp    11b7 <__fdim+0x97>
movsd  0x8(%rsp),%xmm0
subsd  0x10(%rsp),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@FP_NAN = global i32 0
@FP_INFINITE = global i32 0
@ERANGE = global i32 0
define double @__fdim(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
store double %0, double* %4
store double %1, double* %5
%9 = load double, double* %4
%10 = call i32 @fpclassify(double %9)
store i32 %10, i32* %6
%11 = load double, double* %5
%12 = call i32 @fpclassify(double %11)
store i32 %12, i32* %7
%13 = load i32, i32* %6
%14 = load i32, i32* @FP_NAN
%15 = icmp eq i32 %13, %14
br i1 %15, label %20, label %16
16: ; preds = %2
%17 = load i32, i32* %7
%18 = load i32, i32* @FP_NAN
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %24
20: ; preds = %16, %2
%21 = load double, double* %4
%22 = load double, double* %5
%23 = fsub double %21, %22
store double %23, double* %3
br label %50
24: ; preds = %16
%25 = load double, double* %4
%26 = load double, double* %5
%27 = fcmp ole double %25, %26
br i1 %27, label %28, label %29
28: ; preds = %24
store double 0.000000e+00, double* %3
br label %50
29: ; preds = %24
%30 = load double, double* %4
%31 = load double, double* %5
%32 = fsub double %30, %31
store double %32, double* %8
%33 = load double, double* %8
%34 = call i32 @fpclassify(double %33)
%35 = load i32, i32* @FP_INFINITE
%36 = icmp eq i32 %34, %35
br i1 %36, label %37, label %48
37: ; preds = %29
%38 = load i32, i32* %6
%39 = load i32, i32* @FP_INFINITE
%40 = icmp ne i32 %38, %39
br i1 %40, label %41, label %48
41: ; preds = %37
%42 = load i32, i32* %7
%43 = load i32, i32* @FP_INFINITE
%44 = icmp ne i32 %42, %43
br i1 %44, label %45, label %48
45: ; preds = %41
%46 = load i32, i32* @ERANGE
%47 = call i32 @__set_errno(i32 %46)
br label %48
48: ; preds = %45, %41, %37, %29
%49 = load double, double* %8
store double %49, double* %3
br label %50
50: ; preds = %48, %28, %20
%51 = load double, double* %3
ret double %51
}

LLVM IR (-O2):
@FP_NAN = global i32 0
@FP_INFINITE = global i32 0
@ERANGE = global i32 0
define double @__fdim(double %0, double %1) {
%3 = tail call i32 @fpclassify(double %0)
%4 = tail call i32 @fpclassify(double %1)
%5 = load i32, i32* @FP_NAN
%6 = icmp eq i32 %3, %5
%7 = icmp eq i32 %4, %5
%8 = select i1 %6, i1 true, i1 %7
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = fsub double %0, %1
br label %25
11: ; preds = %2
%12 = fcmp ugt double %0, %1
br i1 %12, label %13, label %25
13: ; preds = %11
%14 = fsub double %0, %1
%15 = tail call i32 @fpclassify(double %14)
%16 = load i32, i32* @FP_INFINITE
%17 = icmp ne i32 %15, %16
%18 = icmp eq i32 %3, %16
%19 = select i1 %17, i1 true, i1 %18
%20 = icmp eq i32 %4, %16
%21 = select i1 %19, i1 true, i1 %20
br i1 %21, label %25, label %22
22: ; preds = %13
%23 = load i32, i32* @ERANGE
%24 = tail call i32 @__set_errno(i32 %23)
br label %25
25: ; preds = %13, %22, %11, %9
%26 = phi double [ %10, %9 ], [ 0.000000e+00, %11 ], [ %14, %22 ], [ %14, %13 ]
ret double %26
}