void test_fcmov(void) {
  double a, b;
  int eflags, i;
  a = 1.0;
  b = 2.0;
  for (i = 0; i < 4; i++) {
    eflags = 0;
    if (i & 1)
      eflags |= 0x0001;
    if (i & 2)
      eflags |= 0x0040;
    {
      double res;
      asm("push %3\n"
          "popf\n"
          "fcmov"
          "b"
          " %2, %0\n"
          : "=t"(res)
          : "0"(a), "u"(b), "g"(eflags));
      printf("fcmov%s eflags=0x%04x-> %f\n", "b", eflags, res);
    };
    {
      double res;
      asm("push %3\n"
          "popf\n"
          "fcmov"
          "e"
          " %2, %0\n"
          : "=t"(res)
          : "0"(a), "u"(b), "g"(eflags));
      printf("fcmov%s eflags=0x%04x-> %f\n", "e", eflags, res);
    };
    {
      double res;
      asm("push %3\n"
          "popf\n"
          "fcmov"
          "be"
          " %2, %0\n"
          : "=t"(res)
          : "0"(a), "u"(b), "g"(eflags));
      printf("fcmov%s eflags=0x%04x-> %f\n", "be", eflags, res);
    };
    {
      double res;
      asm("push %3\n"
          "popf\n"
          "fcmov"
          "nb"
          " %2, %0\n"
          : "=t"(res)
          : "0"(a), "u"(b), "g"(eflags));
      printf("fcmov%s eflags=0x%04x-> %f\n", "nb", eflags, res);
    };
    {
      double res;
      asm("push %3\n"
          "popf\n"
          "fcmov"
          "ne"
          " %2, %0\n"
          : "=t"(res)
          : "0"(a), "u"(b), "g"(eflags));
      printf("fcmov%s eflags=0x%04x-> %f\n", "ne", eflags, res);
    };
    {
      double res;
      asm("push %3\n"
          "popf\n"
          "fcmov"
          "nbe"
          " %2, %0\n"
          : "=t"(res)
          : "0"(a), "u"(b), "g"(eflags));
      printf("fcmov%s eflags=0x%04x-> %f\n", "nbe", eflags, res);
    };
  }
  {
    double res;
    asm("push %3\n"
        "popf\n"
        "fcmov"
        "u"
        " %2, %0\n"
        : "=t"(res)
        : "0"(a), "u"(b), "g"(0));
    printf("fcmov%s eflags=0x%04x-> %f\n", "u", 0, res);
  };
  {
    double res;
    asm("push %3\n"
        "popf\n"
        "fcmov"
        "u"
        " %2, %0\n"
        : "=t"(res)
        : "0"(a), "u"(b), "g"(0x0004));
    printf("fcmov%s eflags=0x%04x-> %f\n", "u", 0x0004, res);
  };
  {
    double res;
    asm("push %3\n"
        "popf\n"
        "fcmov"
        "nu"
        " %2, %0\n"
        : "=t"(res)
        : "0"(a), "u"(b), "g"(0));
    printf("fcmov%s eflags=0x%04x-> %f\n", "nu", 0, res);
  };
  {
    double res;
    asm("push %3\n"
        "popf\n"
        "fcmov"
        "nu"
        " %2, %0\n"
        : "=t"(res)
        : "0"(a), "u"(b), "g"(0x0004));
    printf("fcmov%s eflags=0x%04x-> %f\n", "nu", 0x0004, res);
  };
}


