unsigned char *Convert_to_80bit_BE_IEEE854_Float(unsigned char *p,
                                                 long double val) {
  unsigned long word32 = 0x401E;
  if (val > 0.L)
    while (val < (long double)0x80000000)
      word32--, val *= 2.L;
  *p++ = (unsigned char)(word32 >> 8);
  *p++ = (unsigned char)(word32 >> 0);
  word32 = (unsigned long)val;
  *p++ = (unsigned char)(word32 >> 24);
  *p++ = (unsigned char)(word32 >> 16);
  *p++ = (unsigned char)(word32 >> 8);
  *p++ = (unsigned char)(word32 >> 0);
  word32 = (unsigned long)((val - word32) * 4294967296.L);
  *p++ = (unsigned char)(word32 >> 24);
  *p++ = (unsigned char)(word32 >> 16);
  *p++ = (unsigned char)(word32 >> 8);
  *p++ = (unsigned char)(word32 >> 0);
  return p;
}


x86 assembly (clang, -O0):
<Convert_to_80bit_BE_IEEE854_Float>:
push   %rbp
mov    %rsp,%rbp
fldt   0x10(%rbp)
mov    %rdi,-0x8(%rbp)
fstpt  -0x20(%rbp)
movq   $0x401e,-0x28(%rbp)
fldt   -0x20(%rbp)
fldz
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jbe    1167 <Convert_to_80bit_BE_IEEE854_Float+0x67>
jmp    112c <Convert_to_80bit_BE_IEEE854_Float+0x2c>
jmp    1131 <Convert_to_80bit_BE_IEEE854_Float+0x31>
fldt   -0x20(%rbp)
flds   0xec6(%rip)
fucomip %st(1),%st
fstp   %st(0)
jbe    1162 <Convert_to_80bit_BE_IEEE854_Float+0x62>
jmp    1149 <Convert_to_80bit_BE_IEEE854_Float+0x49>
mov    -0x28(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
fldt   -0x20(%rbp)
fadd   %st,%st(0)
fstpt  -0x20(%rbp)
jmp    1131 <Convert_to_80bit_BE_IEEE854_Float+0x31>
jmp    1167 <Convert_to_80bit_BE_IEEE854_Float+0x67>
mov    -0x27(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x28(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
fldt   -0x20(%rbp)
flds   0xe6c(%rip)
fucomi %st(1),%st
setbe  %al
fldz
fld    %st(0)
fcmovbe %st(2),%st
fsubrp %st,%st(3)
fnstcw -0x42(%rbp)
movzwl -0x42(%rbp),%ecx
or     $0xc00,%ecx
mov    %cx,-0x44(%rbp)
fldcw  -0x44(%rbp)
fxch   %st(2)
fistpll -0x40(%rbp)
fldcw  -0x42(%rbp)
movzbl %al,%eax
mov    %eax,%ecx
shl    $0x3f,%rcx
mov    -0x40(%rbp),%rax
xor    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x25(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x26(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x27(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x28(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
fldt   -0x20(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
test   %rax,%rax
sets   %al
movzbl %al,%eax
mov    %eax,%ecx
fildll -0x38(%rbp)
lea    0xdcb(%rip),%rax
flds   (%rax,%rcx,4)
faddp  %st,%st(1)
fsubrp %st,%st(1)
flds   0xdb6(%rip)
fmulp  %st,%st(1)
fucomi %st(1),%st
fxch   %st(2)
fcmovnb %st(1),%st
fstp   %st(1)
fsubrp %st,%st(1)
setae  %al
fnstcw -0x46(%rbp)
movzwl -0x46(%rbp),%ecx
or     $0xc00,%ecx
mov    %cx,-0x48(%rbp)
fldcw  -0x48(%rbp)
fistpll -0x30(%rbp)
fldcw  -0x46(%rbp)
movzbl %al,%eax
mov    %eax,%ecx
shl    $0x3f,%rcx
mov    -0x30(%rbp),%rax
xor    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
shr    $0x18,%rax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x28(%rbp),%rax
shr    $0x10,%rax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x28(%rbp),%rax
shr    $0x8,%rax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x28(%rbp),%rax
shr    $0x0,%rax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<Convert_to_80bit_BE_IEEE854_Float>:
mov    %rdi,%rax
fldt   0x8(%rsp)
fldz
fxch   %st(1)
fucomi %st(1),%st
fstp   %st(1)
mov    $0x401e,%ecx
jbe    1140 <Convert_to_80bit_BE_IEEE854_Float+0x40>
flds   0xee4(%rip)
fucomip %st(1),%st
jbe    1140 <Convert_to_80bit_BE_IEEE854_Float+0x40>
mov    $0x401e,%ecx
flds   0xed5(%rip)
nopl   0x0(%rax,%rax,1)
add    $0xffffffffffffffff,%rcx
fxch   %st(1)
fadd   %st,%st(0)
fxch   %st(1)
fucomi %st(1),%st
ja     1130 <Convert_to_80bit_BE_IEEE854_Float+0x30>
jmp    1142 <Convert_to_80bit_BE_IEEE854_Float+0x42>
fldz
fstp   %st(0)
mov    %ch,(%rax)
mov    %cl,0x1(%rax)
flds   0xeb5(%rip)
xor    %ecx,%ecx
fxch   %st(1)
fucomi %st(1),%st
setae  %cl
fldz
fld    %st(0)
fcmovnb %st(3),%st
fsubr  %st(2),%st
fnstcw -0x1e(%rsp)
movzwl -0x1e(%rsp),%edx
or     $0xc00,%edx
mov    %dx,-0x1a(%rsp)
fldcw  -0x1a(%rsp)
fistpll -0x18(%rsp)
fldcw  -0x1e(%rsp)
shl    $0x3f,%rcx
mov    -0x18(%rsp),%rdx
xor    %rdx,%rcx
mov    %rdx,%rsi
shr    $0x18,%rsi
mov    %sil,0x2(%rax)
mov    %rdx,%rsi
shr    $0x10,%rsi
mov    %sil,0x3(%rax)
mov    %dh,0x4(%rax)
mov    %dl,0x5(%rax)
mov    %rcx,-0x10(%rsp)
xor    %edx,%edx
test   %rcx,%rcx
sets   %dl
fildll -0x10(%rsp)
lea    0xe50(%rip),%rcx
fadds  (%rcx,%rdx,4)
fsubrp %st,%st(2)
fxch   %st(1)
fmuls  0xe3b(%rip)
fucomi %st(2),%st
fxch   %st(1)
fcmovnb %st(2),%st
fstp   %st(2)
fsubp  %st,%st(1)
fnstcw -0x20(%rsp)
movzwl -0x20(%rsp),%ecx
or     $0xc00,%ecx
mov    %cx,-0x1c(%rsp)
fldcw  -0x1c(%rsp)
fistpll -0x8(%rsp)
fldcw  -0x20(%rsp)
mov    -0x8(%rsp),%rcx
mov    %rcx,%rdx
shr    $0x18,%rdx
mov    %dl,0x6(%rax)
mov    %rcx,%rdx
shr    $0x10,%rdx
mov    %dl,0x7(%rax)
mov    %ch,0x8(%rax)
mov    %cl,0x9(%rax)
add    $0xa,%rax
ret

LLVM IR (-O0):
define i8* @Convert_to_80bit_BE_IEEE854_Float(i8* %0, x86_fp80 %1) {
%3 = alloca i8*
%4 = alloca x86_fp80
%5 = alloca i64
store i8* %0, i8** %3
store x86_fp80 %1, x86_fp80* %4
store i64 16414, i64* %5
%6 = load x86_fp80, x86_fp80* %4
%7 = fcmp ogt x86_fp80 %6, 0xK00000000000000000000
br i1 %7, label %8, label %18
8: ; preds = %2
br label %9
9: ; preds = %12, %8
%10 = load x86_fp80, x86_fp80* %4
%11 = fcmp olt x86_fp80 %10, 0xK401E8000000000000000
br i1 %11, label %12, label %17
12: ; preds = %9
%13 = load i64, i64* %5
%14 = add i64 %13, -1
store i64 %14, i64* %5
%15 = load x86_fp80, x86_fp80* %4
%16 = fmul x86_fp80 %15, 0xK40008000000000000000
store x86_fp80 %16, x86_fp80* %4
br label %9
17: ; preds = %9
br label %18
18: ; preds = %17, %2
%19 = load i64, i64* %5
%20 = lshr i64 %19, 8
%21 = trunc i64 %20 to i8
%22 = load i8*, i8** %3
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %3
store i8 %21, i8* %22
%24 = load i64, i64* %5
%25 = lshr i64 %24, 0
%26 = trunc i64 %25 to i8
%27 = load i8*, i8** %3
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %3
store i8 %26, i8* %27
%29 = load x86_fp80, x86_fp80* %4
%30 = fptoui x86_fp80 %29 to i64
store i64 %30, i64* %5
%31 = load i64, i64* %5
%32 = lshr i64 %31, 24
%33 = trunc i64 %32 to i8
%34 = load i8*, i8** %3
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %3
store i8 %33, i8* %34
%36 = load i64, i64* %5
%37 = lshr i64 %36, 16
%38 = trunc i64 %37 to i8
%39 = load i8*, i8** %3
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %3
store i8 %38, i8* %39
%41 = load i64, i64* %5
%42 = lshr i64 %41, 8
%43 = trunc i64 %42 to i8
%44 = load i8*, i8** %3
%45 = getelementptr inbounds i8, i8* %44, i32 1
store i8* %45, i8** %3
store i8 %43, i8* %44
%46 = load i64, i64* %5
%47 = lshr i64 %46, 0
%48 = trunc i64 %47 to i8
%49 = load i8*, i8** %3
%50 = getelementptr inbounds i8, i8* %49, i32 1
store i8* %50, i8** %3
store i8 %48, i8* %49
%51 = load x86_fp80, x86_fp80* %4
%52 = load i64, i64* %5
%53 = uitofp i64 %52 to x86_fp80
%54 = fsub x86_fp80 %51, %53
%55 = fmul x86_fp80 %54, 0xK401F8000000000000000
%56 = fptoui x86_fp80 %55 to i64
store i64 %56, i64* %5
%57 = load i64, i64* %5
%58 = lshr i64 %57, 24
%59 = trunc i64 %58 to i8
%60 = load i8*, i8** %3
%61 = getelementptr inbounds i8, i8* %60, i32 1
store i8* %61, i8** %3
store i8 %59, i8* %60
%62 = load i64, i64* %5
%63 = lshr i64 %62, 16
%64 = trunc i64 %63 to i8
%65 = load i8*, i8** %3
%66 = getelementptr inbounds i8, i8* %65, i32 1
store i8* %66, i8** %3
store i8 %64, i8* %65
%67 = load i64, i64* %5
%68 = lshr i64 %67, 8
%69 = trunc i64 %68 to i8
%70 = load i8*, i8** %3
%71 = getelementptr inbounds i8, i8* %70, i32 1
store i8* %71, i8** %3
store i8 %69, i8* %70
%72 = load i64, i64* %5
%73 = lshr i64 %72, 0
%74 = trunc i64 %73 to i8
%75 = load i8*, i8** %3
%76 = getelementptr inbounds i8, i8* %75, i32 1
store i8* %76, i8** %3
store i8 %74, i8* %75
%77 = load i8*, i8** %3
ret i8* %77
}

LLVM IR (-O2):
define i8* @Convert_to_80bit_BE_IEEE854_Float(i8* writeonly %0, x86_fp80 %1) {
%3 = fcmp ogt x86_fp80 %1, 0xK00000000000000000000
%4 = fcmp olt x86_fp80 %1, 0xK401E8000000000000000
%5 = and i1 %3, %4
br i1 %5, label %6, label %12
6: ; preds = %2, %6
%7 = phi x86_fp80 [ %10, %6 ], [ %1, %2 ]
%8 = phi i64 [ %9, %6 ], [ 16414, %2 ]
%9 = add i64 %8, -1
%10 = fmul x86_fp80 %7, 0xK40008000000000000000
%11 = fcmp olt x86_fp80 %10, 0xK401E8000000000000000
br i1 %11, label %6, label %12
12: ; preds = %6, %2
%13 = phi x86_fp80 [ %1, %2 ], [ %10, %6 ]
%14 = phi i64 [ 16414, %2 ], [ %9, %6 ]
%15 = lshr i64 %14, 8
%16 = trunc i64 %15 to i8
%17 = getelementptr inbounds i8, i8* %0, i64 1
store i8 %16, i8* %0
%18 = trunc i64 %14 to i8
%19 = getelementptr inbounds i8, i8* %0, i64 2
store i8 %18, i8* %17
%20 = fptoui x86_fp80 %13 to i64
%21 = lshr i64 %20, 24
%22 = trunc i64 %21 to i8
%23 = getelementptr inbounds i8, i8* %0, i64 3
store i8 %22, i8* %19
%24 = lshr i64 %20, 16
%25 = trunc i64 %24 to i8
%26 = getelementptr inbounds i8, i8* %0, i64 4
store i8 %25, i8* %23
%27 = lshr i64 %20, 8
%28 = trunc i64 %27 to i8
%29 = getelementptr inbounds i8, i8* %0, i64 5
store i8 %28, i8* %26
%30 = trunc i64 %20 to i8
%31 = getelementptr inbounds i8, i8* %0, i64 6
store i8 %30, i8* %29
%32 = uitofp i64 %20 to x86_fp80
%33 = fsub x86_fp80 %13, %32
%34 = fmul x86_fp80 %33, 0xK401F8000000000000000
%35 = fptoui x86_fp80 %34 to i64
%36 = lshr i64 %35, 24
%37 = trunc i64 %36 to i8
%38 = getelementptr inbounds i8, i8* %0, i64 7
store i8 %37, i8* %31
%39 = lshr i64 %35, 16
%40 = trunc i64 %39 to i8
%41 = getelementptr inbounds i8, i8* %0, i64 8
store i8 %40, i8* %38
%42 = lshr i64 %35, 8
%43 = trunc i64 %42 to i8
%44 = getelementptr inbounds i8, i8* %0, i64 9
store i8 %43, i8* %41
%45 = trunc i64 %35 to i8
%46 = getelementptr inbounds i8, i8* %0, i64 10
store i8 %45, i8* %44
ret i8* %46
}