#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;

/* Variables and functions */
long htonl(int);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/ **, int);
void serial_uint64(uint8_t **const ptr, const uint64_t v) {
  if (htonl(1) == 1L) {
    memcpy(*ptr, &v, sizeof(uint64_t));
  } else {
    int i;
    uint8_t rv[sizeof(uint64_t)];
    uint8_t *pv = (uint8_t *)&v;
    for (i = 0; i < 8; i++) {
      rv[i] = pv[7 - i];
    }
    memcpy(*ptr, &rv, sizeof(uint64_t));
  }
  *ptr += sizeof(uint64_t);
}


x86 assembly (clang, -O0):
<serial_uint64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x1,%edi
call   1030 <htonl@plt>
cmp    $0x1,%rax
jne    115e <serial_uint64+0x3e>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x8,%edx
call   1040 <memcpy@plt>
jmp    11b4 <serial_uint64+0x94>
lea    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x8,-0x14(%rbp)
jge    119f <serial_uint64+0x7f>
mov    -0x48(%rbp),%rax
mov    $0x7,%ecx
sub    -0x14(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%ecx
movslq -0x14(%rbp),%rax
mov    %ecx,-0x40(%rbp,%rax,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116d <serial_uint64+0x4d>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
lea    -0x40(%rbp),%rsi
mov    $0x8,%edx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0x20,%rcx
mov    %rcx,(%rax)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serial_uint64>:
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,0x8(%rsp)
mov    $0x1,%edi
call   1030 <htonl@plt>
cmp    $0x1,%rax
jne    114c <serial_uint64+0x2c>
mov    (%r14),%rdi
lea    0x8(%rsp),%rsi
jmp    115d <serial_uint64+0x3d>
ror    $0x20,%rbx
mov    %rbx,0x28(%rsp)
mov    (%r14),%rdi
lea    0x10(%rsp),%rsi
mov    $0x8,%edx
call   1040 <memcpy@plt>
addq   $0x20,(%r14)
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @serial_uint64(i32** %0, i32* %1) {
%3 = alloca i32**
%4 = alloca i32*
%5 = alloca i32
%6 = alloca [8 x i32]
%7 = alloca i32*
store i32** %0, i32*** %3
store i32* %1, i32** %4
%8 = call i64 @htonl(i32 1)
%9 = icmp eq i64 %8, 1
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32**, i32*** %3
%12 = load i32*, i32** %11
%13 = call i32 @memcpy(i32* %12, i32** %4, i32 8)
br label %37
14: ; preds = %2
%15 = bitcast i32** %4 to i32*
store i32* %15, i32** %7
store i32 0, i32* %5
br label %16
16: ; preds = %29, %14
%17 = load i32, i32* %5
%18 = icmp slt i32 %17, 8
br i1 %18, label %19, label %32
19: ; preds = %16
%20 = load i32*, i32** %7
%21 = load i32, i32* %5
%22 = sub nsw i32 7, %21
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %20, i64 %23
%25 = load i32, i32* %24
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 %27
store i32 %25, i32* %28
br label %29
29: ; preds = %19
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
store i32 %31, i32* %5
br label %16
32: ; preds = %16
%33 = load i32**, i32*** %3
%34 = load i32*, i32** %33
%35 = bitcast [8 x i32]* %6 to i32**
%36 = call i32 @memcpy(i32* %34, i32** %35, i32 8)
br label %37
37: ; preds = %32, %10
%38 = load i32**, i32*** %3
%39 = load i32*, i32** %38
%40 = getelementptr inbounds i32, i32* %39, i64 8
store i32* %40, i32** %38
ret void
}

LLVM IR (-O2):
define void @serial_uint64(i32** nocapture %0, i32* %1) {
%3 = alloca i32*
%4 = alloca [8 x i32]
store i32* %1, i32** %3
%5 = tail call i64 @htonl(i32 1)
%6 = icmp eq i64 %5, 1
%7 = ptrtoint i32* %1 to i64
br i1 %6, label %8, label %11
8: ; preds = %2
%9 = load i32*, i32** %0
%10 = call i32 @memcpy(i32* %9, i32** %3, i32 8)
br label %21
11: ; preds = %2
%12 = trunc i64 %7 to i32
%13 = lshr i64 %7, 32
%14 = trunc i64 %13 to i32
%15 = bitcast [8 x i32]* %4 to i8*
%16 = getelementptr inbounds [8 x i32], [8 x i32]* %4, i64 0, i64 6
store i32 %14, i32* %16
%17 = getelementptr inbounds [8 x i32], [8 x i32]* %4, i64 0, i64 7
store i32 %12, i32* %17
%18 = load i32*, i32** %0
%19 = bitcast [8 x i32]* %4 to i32**
%20 = call i32 @memcpy(i32* %18, i32** %19, i32 8)
br label %21
21: ; preds = %11, %8
%22 = load i32*, i32** %0
%23 = getelementptr inbounds i32, i32* %22, i64 8
store i32* %23, i32** %0
ret void
}