#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;
typedef int /*<<< orphan*/ uint64_t;
typedef int /*<<< orphan*/ uint32_t;
typedef int /*<<< orphan*/ b;
typedef int /*<<< orphan*/ a;

/* Variables and functions */
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
void put64_msb(uint64_t length, void *out) {
  uint32_t a, b;
  memcpy(&a, &length, sizeof(a));
  memcpy(&b, ((uint8_t *)&length) + 4, sizeof(b));
  a = htonl(a);
  b = htonl(b);
  memcpy(((uint8_t *)out), &b, sizeof(b));
  memcpy(((uint8_t *)out) + 4, &a, sizeof(a));
}


x86 assembly (clang, -O0):
<put64_msb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x14(%rbp),%rdi
lea    -0x4(%rbp),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
lea    -0x4(%rbp),%rsi
add    $0x10,%rsi
lea    -0x18(%rbp),%rdi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    -0x14(%rbp),%edi
call   1030 <htonl@plt>
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%edi
call   1030 <htonl@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    -0x10(%rbp),%rdi
add    $0x10,%rdi
lea    -0x14(%rbp),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<put64_msb>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %edi,0xc(%rsp)
lea    0x8(%rsp),%r14
lea    0xc(%rsp),%rsi
mov    %r14,%rdi
mov    $0x4,%edx
call   1040 <memcpy@plt>
lea    0x1c(%rsp),%rsi
lea    0x4(%rsp),%r15
mov    %r15,%rdi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    0x8(%rsp),%edi
call   1030 <htonl@plt>
mov    %eax,0x8(%rsp)
mov    0x4(%rsp),%edi
call   1030 <htonl@plt>
mov    %eax,0x4(%rsp)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
add    $0x10,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @put64_msb(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%7 = call i32 @memcpy(i32* %5, i32* %3, i32 4)
%8 = getelementptr inbounds i32, i32* %3, i64 4
%9 = call i32 @memcpy(i32* %6, i32* %8, i32 4)
%10 = load i32, i32* %5
%11 = call i32 @htonl(i32 %10)
store i32 %11, i32* %5
%12 = load i32, i32* %6
%13 = call i32 @htonl(i32 %12)
store i32 %13, i32* %6
%14 = load i8*, i8** %4
%15 = bitcast i8* %14 to i32*
%16 = call i32 @memcpy(i32* %15, i32* %6, i32 4)
%17 = load i8*, i8** %4
%18 = bitcast i8* %17 to i32*
%19 = getelementptr inbounds i32, i32* %18, i64 4
%20 = call i32 @memcpy(i32* %19, i32* %5, i32 4)
ret void
}

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