#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 /*<<< orphan*/ printf(char *, double, unsigned short, unsigned short,
                          unsigned short, unsigned short, unsigned short,
                          double);
void test_fbcd(double a) {
  unsigned short bcd[5];
  double b;
  asm("fbstp %0" : "=m"(bcd[0]) : "t"(a) : "st");
  asm("fbld %1" : "=t"(b) : "m"(bcd[0]));
  printf("a=%f bcd=%04x%04x%04x%04x%04x b=%f\n", a, bcd[4], bcd[3], bcd[2],
         bcd[1], bcd[0], b);
}


x86 assembly (clang, -O0):
<test_fbcd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
lea    -0x12(%rbp),%rax
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
fldl   -0x30(%rbp)
fbstp  (%rax)
lea    -0x12(%rbp),%rax
fbld   (%rax)
fstpl  -0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm0
mov    -0xa(%rbp),%si
mov    -0xc(%rbp),%dx
mov    -0xe(%rbp),%cx
mov    -0x10(%rbp),%r8w
mov    -0x12(%rbp),%ax
movsd  -0x20(%rbp),%xmm1
lea    0xe97(%rip),%rdi
movzwl %si,%esi
movzwl %dx,%edx
movzwl %cx,%ecx
movzwl %r8w,%r8d
movzwl %ax,%r9d
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_fbcd>:
sub    $0x28,%rsp
movsd  %xmm0,0x20(%rsp)
fldl   0x20(%rsp)
fbstp  0xe(%rsp)
fbld   0xe(%rsp)
fstpl  0x18(%rsp)
movsd  0x18(%rsp),%xmm1
movzwl 0x16(%rsp),%esi
movzwl 0x14(%rsp),%edx
movzwl 0x12(%rsp),%ecx
movzwl 0x10(%rsp),%r8d
movzwl 0xe(%rsp),%r9d
lea    0xeae(%rip),%rdi
call   1030 <printf@plt>
add    $0x28,%rsp
ret

LLVM IR (-O0):
@.str = [36 x i8] c"a=%f bcd=%04x%04x%04x%04x%04x b=%f\0A\00"
define void @test_fbcd(double %0) {
%2 = alloca double
%3 = alloca [5 x i16]
%4 = alloca double
store double %0, double* %2
%5 = getelementptr inbounds [5 x i16], [5 x i16]* %3, i64 0, i64 0
%6 = load double, double* %2
%7 = getelementptr inbounds [5 x i16], [5 x i16]* %3, i64 0, i64 0
%8 = call double asm "fbld $1", "={st},*m,~{dirflag},~{fpsr},~{flags}"(i16* elementtype(i16) %7)
store double %8, double* %4
%9 = load double, double* %2
%10 = getelementptr inbounds [5 x i16], [5 x i16]* %3, i64 0, i64 4
%11 = load i16, i16* %10
%12 = getelementptr inbounds [5 x i16], [5 x i16]* %3, i64 0, i64 3
%13 = load i16, i16* %12
%14 = getelementptr inbounds [5 x i16], [5 x i16]* %3, i64 0, i64 2
%15 = load i16, i16* %14
%16 = getelementptr inbounds [5 x i16], [5 x i16]* %3, i64 0, i64 1
%17 = load i16, i16* %16
%18 = getelementptr inbounds [5 x i16], [5 x i16]* %3, i64 0, i64 0
%19 = load i16, i16* %18
%20 = load double, double* %4
%21 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), double %9, i16 zeroext %11, i16 zeroext %13, i16 zeroext %15, i16 zeroext %17, i16 zeroext %19, double %20)
ret void
}

LLVM IR (-O2):
@.str = [36 x i8] c"a=%f bcd=%04x%04x%04x%04x%04x b=%f\0A\00"
define void @test_fbcd(double %0) {
%2 = alloca [5 x i16]
%3 = bitcast [5 x i16]* %2 to i8*
%4 = getelementptr inbounds [5 x i16], [5 x i16]* %2, i64 0, i64 0
%5 = call double asm "fbld $1", "={st},*m,~{dirflag},~{fpsr},~{flags}"(i16* elementtype(i16) %4)
%6 = getelementptr inbounds [5 x i16], [5 x i16]* %2, i64 0, i64 4
%7 = load i16, i16* %6
%8 = getelementptr inbounds [5 x i16], [5 x i16]* %2, i64 0, i64 3
%9 = load i16, i16* %8
%10 = getelementptr inbounds [5 x i16], [5 x i16]* %2, i64 0, i64 2
%11 = load i16, i16* %10
%12 = getelementptr inbounds [5 x i16], [5 x i16]* %2, i64 0, i64 1
%13 = load i16, i16* %12
%14 = load i16, i16* %4
%15 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), double %0, i16 zeroext %7, i16 zeroext %9, i16 zeroext %11, i16 zeroext %13, i16 zeroext %14, double %5)
ret void
}