x86 assembly (clang, -O0):
<test_fcmov>:
push   %rbp
mov    %rsp,%rbp
sub    $0x190,%rsp
movsd  0xee5(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  0xed0(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x4,-0x18(%rbp)
jge    1413 <test_fcmov+0x303>
movl   $0x0,-0x14(%rbp)
mov    -0x18(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1165 <test_fcmov+0x55>
mov    -0x14(%rbp),%eax
or     $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     117d <test_fcmov+0x6d>
mov    -0x14(%rbp),%eax
or     $0x40,%eax
mov    %eax,-0x14(%rbp)
movsd  -0x8(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
mov    -0x14(%rbp),%eax
movsd  %xmm1,-0x178(%rbp)
ff
movsd  %xmm0,-0x180(%rbp)
ff
mov    %eax,-0x16c(%rbp)
fldl   -0x178(%rbp)
fldl   -0x180(%rbp)
fxch   %st(1)
push   -0x16c(%rbp)
popf
fcmovb %st(1),%st
fstp   %st(1)
fstpl  -0x188(%rbp)
movsd  -0x188(%rbp),%xmm0
ff
movsd  %xmm0,-0x20(%rbp)
mov    -0x14(%rbp),%edx
movsd  -0x20(%rbp),%xmm0
lea    0xe35(%rip),%rdi
lea    0xe4b(%rip),%rsi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  -0x8(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
mov    -0x14(%rbp),%eax
movsd  %xmm1,-0x158(%rbp)
ff
movsd  %xmm0,-0x160(%rbp)
ff
mov    %eax,-0x14c(%rbp)
fldl   -0x158(%rbp)
fldl   -0x160(%rbp)
fxch   %st(1)
push   -0x14c(%rbp)
popf
fcmove %st(1),%st
fstp   %st(1)
fstpl  -0x168(%rbp)
movsd  -0x168(%rbp),%xmm0
ff
movsd  %xmm0,-0x28(%rbp)
mov    -0x14(%rbp),%edx
movsd  -0x28(%rbp),%xmm0
lea    0xdc9(%rip),%rdi
lea    0xde6(%rip),%rsi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  -0x8(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
mov    -0x14(%rbp),%eax
movsd  %xmm1,-0x138(%rbp)
ff
movsd  %xmm0,-0x140(%rbp)
ff
mov    %eax,-0x12c(%rbp)
fldl   -0x138(%rbp)
fldl   -0x140(%rbp)
fxch   %st(1)
push   -0x12c(%rbp)
popf
fcmovbe %st(1),%st
fstp   %st(1)
fstpl  -0x148(%rbp)
movsd  -0x148(%rbp),%xmm0
ff
movsd  %xmm0,-0x30(%rbp)
mov    -0x14(%rbp),%edx
movsd  -0x30(%rbp),%xmm0
lea    0xd5d(%rip),%rdi
lea    0xd79(%rip),%rsi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  -0x8(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
mov    -0x14(%rbp),%eax
movsd  %xmm1,-0x118(%rbp)
ff
movsd  %xmm0,-0x120(%rbp)
ff
mov    %eax,-0x10c(%rbp)
fldl   -0x118(%rbp)
fldl   -0x120(%rbp)
fxch   %st(1)
push   -0x10c(%rbp)
popf
fcmovnb %st(1),%st
fstp   %st(1)
fstpl  -0x128(%rbp)
movsd  -0x128(%rbp),%xmm0
ff
movsd  %xmm0,-0x38(%rbp)
mov    -0x14(%rbp),%edx
movsd  -0x38(%rbp),%xmm0
lea    0xcf1(%rip),%rdi
lea    0xd06(%rip),%rsi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  -0x8(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
mov    -0x14(%rbp),%eax
movsd  %xmm1,-0xf8(%rbp)
ff
movsd  %xmm0,-0x100(%rbp)
ff
mov    %eax,-0xec(%rbp)
fldl   -0xf8(%rbp)
fldl   -0x100(%rbp)
fxch   %st(1)
push   -0xec(%rbp)
popf
fcmovne %st(1),%st
fstp   %st(1)
fstpl  -0x108(%rbp)
movsd  -0x108(%rbp),%xmm0
ff
movsd  %xmm0,-0x40(%rbp)
mov    -0x14(%rbp),%edx
movsd  -0x40(%rbp),%xmm0
lea    0xc85(%rip),%rdi
lea    0xc9d(%rip),%rsi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  -0x8(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
mov    -0x14(%rbp),%eax
movsd  %xmm1,-0xd8(%rbp)
ff
movsd  %xmm0,-0xe0(%rbp)
ff
mov    %eax,-0xcc(%rbp)
fldl   -0xd8(%rbp)
fldl   -0xe0(%rbp)
fxch   %st(1)
push   -0xcc(%rbp)
popf
fcmovnbe %st(1),%st
fstp   %st(1)
fstpl  -0xe8(%rbp)
movsd  -0xe8(%rbp),%xmm0
ff
movsd  %xmm0,-0x48(%rbp)
mov    -0x14(%rbp),%edx
movsd  -0x48(%rbp),%xmm0
lea    0xc19(%rip),%rdi
lea    0xc34(%rip),%rsi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113c <test_fcmov+0x2c>
movsd  -0x8(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
movsd  %xmm1,-0xb8(%rbp)
ff
movsd  %xmm0,-0xc0(%rbp)
ff
fldl   -0xb8(%rbp)
fldl   -0xc0(%rbp)
fxch   %st(1)
push   $0x0
popf
fcmovu %st(1),%st
fstp   %st(1)
fstpl  -0xc8(%rbp)
movsd  -0xc8(%rbp),%xmm0
ff
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
lea    0xbaf(%rip),%rdi
lea    0xbcf(%rip),%rsi
xor    %edx,%edx
mov    $0x1,%al
call   1030 <printf@plt>
movsd  -0x8(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
movsd  %xmm1,-0xa0(%rbp)
ff
movsd  %xmm0,-0xa8(%rbp)
ff
fldl   -0xa0(%rbp)
fldl   -0xa8(%rbp)
fxch   %st(1)
push   $0x4
popf
fcmovu %st(1),%st
fstp   %st(1)
fstpl  -0xb0(%rbp)
movsd  -0xb0(%rbp),%xmm0
ff
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
lea    0xb51(%rip),%rdi
lea    0xb71(%rip),%rsi
mov    $0x4,%edx
mov    $0x1,%al
call   1030 <printf@plt>
movsd  -0x8(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
movsd  %xmm1,-0x88(%rbp)
ff
movsd  %xmm0,-0x90(%rbp)
ff
fldl   -0x88(%rbp)
fldl   -0x90(%rbp)
fxch   %st(1)
push   $0x0
popf
fcmovnu %st(1),%st
fstp   %st(1)
fstpl  -0x98(%rbp)
movsd  -0x98(%rbp),%xmm0
ff
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
lea    0xaf0(%rip),%rdi
lea    0xb0f(%rip),%rsi
xor    %edx,%edx
mov    $0x1,%al
call   1030 <printf@plt>
movsd  -0x8(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
movsd  %xmm1,-0x70(%rbp)
movsd  %xmm0,-0x78(%rbp)
fldl   -0x70(%rbp)
fldl   -0x78(%rbp)
fxch   %st(1)
push   $0x4
popf
fcmovnu %st(1),%st
fstp   %st(1)
fstpl  -0x80(%rbp)
movsd  -0x80(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x68(%rbp),%xmm0
lea    0xaa4(%rip),%rdi
lea    0xac3(%rip),%rsi
mov    $0x4,%edx
mov    $0x1,%al
call   1030 <printf@plt>
add    $0x190,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
LLVM IR (-O0):
@.str = [28 x i8] c"fcmov%s eflags=0x%04x-> %f\0A\00"
@.str.1 = [2 x i8] c"b\00"
@.str.2 = [2 x i8] c"e\00"
@.str.3 = [3 x i8] c"be\00"
@.str.4 = [3 x i8] c"nb\00"
@.str.5 = [3 x i8] c"ne\00"
@.str.6 = [4 x i8] c"nbe\00"
@.str.7 = [2 x i8] c"u\00"
@.str.8 = [3 x i8] c"nu\00"
define void @test_fcmov() {
%1 = alloca double
%2 = alloca double
%3 = alloca i32
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
store double 1.000000e+00, double* %1
store double 2.000000e+00, double* %2
store i32 0, i32* %4
br label %15
15: ; preds = %75, %0
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 4
br i1 %17, label %18, label %78
18: ; preds = %15
store i32 0, i32* %3
%19 = load i32, i32* %4
%20 = and i32 %19, 1
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = load i32, i32* %3
%24 = or i32 %23, 1
store i32 %24, i32* %3
br label %25
25: ; preds = %22, %18
%26 = load i32, i32* %4
%27 = and i32 %26, 2
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %25
%30 = load i32, i32* %3
%31 = or i32 %30, 64
store i32 %31, i32* %3
br label %32
32: ; preds = %29, %25
%33 = load double, double* %1
%34 = load double, double* %2
%35 = load i32, i32* %3
%36 = call double asm "push $3\0Apopf\0Afcmovb $2, $0\0A", "={st},0,{st(1)},imr,~{dirflag},~{fpsr},~{flags}"(double %33, double %34, i32 %35)
store double %36, double* %5
%37 = load i32, i32* %3
%38 = load double, double* %5
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %37, double %38)
%40 = load double, double* %1
%41 = load double, double* %2
%42 = load i32, i32* %3
%43 = call double asm "push $3\0Apopf\0Afcmove $2, $0\0A", "={st},0,{st(1)},imr,~{dirflag},~{fpsr},~{flags}"(double %40, double %41, i32 %42)
store double %43, double* %6
%44 = load i32, i32* %3
%45 = load double, double* %6
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 %44, double %45)
%47 = load double, double* %1
%48 = load double, double* %2
%49 = load i32, i32* %3
%50 = call double asm "push $3\0Apopf\0Afcmovbe $2, $0\0A", "={st},0,{st(1)},imr,~{dirflag},~{fpsr},~{flags}"(double %47, double %48, i32 %49)
store double %50, double* %7
%51 = load i32, i32* %3
%52 = load double, double* %7
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %51, double %52)
%54 = load double, double* %1
%55 = load double, double* %2
%56 = load i32, i32* %3
%57 = call double asm "push $3\0Apopf\0Afcmovnb $2, $0\0A", "={st},0,{st(1)},imr,~{dirflag},~{fpsr},~{flags}"(double %54, double %55, i32 %56)
store double %57, double* %8
%58 = load i32, i32* %3
%59 = load double, double* %8
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %58, double %59)
%61 = load double, double* %1
%62 = load double, double* %2
%63 = load i32, i32* %3
%64 = call double asm "push $3\0Apopf\0Afcmovne $2, $0\0A", "={st},0,{st(1)},imr,~{dirflag},~{fpsr},~{flags}"(double %61, double %62, i32 %63)
store double %64, double* %9
%65 = load i32, i32* %3
%66 = load double, double* %9
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %65, double %66)
%68 = load double, double* %1
%69 = load double, double* %2
%70 = load i32, i32* %3
%71 = call double asm "push $3\0Apopf\0Afcmovnbe $2, $0\0A", "={st},0,{st(1)},imr,~{dirflag},~{fpsr},~{flags}"(double %68, double %69, i32 %70)
store double %71, double* %10
%72 = load i32, i32* %3
%73 = load double, double* %10
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %72, double %73)
br label %75
75: ; preds = %32
%76 = load i32, i32* %4
%77 = add nsw i32 %76, 1
store i32 %77, i32* %4
br label %15
78: ; preds = %15
%79 = load double, double* %1
%80 = load double, double* %2
%81 = call double asm "push $3\0Apopf\0Afcmovu $2, $0\0A", "={st},0,{st(1)},imr,~{dirflag},~{fpsr},~{flags}"(double %79, double %80, i32 0)
store double %81, double* %11
%82 = load double, double* %11
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0), i32 0, double %82)
%84 = load double, double* %1
%85 = load double, double* %2
%86 = call double asm "push $3\0Apopf\0Afcmovu $2, $0\0A", "={st},0,{st(1)},imr,~{dirflag},~{fpsr},~{flags}"(double %84, double %85, i32 4)
store double %86, double* %12
%87 = load double, double* %12
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0), i32 4, double %87)
%89 = load double, double* %1
%90 = load double, double* %2
%91 = call double asm "push $3\0Apopf\0Afcmovnu $2, $0\0A", "={st},0,{st(1)},imr,~{dirflag},~{fpsr},~{flags}"(double %89, double %90, i32 0)
store double %91, double* %13
%92 = load double, double* %13
%93 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32 0, double %92)
%94 = load double, double* %1
%95 = load double, double* %2
%96 = call double asm "push $3\0Apopf\0Afcmovnu $2, $0\0A", "={st},0,{st(1)},imr,~{dirflag},~{fpsr},~{flags}"(double %94, double %95, i32 4)
store double %96, double* %14
%97 = load double, double* %14
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32 4, double %97)
ret void
}

LLVM IR (-O2):