#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 FP_INFINITE;
int FP_NAN;
int fpclassify(double);
double __fdim(double x, double y) {
  int clsx = fpclassify(x);
  int clsy = fpclassify(y);
  if (clsx == FP_NAN || clsy == FP_NAN ||
      (y < 0 && clsx == FP_INFINITE && clsy == FP_INFINITE))
    return x - y;
  return x <= y ? 0 : x - y;
}


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   1030 <fpclassify@plt>
mov    %eax,-0x1c(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1030 <fpclassify@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2ea2(%rip),%rcx
cmp    (%rcx),%eax
je     1192 <__fdim+0x82>
mov    -0x20(%rbp),%eax
mov    0x2e90(%rip),%rcx
cmp    (%rcx),%eax
je     1192 <__fdim+0x82>
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    11a6 <__fdim+0x96>
mov    -0x1c(%rbp),%eax
mov    0x2e68(%rip),%rcx
cmp    (%rcx),%eax
jne    11a6 <__fdim+0x96>
mov    -0x20(%rbp),%eax
mov    0x2e56(%rip),%rcx
cmp    (%rcx),%eax
jne    11a6 <__fdim+0x96>
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11e0 <__fdim+0xd0>
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     11c7 <__fdim+0xb7>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    11d6 <__fdim+0xc6>
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__fdim>:
push   %rbx
sub    $0x20,%rsp
movsd  %xmm1,0x8(%rsp)
movaps %xmm0,0x10(%rsp)
call   1030 <fpclassify@plt>
mov    %eax,%ebx
movsd  0x8(%rsp),%xmm0
call   1030 <fpclassify@plt>
movsd  0x8(%rsp),%xmm2
mov    0x2ea9(%rip),%rcx
mov    (%rcx),%ecx
cmp    %ecx,%ebx
je     1164 <__fdim+0x54>
cmp    %ecx,%eax
je     1164 <__fdim+0x54>
xorpd  %xmm0,%xmm0
ucomisd %xmm2,%xmm0
jbe    1170 <__fdim+0x60>
mov    0x2e86(%rip),%rcx
mov    (%rcx),%ecx
cmp    %ecx,%ebx
jne    1170 <__fdim+0x60>
cmp    %ecx,%eax
jne    1170 <__fdim+0x60>
movapd 0x10(%rsp),%xmm0
subsd  %xmm2,%xmm0
jmp    1187 <__fdim+0x77>
movapd 0x10(%rsp),%xmm0
movapd %xmm0,%xmm1
subsd  %xmm2,%xmm1
cmplesd %xmm2,%xmm0
andnpd %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@FP_NAN = global i32 0
@FP_INFINITE = 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
store double %0, double* %4
store double %1, double* %5
%8 = load double, double* %4
%9 = call i32 @fpclassify(double %8)
store i32 %9, i32* %6
%10 = load double, double* %5
%11 = call i32 @fpclassify(double %10)
store i32 %11, i32* %7
%12 = load i32, i32* %6
%13 = load i32, i32* @FP_NAN
%14 = icmp eq i32 %12, %13
br i1 %14, label %30, label %15
15: ; preds = %2
%16 = load i32, i32* %7
%17 = load i32, i32* @FP_NAN
%18 = icmp eq i32 %16, %17
br i1 %18, label %30, label %19
19: ; preds = %15
%20 = load double, double* %5
%21 = fcmp olt double %20, 0.000000e+00
br i1 %21, label %22, label %34
22: ; preds = %19
%23 = load i32, i32* %6
%24 = load i32, i32* @FP_INFINITE
%25 = icmp eq i32 %23, %24
br i1 %25, label %26, label %34
26: ; preds = %22
%27 = load i32, i32* %7
%28 = load i32, i32* @FP_INFINITE
%29 = icmp eq i32 %27, %28
br i1 %29, label %30, label %34
30: ; preds = %26, %15, %2
%31 = load double, double* %4
%32 = load double, double* %5
%33 = fsub double %31, %32
store double %33, double* %3
br label %45
34: ; preds = %26, %22, %19
%35 = load double, double* %4
%36 = load double, double* %5
%37 = fcmp ole double %35, %36
br i1 %37, label %38, label %39
38: ; preds = %34
br label %43
39: ; preds = %34
%40 = load double, double* %4
%41 = load double, double* %5
%42 = fsub double %40, %41
br label %43
43: ; preds = %39, %38
%44 = phi double [ 0.000000e+00, %38 ], [ %42, %39 ]
store double %44, double* %3
br label %45
45: ; preds = %43, %30
%46 = load double, double* %3
ret double %46
}

LLVM IR (-O2):
@FP_NAN = global i32 0
@FP_INFINITE = 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 %16, label %9
9: ; preds = %2
%10 = fcmp olt double %1, 0.000000e+00
br i1 %10, label %11, label %18
11: ; preds = %9
%12 = load i32, i32* @FP_INFINITE
%13 = icmp eq i32 %3, %12
%14 = icmp eq i32 %4, %12
%15 = select i1 %13, i1 %14, i1 false
br i1 %15, label %16, label %18
16: ; preds = %11, %2
%17 = fsub double %0, %1
br label %22
18: ; preds = %11, %9
%19 = fcmp ole double %0, %1
%20 = fsub double %0, %1
%21 = select i1 %19, double 0.000000e+00, double %20
br label %22
22: ; preds = %18, %16
%23 = phi double [ %17, %16 ], [ %21, %18 ]
ret double %23
}