#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 */
scalar_t__ isBigEndian();
double DoubleVal(double d) {
  {
    (void)((int (*)(
        char failed_static_assertion[(sizeof(double) == 8) ? 1 : -1]))0);
  };
  if (isBigEndian()) {
    union {
      double d;
      unsigned char b[8];
    } dat1, dat2;
    dat1.d = d;
    dat2.b[0] = dat1.b[7];
    dat2.b[1] = dat1.b[6];
    dat2.b[2] = dat1.b[5];
    dat2.b[3] = dat1.b[4];
    dat2.b[4] = dat1.b[3];
    dat2.b[5] = dat1.b[2];
    dat2.b[6] = dat1.b[1];
    dat2.b[7] = dat1.b[0];
    return dat2.d;
  } else
    return d;
}


x86 assembly (clang, -O0):
<DoubleVal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    $0x0,%al
call   1030 <isBigEndian@plt>
cmp    $0x0,%rax
je     1177 <DoubleVal+0x67>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x11(%rbp),%al
mov    %al,-0x20(%rbp)
mov    -0x12(%rbp),%al
mov    %al,-0x1f(%rbp)
mov    -0x13(%rbp),%al
mov    %al,-0x1e(%rbp)
mov    -0x14(%rbp),%al
mov    %al,-0x1d(%rbp)
mov    -0x15(%rbp),%al
mov    %al,-0x1c(%rbp)
mov    -0x16(%rbp),%al
mov    %al,-0x1b(%rbp)
mov    -0x17(%rbp),%al
mov    %al,-0x1a(%rbp)
mov    -0x18(%rbp),%al
mov    %al,-0x19(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1181 <DoubleVal+0x71>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DoubleVal>:
push   %rax
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1030 <isBigEndian@plt>
test   %rax,%rax
je     1136 <DoubleVal+0x26>
movq   (%rsp),%xmm0
movq   %xmm0,%rax
bswap  %rax
movq   %rax,%xmm0
pop    %rax
ret
movsd  (%rsp),%xmm0
pop    %rax
ret

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

LLVM IR (-O2):
define double @DoubleVal(double %0) {
%2 = tail call i64 (...) @isBigEndian()
%3 = icmp eq i64 %2, 0
%4 = bitcast double %0 to i64
%5 = tail call i64 @llvm.bswap.i64(i64 %4)
%6 = bitcast i64 %5 to double
%7 = select i1 %3, double %0, double %6
ret double %7
}