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

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int32_t WriteUint64Be(uint64_t value, void *out) {
  assert(out != NULL);
  uint8_t *buf = (uint8_t *)out;
  buf[0] = (uint8_t)(value >> 56);
  buf[1] = (uint8_t)(value >> 48);
  buf[2] = (uint8_t)(value >> 40);
  buf[3] = (uint8_t)(value >> 32);
  buf[4] = (uint8_t)(value >> 24);
  buf[5] = (uint8_t)(value >> 16);
  buf[6] = (uint8_t)(value >> 8);
  buf[7] = (uint8_t)(value >> 0);
  return 8;
}


x86 assembly (clang, -O0):
<WriteUint64Be>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x38,%ecx
sar    %cl,%eax
movslq %eax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x4(%rbp),%eax
mov    $0x30,%ecx
sar    %cl,%eax
movslq %eax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x4(%rbp),%eax
mov    $0x28,%ecx
sar    %cl,%eax
movslq %eax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x10(%rax)
mov    -0x4(%rbp),%eax
mov    $0x20,%ecx
sar    %cl,%eax
movslq %eax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x18(%rax)
mov    -0x4(%rbp),%eax
sar    $0x18,%eax
movslq %eax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x20(%rax)
mov    -0x4(%rbp),%eax
sar    $0x10,%eax
movslq %eax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x28(%rax)
mov    -0x4(%rbp),%eax
sar    $0x8,%eax
movslq %eax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x30(%rax)
mov    -0x4(%rbp),%eax
sar    $0x0,%eax
movslq %eax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x38(%rax)
mov    $0x8,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<WriteUint64Be>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %edi,%edi
test   %rsi,%rsi
setne  %dil
call   1030 <assert@plt>
mov    %ebp,%eax
sar    $0x18,%eax
cltq
mov    %rax,0x20(%rbx)
mov    %ebp,%eax
sar    $0x10,%eax
cltq
mov    %rax,0x28(%rbx)
movslq %ebp,%rax
sar    $0x8,%ebp
movslq %ebp,%rcx
mov    %rcx,0x30(%rbx)
mov    %rax,0x38(%rbx)
mov    $0x8,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @WriteUint64Be(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64*
store i32 %0, i32* %3
store i8* %1, i8** %4
%6 = load i8*, i8** %4
%7 = icmp ne i8* %6, null
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load i8*, i8** %4
%11 = bitcast i8* %10 to i64*
store i64* %11, i64** %5
%12 = load i32, i32* %3
%13 = ashr i32 %12, 56
%14 = sext i32 %13 to i64
%15 = load i64*, i64** %5
%16 = getelementptr inbounds i64, i64* %15, i64 0
store i64 %14, i64* %16
%17 = load i32, i32* %3
%18 = ashr i32 %17, 48
%19 = sext i32 %18 to i64
%20 = load i64*, i64** %5
%21 = getelementptr inbounds i64, i64* %20, i64 1
store i64 %19, i64* %21
%22 = load i32, i32* %3
%23 = ashr i32 %22, 40
%24 = sext i32 %23 to i64
%25 = load i64*, i64** %5
%26 = getelementptr inbounds i64, i64* %25, i64 2
store i64 %24, i64* %26
%27 = load i32, i32* %3
%28 = ashr i32 %27, 32
%29 = sext i32 %28 to i64
%30 = load i64*, i64** %5
%31 = getelementptr inbounds i64, i64* %30, i64 3
store i64 %29, i64* %31
%32 = load i32, i32* %3
%33 = ashr i32 %32, 24
%34 = sext i32 %33 to i64
%35 = load i64*, i64** %5
%36 = getelementptr inbounds i64, i64* %35, i64 4
store i64 %34, i64* %36
%37 = load i32, i32* %3
%38 = ashr i32 %37, 16
%39 = sext i32 %38 to i64
%40 = load i64*, i64** %5
%41 = getelementptr inbounds i64, i64* %40, i64 5
store i64 %39, i64* %41
%42 = load i32, i32* %3
%43 = ashr i32 %42, 8
%44 = sext i32 %43 to i64
%45 = load i64*, i64** %5
%46 = getelementptr inbounds i64, i64* %45, i64 6
store i64 %44, i64* %46
%47 = load i32, i32* %3
%48 = ashr i32 %47, 0
%49 = sext i32 %48 to i64
%50 = load i64*, i64** %5
%51 = getelementptr inbounds i64, i64* %50, i64 7
store i64 %49, i64* %51
ret i32 8
}

LLVM IR (-O2):
define i32 @WriteUint64Be(i32 %0, i8* writeonly %1) {
%3 = icmp ne i8* %1, null
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = ashr i32 %0, 24
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %1, i64 32
%9 = bitcast i8* %8 to i64*
store i64 %7, i64* %9
%10 = ashr i32 %0, 16
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %1, i64 40
%13 = bitcast i8* %12 to i64*
store i64 %11, i64* %13
%14 = ashr i32 %0, 8
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %1, i64 48
%17 = bitcast i8* %16 to i64*
store i64 %15, i64* %17
%18 = sext i32 %0 to i64
%19 = getelementptr inbounds i8, i8* %1, i64 56
%20 = bitcast i8* %19 to i64*
store i64 %18, i64* %20
ret i32 8
}