#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 u_int64_t;
typedef int u_int32_t;
typedef int /*<<< orphan*/ low_part;
typedef int /*<<< orphan*/ high_part;

/* Variables and functions */
int htonl(int);
int /*<<< orphan*/ memcpy(char *, int *, int);
void htoun64(void *network, u_int64_t host) {
  char *unaligned = (char *)network;
  u_int32_t high_part, low_part;
  high_part = host >> 32;
  high_part = htonl(high_part);
  low_part = host & 0xFFFFFFFFLL;
  low_part = htonl(low_part);
  memcpy(unaligned, &high_part, sizeof(high_part));
  unaligned += sizeof(high_part);
  memcpy(unaligned, &low_part, sizeof(low_part));
}


x86 assembly (clang, -O0):
<htoun64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x20,%ecx
sar    %cl,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <htonl@plt>
mov    %eax,-0x1c(%rbp)
movslq -0xc(%rbp),%rax
movabs $0xffffffff,%rcx
and    %rcx,%rax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
call   1030 <htonl@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<htoun64>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <htonl@plt>
mov    %eax,0x4(%rsp)
mov    %ebp,%edi
call   1030 <htonl@plt>
mov    %eax,(%rsp)
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1040 <memcpy@plt>
add    $0x4,%rbx
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1040 <memcpy@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @htoun64(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = load i8*, i8** %3
store i8* %8, i8** %5
%9 = load i32, i32* %4
%10 = ashr i32 %9, 32
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = call i32 @htonl(i32 %11)
store i32 %12, i32* %6
%13 = load i32, i32* %4
%14 = sext i32 %13 to i64
%15 = and i64 %14, 4294967295
%16 = trunc i64 %15 to i32
store i32 %16, i32* %7
%17 = load i32, i32* %7
%18 = call i32 @htonl(i32 %17)
store i32 %18, i32* %7
%19 = load i8*, i8** %5
%20 = call i32 @memcpy(i8* %19, i32* %6, i32 4)
%21 = load i8*, i8** %5
%22 = getelementptr inbounds i8, i8* %21, i64 4
store i8* %22, i8** %5
%23 = load i8*, i8** %5
%24 = call i32 @memcpy(i8* %23, i32* %7, i32 4)
ret void
}

LLVM IR (-O2):
define void @htoun64(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = tail call i32 @htonl(i32 poison)
store i32 %7, i32* %3
%8 = tail call i32 @htonl(i32 %1)
store i32 %8, i32* %4
%9 = call i32 @memcpy(i8* %0, i32* %3, i32 4)
%10 = getelementptr inbounds i8, i8* %0, i64 4
%11 = call i32 @memcpy(i8* %10, i32* %4, i32 4)
ret void
}