long double bswap_ldbl(long double x) {
  union {
    char d[10];
    long double ld;
  } uin;
  union {
    char d[10];
    long double ld;
  } uout;
  uin.ld = x;
  uout.d[0] = uin.d[9];
  uout.d[1] = uin.d[8];
  uout.d[2] = uin.d[7];
  uout.d[3] = uin.d[6];
  uout.d[4] = uin.d[5];
  uout.d[5] = uin.d[4];
  uout.d[6] = uin.d[3];
  uout.d[7] = uin.d[2];
  uout.d[8] = uin.d[1];
  uout.d[9] = uin.d[0];
  return uout.ld;
}


x86 assembly (clang, -O0):
<bswap_ldbl>:
push   %rbp
mov    %rsp,%rbp
fldt   0x10(%rbp)
fstpt  -0x10(%rbp)
fldt   -0x10(%rbp)
fstpt  -0x20(%rbp)
mov    -0x17(%rbp),%al
mov    %al,-0x30(%rbp)
mov    -0x18(%rbp),%al
mov    %al,-0x2f(%rbp)
mov    -0x19(%rbp),%al
mov    %al,-0x2e(%rbp)
mov    -0x1a(%rbp),%al
mov    %al,-0x2d(%rbp)
mov    -0x1b(%rbp),%al
mov    %al,-0x2c(%rbp)
mov    -0x1c(%rbp),%al
mov    %al,-0x2b(%rbp)
mov    -0x1d(%rbp),%al
mov    %al,-0x2a(%rbp)
mov    -0x1e(%rbp),%al
mov    %al,-0x29(%rbp)
mov    -0x1f(%rbp),%al
mov    %al,-0x28(%rbp)
mov    -0x20(%rbp),%al
mov    %al,-0x27(%rbp)
fldt   -0x30(%rbp)
pop    %rbp
ret

x86 assembly (clang, -O2):
<bswap_ldbl>:
mov    0x10(%rsp),%eax
mov    0x8(%rsp),%rcx
bswap  %rcx
bswap  %rax
shrd   $0x30,%rcx,%rax
shr    $0x30,%rcx
mov    %cx,-0x10(%rsp)
mov    %rax,-0x18(%rsp)
fldt   -0x18(%rsp)
ret

LLVM IR (-O0):
%union.anon = type { x86_fp80 }
%union.anon.0 = type { x86_fp80 }
define x86_fp80 @bswap_ldbl(x86_fp80 %0) {
%2 = alloca x86_fp80
%3 = alloca %union.anon
%4 = alloca %union.anon.0
store x86_fp80 %0, x86_fp80* %2
%5 = load x86_fp80, x86_fp80* %2
%6 = bitcast %union.anon* %3 to x86_fp80*
store x86_fp80 %5, x86_fp80* %6
%7 = bitcast %union.anon* %3 to [10 x i8]*
%8 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 9
%9 = load i8, i8* %8
%10 = bitcast %union.anon.0* %4 to [10 x i8]*
%11 = getelementptr inbounds [10 x i8], [10 x i8]* %10, i64 0, i64 0
store i8 %9, i8* %11
%12 = bitcast %union.anon* %3 to [10 x i8]*
%13 = getelementptr inbounds [10 x i8], [10 x i8]* %12, i64 0, i64 8
%14 = load i8, i8* %13
%15 = bitcast %union.anon.0* %4 to [10 x i8]*
%16 = getelementptr inbounds [10 x i8], [10 x i8]* %15, i64 0, i64 1
store i8 %14, i8* %16
%17 = bitcast %union.anon* %3 to [10 x i8]*
%18 = getelementptr inbounds [10 x i8], [10 x i8]* %17, i64 0, i64 7
%19 = load i8, i8* %18
%20 = bitcast %union.anon.0* %4 to [10 x i8]*
%21 = getelementptr inbounds [10 x i8], [10 x i8]* %20, i64 0, i64 2
store i8 %19, i8* %21
%22 = bitcast %union.anon* %3 to [10 x i8]*
%23 = getelementptr inbounds [10 x i8], [10 x i8]* %22, i64 0, i64 6
%24 = load i8, i8* %23
%25 = bitcast %union.anon.0* %4 to [10 x i8]*
%26 = getelementptr inbounds [10 x i8], [10 x i8]* %25, i64 0, i64 3
store i8 %24, i8* %26
%27 = bitcast %union.anon* %3 to [10 x i8]*
%28 = getelementptr inbounds [10 x i8], [10 x i8]* %27, i64 0, i64 5
%29 = load i8, i8* %28
%30 = bitcast %union.anon.0* %4 to [10 x i8]*
%31 = getelementptr inbounds [10 x i8], [10 x i8]* %30, i64 0, i64 4
store i8 %29, i8* %31
%32 = bitcast %union.anon* %3 to [10 x i8]*
%33 = getelementptr inbounds [10 x i8], [10 x i8]* %32, i64 0, i64 4
%34 = load i8, i8* %33
%35 = bitcast %union.anon.0* %4 to [10 x i8]*
%36 = getelementptr inbounds [10 x i8], [10 x i8]* %35, i64 0, i64 5
store i8 %34, i8* %36
%37 = bitcast %union.anon* %3 to [10 x i8]*
%38 = getelementptr inbounds [10 x i8], [10 x i8]* %37, i64 0, i64 3
%39 = load i8, i8* %38
%40 = bitcast %union.anon.0* %4 to [10 x i8]*
%41 = getelementptr inbounds [10 x i8], [10 x i8]* %40, i64 0, i64 6
store i8 %39, i8* %41
%42 = bitcast %union.anon* %3 to [10 x i8]*
%43 = getelementptr inbounds [10 x i8], [10 x i8]* %42, i64 0, i64 2
%44 = load i8, i8* %43
%45 = bitcast %union.anon.0* %4 to [10 x i8]*
%46 = getelementptr inbounds [10 x i8], [10 x i8]* %45, i64 0, i64 7
store i8 %44, i8* %46
%47 = bitcast %union.anon* %3 to [10 x i8]*
%48 = getelementptr inbounds [10 x i8], [10 x i8]* %47, i64 0, i64 1
%49 = load i8, i8* %48
%50 = bitcast %union.anon.0* %4 to [10 x i8]*
%51 = getelementptr inbounds [10 x i8], [10 x i8]* %50, i64 0, i64 8
store i8 %49, i8* %51
%52 = bitcast %union.anon* %3 to [10 x i8]*
%53 = getelementptr inbounds [10 x i8], [10 x i8]* %52, i64 0, i64 0
%54 = load i8, i8* %53
%55 = bitcast %union.anon.0* %4 to [10 x i8]*
%56 = getelementptr inbounds [10 x i8], [10 x i8]* %55, i64 0, i64 9
store i8 %54, i8* %56
%57 = bitcast %union.anon.0* %4 to x86_fp80*
%58 = load x86_fp80, x86_fp80* %57
ret x86_fp80 %58
}

LLVM IR (-O2):
define x86_fp80 @bswap_ldbl(x86_fp80 %0) {
%2 = bitcast x86_fp80 %0 to i80
%3 = tail call i80 @llvm.bswap.i80(i80 %2)
%4 = bitcast i80 %3 to x86_fp80
ret x86_fp80 %4
}