#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 */
typedef int /*<<< orphan*/ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
uint8_t *double_to_bytes(uint8_t *buf, double val) {
  union {
    uint8_t dc[8];
    double dd;
  } d;
  uint8_t b[8];
  d.dd = val;
  b[0] = d.dc[7];
  b[1] = d.dc[6];
  b[2] = d.dc[5];
  b[3] = d.dc[4];
  b[4] = d.dc[3];
  b[5] = d.dc[2];
  b[6] = d.dc[1];
  b[7] = d.dc[0];
  memcpy(buf, b, 8);
  return buf + 8;
}


x86 assembly (clang, -O0):
<double_to_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x50(%rbp),%rsi
mov    $0x8,%edx
call   1030 <memcpy@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<double_to_bytes>:
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
movq   %xmm0,%rax
ror    $0x20,%rax
mov    %rax,0x18(%rsp)
mov    %rsp,%rsi
mov    $0x8,%edx
call   1030 <memcpy@plt>
add    $0x20,%rbx
mov    %rbx,%rax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%union.anon = type { double, [24 x i8] }
define i32* @double_to_bytes(i32* %0, double %1) {
%3 = alloca i32*
%4 = alloca double
%5 = alloca %union.anon
%6 = alloca [8 x i32]
store i32* %0, i32** %3
store double %1, double* %4
%7 = load double, double* %4
%8 = bitcast %union.anon* %5 to double*
store double %7, double* %8
%9 = bitcast %union.anon* %5 to [8 x i32]*
%10 = getelementptr inbounds [8 x i32], [8 x i32]* %9, i64 0, i64 7
%11 = load i32, i32* %10
%12 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 0
store i32 %11, i32* %12
%13 = bitcast %union.anon* %5 to [8 x i32]*
%14 = getelementptr inbounds [8 x i32], [8 x i32]* %13, i64 0, i64 6
%15 = load i32, i32* %14
%16 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 1
store i32 %15, i32* %16
%17 = bitcast %union.anon* %5 to [8 x i32]*
%18 = getelementptr inbounds [8 x i32], [8 x i32]* %17, i64 0, i64 5
%19 = load i32, i32* %18
%20 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 2
store i32 %19, i32* %20
%21 = bitcast %union.anon* %5 to [8 x i32]*
%22 = getelementptr inbounds [8 x i32], [8 x i32]* %21, i64 0, i64 4
%23 = load i32, i32* %22
%24 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 3
store i32 %23, i32* %24
%25 = bitcast %union.anon* %5 to [8 x i32]*
%26 = getelementptr inbounds [8 x i32], [8 x i32]* %25, i64 0, i64 3
%27 = load i32, i32* %26
%28 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 4
store i32 %27, i32* %28
%29 = bitcast %union.anon* %5 to [8 x i32]*
%30 = getelementptr inbounds [8 x i32], [8 x i32]* %29, i64 0, i64 2
%31 = load i32, i32* %30
%32 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 5
store i32 %31, i32* %32
%33 = bitcast %union.anon* %5 to [8 x i32]*
%34 = getelementptr inbounds [8 x i32], [8 x i32]* %33, i64 0, i64 1
%35 = load i32, i32* %34
%36 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 6
store i32 %35, i32* %36
%37 = bitcast %union.anon* %5 to [8 x i32]*
%38 = getelementptr inbounds [8 x i32], [8 x i32]* %37, i64 0, i64 0
%39 = load i32, i32* %38
%40 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 7
store i32 %39, i32* %40
%41 = load i32*, i32** %3
%42 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 0
%43 = call i32 @memcpy(i32* %41, i32* %42, i32 8)
%44 = load i32*, i32** %3
%45 = getelementptr inbounds i32, i32* %44, i64 8
ret i32* %45
}

LLVM IR (-O2):
define i32* @double_to_bytes(i32* %0, double %1) {
%3 = alloca [8 x i32]
%4 = bitcast [8 x i32]* %3 to i8*
%5 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 0
%6 = bitcast double %1 to i64
%7 = lshr i64 %6, 32
%8 = trunc i64 %7 to i32
%9 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 6
store i32 %8, i32* %9
%10 = trunc i64 %6 to i32
%11 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 7
store i32 %10, i32* %11
%12 = call i32 @memcpy(i32* %0, i32* %5, i32 8)
%13 = getelementptr inbounds i32, i32* %0, i64 8
ret i32* %13
}