#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*/ int64_t;

/* Variables and functions */
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char const *, int);
scalar_t__ utilIsLittleEndian();
int64_t utilReadInt64(const unsigned char *buf) {
  int64_t i;
  if (utilIsLittleEndian()) {
    ((unsigned char *)&i)[0] = buf[7];
    ((unsigned char *)&i)[1] = buf[6];
    ((unsigned char *)&i)[2] = buf[5];
    ((unsigned char *)&i)[3] = buf[4];
    ((unsigned char *)&i)[4] = buf[3];
    ((unsigned char *)&i)[5] = buf[2];
    ((unsigned char *)&i)[6] = buf[1];
    ((unsigned char *)&i)[7] = buf[0];
    return i;
  } else {
    memcpy((unsigned char *)&i, buf, 8);
    return i;
  }
}


x86 assembly (clang, -O0):
<utilReadInt64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <utilIsLittleEndian@plt>
cmp    $0x0,%rax
je     1197 <utilReadInt64+0x77>
mov    -0x10(%rbp),%rax
mov    0x7(%rax),%al
mov    %al,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x6(%rax),%al
mov    %al,-0x13(%rbp)
mov    -0x10(%rbp),%rax
mov    0x5(%rax),%al
mov    %al,-0x12(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%al
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%rax
mov    0x3(%rax),%al
mov    %al,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2(%rax),%al
mov    %al,-0xf(%rbp)
mov    -0x10(%rbp),%rax
mov    0x1(%rax),%al
mov    %al,-0xe(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,-0xd(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11af <utilReadInt64+0x8f>
lea    -0x14(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x8,%edx
call   1030 <memcpy@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<utilReadInt64>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
xor    %eax,%eax
call   1040 <utilIsLittleEndian@plt>
test   %rax,%rax
je     1152 <utilReadInt64+0x32>
mov    0x7(%rbx),%al
mov    %al,0xc(%rsp)
mov    0x6(%rbx),%al
mov    %al,0xd(%rsp)
mov    0x5(%rbx),%al
mov    %al,0xe(%rsp)
mov    0x4(%rbx),%al
mov    %al,0xf(%rsp)
jmp    1164 <utilReadInt64+0x44>
lea    0xc(%rsp),%rdi
mov    %rbx,%rsi
mov    $0x8,%edx
call   1030 <memcpy@plt>
mov    0xc(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @utilReadInt64(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = call i64 (...) @utilIsLittleEndian()
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %49
7: ; preds = %1
%8 = load i8*, i8** %3
%9 = getelementptr inbounds i8, i8* %8, i64 7
%10 = load i8, i8* %9
%11 = bitcast i32* %4 to i8*
%12 = getelementptr inbounds i8, i8* %11, i64 0
store i8 %10, i8* %12
%13 = load i8*, i8** %3
%14 = getelementptr inbounds i8, i8* %13, i64 6
%15 = load i8, i8* %14
%16 = bitcast i32* %4 to i8*
%17 = getelementptr inbounds i8, i8* %16, i64 1
store i8 %15, i8* %17
%18 = load i8*, i8** %3
%19 = getelementptr inbounds i8, i8* %18, i64 5
%20 = load i8, i8* %19
%21 = bitcast i32* %4 to i8*
%22 = getelementptr inbounds i8, i8* %21, i64 2
store i8 %20, i8* %22
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i64 4
%25 = load i8, i8* %24
%26 = bitcast i32* %4 to i8*
%27 = getelementptr inbounds i8, i8* %26, i64 3
store i8 %25, i8* %27
%28 = load i8*, i8** %3
%29 = getelementptr inbounds i8, i8* %28, i64 3
%30 = load i8, i8* %29
%31 = bitcast i32* %4 to i8*
%32 = getelementptr inbounds i8, i8* %31, i64 4
store i8 %30, i8* %32
%33 = load i8*, i8** %3
%34 = getelementptr inbounds i8, i8* %33, i64 2
%35 = load i8, i8* %34
%36 = bitcast i32* %4 to i8*
%37 = getelementptr inbounds i8, i8* %36, i64 5
store i8 %35, i8* %37
%38 = load i8*, i8** %3
%39 = getelementptr inbounds i8, i8* %38, i64 1
%40 = load i8, i8* %39
%41 = bitcast i32* %4 to i8*
%42 = getelementptr inbounds i8, i8* %41, i64 6
store i8 %40, i8* %42
%43 = load i8*, i8** %3
%44 = getelementptr inbounds i8, i8* %43, i64 0
%45 = load i8, i8* %44
%46 = bitcast i32* %4 to i8*
%47 = getelementptr inbounds i8, i8* %46, i64 7
store i8 %45, i8* %47
%48 = load i32, i32* %4
store i32 %48, i32* %2
br label %54
49: ; preds = %1
%50 = bitcast i32* %4 to i8*
%51 = load i8*, i8** %3
%52 = call i32 @memcpy(i8* %50, i8* %51, i32 8)
%53 = load i32, i32* %4
store i32 %53, i32* %2
br label %54
54: ; preds = %49, %7
%55 = load i32, i32* %2
ret i32 %55
}

LLVM IR (-O2):
define i32 @utilReadInt64(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i64 (...) @utilIsLittleEndian()
%5 = icmp eq i64 %4, 0
br i1 %5, label %18, label %6
6: ; preds = %1
%7 = getelementptr inbounds i8, i8* %0, i64 7
%8 = load i8, i8* %7
store i8 %8, i8* %3
%9 = getelementptr inbounds i8, i8* %0, i64 6
%10 = load i8, i8* %9
%11 = getelementptr inbounds i8, i8* %3, i64 1
store i8 %10, i8* %11
%12 = getelementptr inbounds i8, i8* %0, i64 5
%13 = load i8, i8* %12
%14 = getelementptr inbounds i8, i8* %3, i64 2
store i8 %13, i8* %14
%15 = getelementptr inbounds i8, i8* %0, i64 4
%16 = load i8, i8* %15
%17 = getelementptr inbounds i8, i8* %3, i64 3
store i8 %16, i8* %17
br label %20
18: ; preds = %1
%19 = call i32 @memcpy(i8* %3, i8* %0, i32 8)
br label %20
20: ; preds = %18, %6
%21 = load i32, i32* %2
ret i32 %21
}