int main() {
  volatile double nan = __builtin_nan("");
  volatile double a = 0.1;
  if (__builtin_isnan(__builtin_fmax(nan, a))) {
    return 1;
  }
  if (__builtin_isnan(__builtin_fmax(a, nan))) {
    return 1;
  }
  if (!__builtin_isnan(__builtin_fmax(nan, nan))) {
    return 1;
  }
  volatile double b = 0.2;
  if (__builtin_fmax(a, b) != 0.2) {
    return 1;
  }
  if (__builtin_fmax(b, a) != 0.2) {
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
movl   $0x0,-0x4(%rbp)
movsd  0xef5(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xee0(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm3
movsd  -0x18(%rbp),%xmm2
movaps %xmm2,%xmm4
movaps %xmm3,%xmm0
cmpunordsd %xmm0,%xmm0
movaps %xmm0,%xmm1
pand   %xmm4,%xmm1
maxsd  %xmm3,%xmm2
pandn  %xmm2,%xmm0
por    %xmm1,%xmm0
ucomisd %xmm0,%xmm0
jnp    1163 <main+0x63>
movl   $0x1,-0x4(%rbp)
jmp    1295 <main+0x195>
movsd  -0x18(%rbp),%xmm3
movsd  -0x10(%rbp),%xmm2
movaps %xmm2,%xmm4
movaps %xmm3,%xmm0
cmpunordsd %xmm0,%xmm0
movaps %xmm0,%xmm1
pand   %xmm4,%xmm1
maxsd  %xmm3,%xmm2
pandn  %xmm2,%xmm0
por    %xmm1,%xmm0
ucomisd %xmm0,%xmm0
jnp    11a1 <main+0xa1>
movl   $0x1,-0x4(%rbp)
jmp    1295 <main+0x195>
movsd  -0x10(%rbp),%xmm3
movsd  -0x10(%rbp),%xmm2
movaps %xmm2,%xmm4
movaps %xmm3,%xmm0
cmpunordsd %xmm0,%xmm0
movaps %xmm0,%xmm1
pand   %xmm4,%xmm1
maxsd  %xmm3,%xmm2
pandn  %xmm2,%xmm0
por    %xmm1,%xmm0
ucomisd %xmm0,%xmm0
jp     11df <main+0xdf>
movl   $0x1,-0x4(%rbp)
jmp    1295 <main+0x195>
movsd  0xe29(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm3
movsd  -0x20(%rbp),%xmm2
movaps %xmm2,%xmm4
movaps %xmm3,%xmm0
cmpunordsd %xmm0,%xmm0
movaps %xmm0,%xmm1
pand   %xmm4,%xmm1
maxsd  %xmm3,%xmm2
pandn  %xmm2,%xmm0
por    %xmm1,%xmm0
movsd  0xdf4(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    1231 <main+0x131>
jp     1231 <main+0x131>
jmp    123d <main+0x13d>
movl   $0x1,-0x4(%rbp)
jmp    1295 <main+0x195>
movsd  -0x20(%rbp),%xmm3
movsd  -0x18(%rbp),%xmm2
movaps %xmm2,%xmm4
movaps %xmm3,%xmm0
cmpunordsd %xmm0,%xmm0
movaps %xmm0,%xmm1
pand   %xmm4,%xmm1
maxsd  %xmm3,%xmm2
pandn  %xmm2,%xmm0
por    %xmm1,%xmm0
movsd  0xda3(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    1282 <main+0x182>
jp     1282 <main+0x182>
jmp    128e <main+0x18e>
movl   $0x1,-0x4(%rbp)
jmp    1295 <main+0x195>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
movabs $0x7ff8000000000000,%rax
mov    %rax,-0x10(%rsp)
movabs $0x3fb999999999999a,%rax
99 b9 3f
mov    %rax,-0x18(%rsp)
movsd  -0x10(%rsp),%xmm0
movsd  -0x18(%rsp),%xmm1
movapd %xmm0,%xmm2
cmpunordsd %xmm0,%xmm2
movapd %xmm2,%xmm3
andpd  %xmm1,%xmm3
maxsd  %xmm0,%xmm1
andnpd %xmm1,%xmm2
orpd   %xmm3,%xmm2
mov    $0x1,%eax
ucomisd %xmm2,%xmm2
jp     11b0 <main+0xb0>
movsd  -0x18(%rsp),%xmm0
movsd  -0x10(%rsp),%xmm1
movapd %xmm0,%xmm2
cmpunordsd %xmm0,%xmm2
movapd %xmm2,%xmm3
andpd  %xmm1,%xmm3
maxsd  %xmm0,%xmm1
andnpd %xmm1,%xmm2
orpd   %xmm3,%xmm2
ucomisd %xmm2,%xmm2
jp     11b0 <main+0xb0>
movsd  -0x10(%rsp),%xmm0
movsd  -0x10(%rsp),%xmm1
movapd %xmm0,%xmm2
cmpunordsd %xmm0,%xmm2
movapd %xmm2,%xmm3
andpd  %xmm1,%xmm3
maxsd  %xmm0,%xmm1
andnpd %xmm1,%xmm2
orpd   %xmm3,%xmm2
ucomisd %xmm2,%xmm2
jp     11b1 <main+0xb1>
ret
movabs $0x3fc999999999999a,%rax
99 c9 3f
mov    %rax,-0x8(%rsp)
movsd  -0x18(%rsp),%xmm0
movsd  -0x8(%rsp),%xmm1
movapd %xmm0,%xmm2
cmpunordsd %xmm0,%xmm2
movapd %xmm2,%xmm3
andpd  %xmm1,%xmm3
maxsd  %xmm0,%xmm1
andnpd %xmm1,%xmm2
orpd   %xmm3,%xmm2
mov    $0x1,%eax
ucomisd 0xe0a(%rip),%xmm2
jne    11b0 <main+0xb0>
jp     11b0 <main+0xb0>
movsd  -0x8(%rsp),%xmm0
movsd  -0x18(%rsp),%xmm1
movapd %xmm0,%xmm2
cmpunordsd %xmm0,%xmm2
movapd %xmm2,%xmm3
andpd  %xmm1,%xmm3
maxsd  %xmm0,%xmm1
andnpd %xmm1,%xmm2
orpd   %xmm3,%xmm2
cmpneqsd 0xdd4(%rip),%xmm2
movq   %xmm2,%rax
and    $0x1,%eax
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
store i32 0, i32* %1
store volatile double 0x7FF8000000000000, double* %2
store volatile double 1.000000e-01, double* %3
%5 = load volatile double, double* %2
%6 = load volatile double, double* %3
%7 = call double @llvm.maxnum.f64(double %5, double %6)
%8 = fcmp uno double %7, %7
br i1 %8, label %9, label %10
9: ; preds = %0
store i32 1, i32* %1
br label %35
10: ; preds = %0
%11 = load volatile double, double* %3
%12 = load volatile double, double* %2
%13 = call double @llvm.maxnum.f64(double %11, double %12)
%14 = fcmp uno double %13, %13
br i1 %14, label %15, label %16
15: ; preds = %10
store i32 1, i32* %1
br label %35
16: ; preds = %10
%17 = load volatile double, double* %2
%18 = load volatile double, double* %2
%19 = call double @llvm.maxnum.f64(double %17, double %18)
%20 = fcmp uno double %19, %19
br i1 %20, label %22, label %21
21: ; preds = %16
store i32 1, i32* %1
br label %35
22: ; preds = %16
store volatile double 2.000000e-01, double* %4
%23 = load volatile double, double* %3
%24 = load volatile double, double* %4
%25 = call double @llvm.maxnum.f64(double %23, double %24)
%26 = fcmp une double %25, 2.000000e-01
br i1 %26, label %27, label %28
27: ; preds = %22
store i32 1, i32* %1
br label %35
28: ; preds = %22
%29 = load volatile double, double* %4
%30 = load volatile double, double* %3
%31 = call double @llvm.maxnum.f64(double %29, double %30)
%32 = fcmp une double %31, 2.000000e-01
br i1 %32, label %33, label %34
33: ; preds = %28
store i32 1, i32* %1
br label %35
34: ; preds = %28
store i32 0, i32* %1
br label %35
35: ; preds = %34, %33, %27, %21, %15, %9
%36 = load i32, i32* %1
ret i32 %36
}

LLVM IR (-O2):
define i32 @main() {
%1 = alloca double
%2 = alloca double
%3 = alloca double
%4 = bitcast double* %1 to i8*
store volatile double 0x7FF8000000000000, double* %1
%5 = bitcast double* %2 to i8*
store volatile double 1.000000e-01, double* %2
%6 = load volatile double, double* %1
%7 = load volatile double, double* %2
%8 = tail call double @llvm.maxnum.f64(double %6, double %7)
%9 = fcmp uno double %8, 0.000000e+00
br i1 %9, label %34, label %10
10: ; preds = %0
%11 = load volatile double, double* %2
%12 = load volatile double, double* %1
%13 = tail call double @llvm.maxnum.f64(double %11, double %12)
%14 = fcmp uno double %13, 0.000000e+00
br i1 %14, label %34, label %15
15: ; preds = %10
%16 = load volatile double, double* %1
%17 = load volatile double, double* %1
%18 = tail call double @llvm.maxnum.f64(double %16, double %17)
%19 = fcmp uno double %18, 0.000000e+00
br i1 %19, label %20, label %34
20: ; preds = %15
%21 = bitcast double* %3 to i8*
store volatile double 2.000000e-01, double* %3
%22 = load volatile double, double* %2
%23 = load volatile double, double* %3
%24 = tail call double @llvm.maxnum.f64(double %22, double %23)
%25 = fcmp une double %24, 2.000000e-01
br i1 %25, label %32, label %26
26: ; preds = %20
%27 = load volatile double, double* %3
%28 = load volatile double, double* %2
%29 = tail call double @llvm.maxnum.f64(double %27, double %28)
%30 = fcmp une double %29, 2.000000e-01
%31 = zext i1 %30 to i32
br label %32
32: ; preds = %26, %20
%33 = phi i32 [ 1, %20 ], [ %31, %26 ]
br label %34
34: ; preds = %15, %10, %0, %32
%35 = phi i32 [ %33, %32 ], [ 1, %0 ], [ 1, %10 ], [ 1, %15 ]
ret i32 %35
}