#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 */
void write64_be(uint64_t v, uint8_t buf[8]) {
  *buf++ = (v >> 56) & 0xff;
  *buf++ = (v >> 48) & 0xff;
  *buf++ = (v >> 40) & 0xff;
  *buf++ = (v >> 32) & 0xff;
  *buf++ = (v >> 24) & 0xff;
  *buf++ = (v >> 16) & 0xff;
  *buf++ = (v >> 8) & 0xff;
  *buf = v & 0xff;
}


x86 assembly (clang, -O0):
<write64_be>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x38,%ecx
sar    %cl,%eax
mov    %eax,%ecx
and    $0xff,%ecx
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x10(%rbp)
mov    %ecx,(%rax)
mov    -0x4(%rbp),%eax
mov    $0x30,%ecx
sar    %cl,%eax
mov    %eax,%ecx
and    $0xff,%ecx
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x10(%rbp)
mov    %ecx,(%rax)
mov    -0x4(%rbp),%eax
mov    $0x28,%ecx
sar    %cl,%eax
mov    %eax,%ecx
and    $0xff,%ecx
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x10(%rbp)
mov    %ecx,(%rax)
mov    -0x4(%rbp),%eax
mov    $0x20,%ecx
sar    %cl,%eax
mov    %eax,%ecx
and    $0xff,%ecx
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x10(%rbp)
mov    %ecx,(%rax)
mov    -0x4(%rbp),%ecx
sar    $0x18,%ecx
and    $0xff,%ecx
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x10(%rbp)
mov    %ecx,(%rax)
mov    -0x4(%rbp),%ecx
sar    $0x10,%ecx
and    $0xff,%ecx
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x10(%rbp)
mov    %ecx,(%rax)
mov    -0x4(%rbp),%ecx
sar    $0x8,%ecx
and    $0xff,%ecx
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x10(%rbp)
mov    %ecx,(%rax)
mov    -0x4(%rbp),%ecx
and    $0xff,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<write64_be>:
mov    %edi,%eax
mov    %edi,%ecx
movzbl %ah,%edx
movzbl %al,%edi
shr    $0x18,%eax
mov    %eax,0x10(%rsi)
shr    $0x10,%ecx
movzbl %cl,%eax
mov    %eax,0x14(%rsi)
mov    %edx,0x18(%rsi)
mov    %edi,0x1c(%rsi)
ret

LLVM IR (-O0):
define void @write64_be(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
store i32 %0, i32* %3
store i32* %1, i32** %4
%5 = load i32, i32* %3
%6 = ashr i32 %5, 56
%7 = and i32 %6, 255
%8 = load i32*, i32** %4
%9 = getelementptr inbounds i32, i32* %8, i32 1
store i32* %9, i32** %4
store i32 %7, i32* %8
%10 = load i32, i32* %3
%11 = ashr i32 %10, 48
%12 = and i32 %11, 255
%13 = load i32*, i32** %4
%14 = getelementptr inbounds i32, i32* %13, i32 1
store i32* %14, i32** %4
store i32 %12, i32* %13
%15 = load i32, i32* %3
%16 = ashr i32 %15, 40
%17 = and i32 %16, 255
%18 = load i32*, i32** %4
%19 = getelementptr inbounds i32, i32* %18, i32 1
store i32* %19, i32** %4
store i32 %17, i32* %18
%20 = load i32, i32* %3
%21 = ashr i32 %20, 32
%22 = and i32 %21, 255
%23 = load i32*, i32** %4
%24 = getelementptr inbounds i32, i32* %23, i32 1
store i32* %24, i32** %4
store i32 %22, i32* %23
%25 = load i32, i32* %3
%26 = ashr i32 %25, 24
%27 = and i32 %26, 255
%28 = load i32*, i32** %4
%29 = getelementptr inbounds i32, i32* %28, i32 1
store i32* %29, i32** %4
store i32 %27, i32* %28
%30 = load i32, i32* %3
%31 = ashr i32 %30, 16
%32 = and i32 %31, 255
%33 = load i32*, i32** %4
%34 = getelementptr inbounds i32, i32* %33, i32 1
store i32* %34, i32** %4
store i32 %32, i32* %33
%35 = load i32, i32* %3
%36 = ashr i32 %35, 8
%37 = and i32 %36, 255
%38 = load i32*, i32** %4
%39 = getelementptr inbounds i32, i32* %38, i32 1
store i32* %39, i32** %4
store i32 %37, i32* %38
%40 = load i32, i32* %3
%41 = and i32 %40, 255
%42 = load i32*, i32** %4
store i32 %41, i32* %42
ret void
}

LLVM IR (-O2):
define void @write64_be(i32 %0, i32* nocapture writeonly %1) {
%3 = getelementptr inbounds i32, i32* %1, i64 4
%4 = lshr i32 %0, 24
%5 = getelementptr inbounds i32, i32* %1, i64 5
store i32 %4, i32* %3
%6 = lshr i32 %0, 16
%7 = and i32 %6, 255
%8 = getelementptr inbounds i32, i32* %1, i64 6
store i32 %7, i32* %5
%9 = lshr i32 %0, 8
%10 = and i32 %9, 255
%11 = getelementptr inbounds i32, i32* %1, i64 7
store i32 %10, i32* %8
%12 = and i32 %0, 255
store i32 %12, i32* %11
ret void
}