void test_fcmp(double a, double b) {
  printf("(%f<%f)=%d\n", a, b, a < b);
  printf("(%f<=%f)=%d\n", a, b, a <= b);
  printf("(%f==%f)=%d\n", a, b, a == b);
  printf("(%f>%f)=%d\n", a, b, a > b);
  printf("(%f<=%f)=%d\n", a, b, a >= b);
  {
    unsigned long long int eflags;
    asm("fcomi %2, %1\n"
        "pushfq\n"
        "popq %0\n"
        : "=r"(eflags)
        : "t"(a), "u"(b));
    printf("fcomi(%f %f)=%08llx\n", a, b, eflags & (0x0040 | 0x0004 | 0x0001));
  }
}


x86 assembly (clang, -O0):
<test_fcmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x8(%rbp),%xmm3
movsd  -0x10(%rbp),%xmm2
ucomisd %xmm3,%xmm2
seta   %al
and    $0x1,%al
movzbl %al,%esi
lea    0xeb7(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x8(%rbp),%xmm3
movsd  -0x10(%rbp),%xmm2
ucomisd %xmm3,%xmm2
setae  %al
and    $0x1,%al
movzbl %al,%esi
lea    0xe95(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x8(%rbp),%xmm2
ucomisd -0x10(%rbp),%xmm2
sete   %al
setnp  %cl
and    %cl,%al
and    $0x1,%al
movzbl %al,%esi
lea    0xe73(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x8(%rbp),%xmm2
ucomisd -0x10(%rbp),%xmm2
seta   %al
and    $0x1,%al
movzbl %al,%esi
lea    0xe56(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x8(%rbp),%xmm2
ucomisd -0x10(%rbp),%xmm2
setae  %al
and    $0x1,%al
movzbl %al,%esi
lea    0xe12(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
movsd  -0x8(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
movsd  %xmm1,-0x20(%rbp)
movsd  %xmm0,-0x28(%rbp)
fldl   -0x20(%rbp)
fldl   -0x28(%rbp)
fxch   %st(1)
fcomi  %st(1),%st
pushf
pop    %rax
fstp   %st(0)
fstp   %st(0)
mov    %rax,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
mov    -0x18(%rbp),%rsi
and    $0x45,%rsi
lea    0xdf0(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_fcmp>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
xor    %esi,%esi
xor    %ebp,%ebp
ucomisd %xmm0,%xmm1
seta   %sil
lea    0xecb(%rip),%rdi
setae  %bpl
mov    $0x2,%al
call   1030 <printf@plt>
lea    0xec5(%rip),%rbx
mov    %rbx,%rdi
movsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
mov    %ebp,%esi
mov    $0x2,%al
call   1030 <printf@plt>
movsd  0x8(%rsp),%xmm0
movapd %xmm0,%xmm2
movsd  0x10(%rsp),%xmm1
cmpeqsd %xmm1,%xmm2
movq   %xmm2,%rsi
and    $0x1,%esi
lea    0xe96(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
xor    %esi,%esi
xor    %ebp,%ebp
movsd  0x10(%rsp),%xmm1
movsd  0x8(%rsp),%xmm0
ucomisd %xmm1,%xmm0
seta   %sil
lea    0xe7d(%rip),%rdi
setae  %bpl
mov    $0x2,%al
call   1030 <printf@plt>
mov    %rbx,%rdi
movsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
mov    %ebp,%esi
mov    $0x2,%al
call   1030 <printf@plt>
movsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x20(%rsp)
movsd  0x10(%rsp),%xmm1
movsd  %xmm1,0x18(%rsp)
fldl   0x20(%rsp)
fldl   0x18(%rsp)
fxch   %st(1)
fcomi  %st(1),%st
pushf
pop    %rsi
fstp   %st(0)
fstp   %st(0)
and    $0x45,%esi
lea    0xe32(%rip),%rdi
mov    $0x2,%al
add    $0x28,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"(%f<%f)=%d\0A\00"
@.str.1 = [13 x i8] c"(%f<=%f)=%d\0A\00"
@.str.2 = [13 x i8] c"(%f==%f)=%d\0A\00"
@.str.3 = [12 x i8] c"(%f>%f)=%d\0A\00"
@.str.4 = [21 x i8] c"fcomi(%f %f)=%08llx\0A\00"
define void @test_fcmp(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca i64
store double %0, double* %3
store double %1, double* %4
%6 = load double, double* %3
%7 = load double, double* %4
%8 = load double, double* %3
%9 = load double, double* %4
%10 = fcmp olt double %8, %9
%11 = zext i1 %10 to i32
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), double %6, double %7, i32 %11)
%13 = load double, double* %3
%14 = load double, double* %4
%15 = load double, double* %3
%16 = load double, double* %4
%17 = fcmp ole double %15, %16
%18 = zext i1 %17 to i32
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), double %13, double %14, i32 %18)
%20 = load double, double* %3
%21 = load double, double* %4
%22 = load double, double* %3
%23 = load double, double* %4
%24 = fcmp oeq double %22, %23
%25 = zext i1 %24 to i32
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), double %20, double %21, i32 %25)
%27 = load double, double* %3
%28 = load double, double* %4
%29 = load double, double* %3
%30 = load double, double* %4
%31 = fcmp ogt double %29, %30
%32 = zext i1 %31 to i32
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), double %27, double %28, i32 %32)
%34 = load double, double* %3
%35 = load double, double* %4
%36 = load double, double* %3
%37 = load double, double* %4
%38 = fcmp oge double %36, %37
%39 = zext i1 %38 to i32
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), double %34, double %35, i32 %39)
%41 = load double, double* %3
%42 = load double, double* %4
%43 = call i64 asm "fcomi $2, $1\0Apushfq\0Apopq $0\0A", "=r,{st},{st(1)},~{dirflag},~{fpsr},~{flags}"(double %41, double %42)
store i64 %43, i64* %5
%44 = load double, double* %3
%45 = load double, double* %4
%46 = load i64, i64* %5
%47 = and i64 %46, 69
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), double %44, double %45, i64 %47)
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"(%f<%f)=%d\0A\00"
@.str.1 = [13 x i8] c"(%f<=%f)=%d\0A\00"
@.str.2 = [13 x i8] c"(%f==%f)=%d\0A\00"
@.str.3 = [12 x i8] c"(%f>%f)=%d\0A\00"
@.str.4 = [21 x i8] c"fcomi(%f %f)=%08llx\0A\00"
define void @test_fcmp(double %0, double %1) {
%3 = fcmp olt double %0, %1
%4 = zext i1 %3 to i32
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), double %0, double %1, i32 %4)
%6 = fcmp ole double %0, %1
%7 = zext i1 %6 to i32
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), double %0, double %1, i32 %7)
%9 = fcmp oeq double %0, %1
%10 = zext i1 %9 to i32
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), double %0, double %1, i32 %10)
%12 = fcmp ogt double %0, %1
%13 = zext i1 %12 to i32
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), double %0, double %1, i32 %13)
%15 = fcmp oge double %0, %1
%16 = zext i1 %15 to i32
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), double %0, double %1, i32 %16)
%18 = tail call i64 asm "fcomi $2, $1\0Apushfq\0Apopq $0\0A", "=r,{st},{st(1)},~{dirflag},~{fpsr},~{flags}"(double %0, double %1)
%19 = and i64 %18, 69
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), double %0, double %1, i64 %19)
ret void
}