#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 uint8_t;
typedef int uint64_t;

/* Variables and functions */
int /*<<< orphan*/ memcpy(int *, double *, int);
void GST_WRITE_DOUBLE_BE(uint8_t *data, double num) {
  double d = num;
  uint64_t i;
  memcpy(&i, &d, sizeof(double));
  do {
    ((uint8_t *)(data))[0] = (((uint64_t)(i)) >> 56) & 0xff;
    ((uint8_t *)(data))[1] = (((uint64_t)(i)) >> 48) & 0xff;
    ((uint8_t *)(data))[2] = (((uint64_t)(i)) >> 40) & 0xff;
    ((uint8_t *)(data))[3] = (((uint64_t)(i)) >> 32) & 0xff;
    ((uint8_t *)(data))[4] = (((uint64_t)(i)) >> 24) & 0xff;
    ((uint8_t *)(data))[5] = (((uint64_t)(i)) >> 16) & 0xff;
    ((uint8_t *)(data))[6] = (((uint64_t)(i)) >> 8) & 0xff;
    ((uint8_t *)(data))[7] = (((uint64_t)(i)) >> 0) & 0xff;
  } while (0);
}


x86 assembly (clang, -O0):
<GST_WRITE_DOUBLE_BE>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
lea    -0x1c(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x8,%edx
call   1030 <memcpy@plt>
mov    -0x1c(%rbp),%eax
mov    $0x38,%ecx
sar    %cl,%eax
mov    %eax,%ecx
and    $0xff,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%eax
mov    $0x30,%ecx
sar    %cl,%eax
mov    %eax,%ecx
and    $0xff,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x1c(%rbp),%eax
mov    $0x28,%ecx
sar    %cl,%eax
mov    %eax,%ecx
and    $0xff,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x1c(%rbp),%eax
mov    $0x20,%ecx
sar    %cl,%eax
mov    %eax,%ecx
and    $0xff,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0xc(%rax)
mov    -0x1c(%rbp),%ecx
sar    $0x18,%ecx
and    $0xff,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x10(%rax)
mov    -0x1c(%rbp),%ecx
sar    $0x10,%ecx
and    $0xff,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x14(%rax)
mov    -0x1c(%rbp),%ecx
sar    $0x8,%ecx
and    $0xff,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x18(%rax)
mov    -0x1c(%rbp),%ecx
sar    $0x0,%ecx
and    $0xff,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x1c(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GST_WRITE_DOUBLE_BE>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movsd  %xmm0,0x8(%rsp)
lea    0x4(%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    $0x8,%edx
call   1030 <memcpy@plt>
mov    0x4(%rsp),%eax
mov    %eax,%ecx
movzbl %ah,%edx
movzbl %al,%esi
shr    $0x18,%eax
mov    %eax,0x10(%rbx)
shr    $0x10,%ecx
movzbl %cl,%eax
mov    %eax,0x14(%rbx)
mov    %edx,0x18(%rbx)
mov    %esi,0x1c(%rbx)
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define void @GST_WRITE_DOUBLE_BE(i32* %0, double %1) {
%3 = alloca i32*
%4 = alloca double
%5 = alloca double
%6 = alloca i32
store i32* %0, i32** %3
store double %1, double* %4
%7 = load double, double* %4
store double %7, double* %5
%8 = call i32 @memcpy(i32* %6, double* %5, i32 8)
br label %9
9: ; preds = %2
%10 = load i32, i32* %6
%11 = ashr i32 %10, 56
%12 = and i32 %11, 255
%13 = load i32*, i32** %3
%14 = getelementptr inbounds i32, i32* %13, i64 0
store i32 %12, i32* %14
%15 = load i32, i32* %6
%16 = ashr i32 %15, 48
%17 = and i32 %16, 255
%18 = load i32*, i32** %3
%19 = getelementptr inbounds i32, i32* %18, i64 1
store i32 %17, i32* %19
%20 = load i32, i32* %6
%21 = ashr i32 %20, 40
%22 = and i32 %21, 255
%23 = load i32*, i32** %3
%24 = getelementptr inbounds i32, i32* %23, i64 2
store i32 %22, i32* %24
%25 = load i32, i32* %6
%26 = ashr i32 %25, 32
%27 = and i32 %26, 255
%28 = load i32*, i32** %3
%29 = getelementptr inbounds i32, i32* %28, i64 3
store i32 %27, i32* %29
%30 = load i32, i32* %6
%31 = ashr i32 %30, 24
%32 = and i32 %31, 255
%33 = load i32*, i32** %3
%34 = getelementptr inbounds i32, i32* %33, i64 4
store i32 %32, i32* %34
%35 = load i32, i32* %6
%36 = ashr i32 %35, 16
%37 = and i32 %36, 255
%38 = load i32*, i32** %3
%39 = getelementptr inbounds i32, i32* %38, i64 5
store i32 %37, i32* %39
%40 = load i32, i32* %6
%41 = ashr i32 %40, 8
%42 = and i32 %41, 255
%43 = load i32*, i32** %3
%44 = getelementptr inbounds i32, i32* %43, i64 6
store i32 %42, i32* %44
%45 = load i32, i32* %6
%46 = ashr i32 %45, 0
%47 = and i32 %46, 255
%48 = load i32*, i32** %3
%49 = getelementptr inbounds i32, i32* %48, i64 7
store i32 %47, i32* %49
br label %50
50: ; preds = %9
ret void
}

LLVM IR (-O2):
define void @GST_WRITE_DOUBLE_BE(i32* nocapture writeonly %0, double %1) {
%3 = alloca double
%4 = alloca i32
%5 = bitcast double* %3 to i8*
store double %1, double* %3
%6 = bitcast i32* %4 to i8*
%7 = call i32 @memcpy(i32* %4, double* %3, i32 8)
%8 = load i32, i32* %4
%9 = lshr i32 %8, 24
%10 = getelementptr inbounds i32, i32* %0, i64 4
store i32 %9, i32* %10
%11 = lshr i32 %8, 16
%12 = and i32 %11, 255
%13 = getelementptr inbounds i32, i32* %0, i64 5
store i32 %12, i32* %13
%14 = lshr i32 %8, 8
%15 = and i32 %14, 255
%16 = getelementptr inbounds i32, i32* %0, i64 6
store i32 %15, i32* %16
%17 = and i32 %8, 255
%18 = getelementptr inbounds i32, i32* %0, i64 7
store i32 %17, i32* %18
ret void
}