#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__ ConvertBitOrder();
void ConvertFromDouble(double val, unsigned char *cnv) {
  unsigned char *in;
  int i;
  in = (unsigned char *)&val;
  if (ConvertBitOrder() == 0)
    for (i = 0; i < 8; i++)
      cnv[7 - i] = in[i];
  else
    for (i = 0; i < 8; i++)
      cnv[i] = in[i];
}


x86 assembly (clang, -O0):
<ConvertFromDouble>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
lea    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1030 <ConvertBitOrder@plt>
cmp    $0x0,%rax
jne    117b <ConvertFromDouble+0x6b>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x8,-0x1c(%rbp)
jge    1176 <ConvertFromDouble+0x66>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
mov    $0x7,%ecx
sub    -0x1c(%rbp),%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1141 <ConvertFromDouble+0x31>
jmp    11b5 <ConvertFromDouble+0xa5>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x8,-0x1c(%rbp)
jge    11b0 <ConvertFromDouble+0xa0>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1182 <ConvertFromDouble+0x72>
jmp    11b5 <ConvertFromDouble+0xa5>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ConvertFromDouble>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1030 <ConvertBitOrder@plt>
test   %rax,%rax
je     1136 <ConvertFromDouble+0x26>
movq   0x8(%rsp),%xmm0
movq   %xmm0,(%rbx)
jmp    1147 <ConvertFromDouble+0x37>
movq   0x8(%rsp),%xmm0
movq   %xmm0,%rax
bswap  %rax
mov    %rax,(%rbx)
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define void @ConvertFromDouble(double %0, i8* %1) {
%3 = alloca double
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store double %0, double* %3
store i8* %1, i8** %4
%7 = bitcast double* %3 to i8*
store i8* %7, i8** %5
%8 = call i64 (...) @ConvertBitOrder()
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %29
10: ; preds = %2
store i32 0, i32* %6
br label %11
11: ; preds = %25, %10
%12 = load i32, i32* %6
%13 = icmp slt i32 %12, 8
br i1 %13, label %14, label %28
14: ; preds = %11
%15 = load i8*, i8** %5
%16 = load i32, i32* %6
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = load i8*, i8** %4
%21 = load i32, i32* %6
%22 = sub nsw i32 7, %21
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %20, i64 %23
store i8 %19, i8* %24
br label %25
25: ; preds = %14
%26 = load i32, i32* %6
%27 = add nsw i32 %26, 1
store i32 %27, i32* %6
br label %11
28: ; preds = %11
br label %47
29: ; preds = %2
store i32 0, i32* %6
br label %30
30: ; preds = %43, %29
%31 = load i32, i32* %6
%32 = icmp slt i32 %31, 8
br i1 %32, label %33, label %46
33: ; preds = %30
%34 = load i8*, i8** %5
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i8, i8* %37
%39 = load i8*, i8** %4
%40 = load i32, i32* %6
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
store i8 %38, i8* %42
br label %43
43: ; preds = %33
%44 = load i32, i32* %6
%45 = add nsw i32 %44, 1
store i32 %45, i32* %6
br label %30
46: ; preds = %30
br label %47
47: ; preds = %46, %28
ret void
}

LLVM IR (-O2):
define void @ConvertFromDouble(double %0, i8* nocapture writeonly %1) {
%3 = tail call i64 (...) @ConvertBitOrder()
%4 = icmp eq i64 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = bitcast i8* %1 to double*
store double %0, double* %6
br label %31
7: ; preds = %2
%8 = bitcast double %0 to i64
%9 = trunc i64 %8 to i8
%10 = getelementptr inbounds i8, i8* %1, i64 7
store i8 %9, i8* %10
%11 = lshr i64 %8, 8
%12 = trunc i64 %11 to i8
%13 = getelementptr inbounds i8, i8* %1, i64 6
store i8 %12, i8* %13
%14 = lshr i64 %8, 16
%15 = trunc i64 %14 to i8
%16 = getelementptr inbounds i8, i8* %1, i64 5
store i8 %15, i8* %16
%17 = lshr i64 %8, 24
%18 = trunc i64 %17 to i8
%19 = getelementptr inbounds i8, i8* %1, i64 4
store i8 %18, i8* %19
%20 = lshr i64 %8, 32
%21 = trunc i64 %20 to i8
%22 = getelementptr inbounds i8, i8* %1, i64 3
store i8 %21, i8* %22
%23 = lshr i64 %8, 40
%24 = trunc i64 %23 to i8
%25 = getelementptr inbounds i8, i8* %1, i64 2
store i8 %24, i8* %25
%26 = lshr i64 %8, 48
%27 = trunc i64 %26 to i8
%28 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %27, i8* %28
%29 = lshr i64 %8, 56
%30 = trunc i64 %29 to i8
store i8 %30, i8* %1
br label %31
31: ; preds = %5, %7
ret void
}