#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__ isnan(double);
double fdim(double x, double y) {
  if (isnan(x))
    return (x);
  if (isnan(y))
    return (y);
  return (x > y ? x - y : 0.0);
}


x86 assembly (clang, -O0):
<fdim>:
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
je     1145 <fdim+0x35>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11a3 <fdim+0x93>
movsd  -0x18(%rbp),%xmm0
call   1030 <isnan@plt>
cmp    $0x0,%rax
je     1168 <fdim+0x58>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11a3 <fdim+0x93>
movsd  -0x10(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    118c <fdim+0x7c>
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1199 <fdim+0x89>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1199 <fdim+0x89>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fdim>:
sub    $0x28,%rsp
movaps %xmm1,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
call   1030 <isnan@plt>
test   %rax,%rax
je     1134 <fdim+0x24>
movsd  0x8(%rsp),%xmm0
add    $0x28,%rsp
ret
movaps 0x10(%rsp),%xmm0
call   1030 <isnan@plt>
test   %rax,%rax
je     114d <fdim+0x3d>
movaps 0x10(%rsp),%xmm0
add    $0x28,%rsp
ret
movsd  0x8(%rsp),%xmm1
movapd %xmm1,%xmm0
movapd 0x10(%rsp),%xmm2
subsd  %xmm2,%xmm0
cmpltsd %xmm1,%xmm2
andpd  %xmm0,%xmm2
movapd %xmm2,%xmm0
add    $0x28,%rsp
ret

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

LLVM IR (-O2):
define double @fdim(double %0, double %1) {
%3 = tail call i64 @isnan(double %0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %12
5: ; preds = %2
%6 = tail call i64 @isnan(double %1)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %5
%9 = fcmp ogt double %0, %1
%10 = fsub double %0, %1
%11 = select i1 %9, double %10, double 0.000000e+00
br label %12
12: ; preds = %5, %2, %8
%13 = phi double [ %11, %8 ], [ %0, %2 ], [ %1, %5 ]
ret double %13
}