#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);
uint64_t unserial_uint64(uint8_t **const ptr) {
  uint64_t v;
  if (htonl(1) == 1L) {
    memcpy(&v, *ptr, sizeof(uint64_t));
  } else {
    int i;
    uint8_t rv[sizeof(uint64_t)];
    uint8_t *pv = (uint8_t *)&v;
    memcpy(&v, *ptr, sizeof(uint64_t));
    for (i = 0; i < 8; i++) {
      rv[i] = pv[7 - i];
    }
    memcpy(&v, &rv, sizeof(uint64_t));
  }
  *ptr += sizeof(uint64_t);
  return v;
}


x86 assembly (clang, -O0):
<unserial_uint64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x1,%edi
call   1030 <htonl@plt>
cmp    $0x1,%rax
jne    115a <unserial_uint64+0x3a>
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
lea    -0xc(%rbp),%rdi
mov    $0x4,%edx
call   1040 <memcpy@plt>
jmp    11c4 <unserial_uint64+0xa4>
lea    -0xc(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
lea    -0xc(%rbp),%rdi
mov    $0x4,%edx
call   1040 <memcpy@plt>
movl   $0x0,-0x10(%rbp)
cmpl   $0x8,-0x10(%rbp)
jge    11b2 <unserial_uint64+0x92>
mov    -0x38(%rbp),%rax
mov    $0x7,%ecx
sub    -0x10(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rcx
movslq -0x10(%rbp),%rax
mov    %rcx,-0x30(%rbp,%rax,8)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    117e <unserial_uint64+0x5e>
lea    -0x30(%rbp),%rsi
lea    -0xc(%rbp),%rdi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0x20,%rcx
mov    %rcx,(%rax)
mov    -0xc(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unserial_uint64>:
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    %rdi,%rbx
mov    $0x1,%edi
call   1030 <htonl@plt>
cmp    $0x1,%rax
jne    1144 <unserial_uint64+0x24>
mov    (%rbx),%rsi
lea    0x8(%rsp),%rdi
jmp    118e <unserial_uint64+0x6e>
mov    (%rbx),%rsi
lea    0x8(%rsp),%r14
mov    %r14,%rdi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    0x8(%rsp),%rax
mov    %rax,0x10(%rsp)
mov    %rax,0x18(%rsp)
mov    %rax,0x20(%rsp)
mov    %rax,0x28(%rsp)
mov    %rax,0x30(%rsp)
mov    %rax,0x38(%rsp)
mov    %rax,0x40(%rsp)
mov    %rax,0x48(%rsp)
lea    0x10(%rsp),%rsi
mov    %r14,%rdi
mov    $0x4,%edx
call   1040 <memcpy@plt>
addq   $0x20,(%rbx)
mov    0x8(%rsp),%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

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

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