#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 scalar_t__ uint8_t;
typedef int const uint64_t;

/* Variables and functions */
int /*<<< orphan*/ ndm_endian_is_le();
uint64_t ndm_endian_betoh64(const uint64_t x) {
  if (!ndm_endian_is_le()) {
    return x;
  }
  const uint8_t *p = (const uint8_t *)&x;
  return (
      uint64_t)(((uint64_t) * (p + 7)) << 0 | ((uint64_t) * (p + 6)) << 8 |
                ((uint64_t) * (p + 5)) << 16 | ((uint64_t) * (p + 4)) << 24 |
                ((uint64_t) * (p + 3)) << 32 | ((uint64_t) * (p + 2)) << 40 |
                ((uint64_t) * (p + 1)) << 48 | ((uint64_t) * (p + 0)) << 56);
}


x86 assembly (clang, -O0):
<ndm_endian_betoh64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    $0x0,%al
call   1030 <ndm_endian_is_le@plt>
cmp    $0x0,%eax
jne    1136 <ndm_endian_betoh64+0x26>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c6 <ndm_endian_betoh64+0xb6>
lea    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x38(%rax),%rax
shl    $0x0,%eax
mov    -0x10(%rbp),%rcx
mov    0x30(%rcx),%rcx
shl    $0x8,%ecx
or     %ecx,%eax
mov    -0x10(%rbp),%rcx
mov    0x28(%rcx),%rcx
shl    $0x10,%ecx
or     %ecx,%eax
mov    -0x10(%rbp),%rcx
mov    0x20(%rcx),%rcx
shl    $0x18,%ecx
or     %ecx,%eax
mov    -0x10(%rbp),%rcx
mov    0x18(%rcx),%rcx
mov    %ecx,%edx
mov    $0x20,%ecx
shl    %cl,%edx
mov    %edx,%ecx
or     %ecx,%eax
mov    -0x10(%rbp),%rcx
mov    0x10(%rcx),%rcx
mov    %ecx,%edx
mov    $0x28,%ecx
shl    %cl,%edx
mov    %edx,%ecx
or     %ecx,%eax
mov    -0x10(%rbp),%rcx
mov    0x8(%rcx),%rcx
mov    %ecx,%edx
mov    $0x30,%ecx
shl    %cl,%edx
mov    %edx,%ecx
or     %ecx,%eax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%rcx
mov    %ecx,%edx
mov    $0x38,%ecx
shl    %cl,%edx
mov    %edx,%ecx
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ndm_endian_betoh64>:
push   %rbx
mov    %edi,%ebx
xor    %eax,%eax
call   1030 <ndm_endian_is_le@plt>
mov    %ebx,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
define i32 @ndm_endian_betoh64(i32 returned %0) {
%2 = tail call i32 (...) @ndm_endian_is_le()
ret i32 %0
}