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

/* Variables and functions */
scalar_t__ tracecmd_host_bigendian();
unsigned long long be64_to_cpu(unsigned long long val) {
  unsigned long long swap;
  if (tracecmd_host_bigendian())
    return val;
  swap = ((val & 0xffULL) << 56) | ((val & (0xffULL << 8)) << 40) |
         ((val & (0xffULL << 16)) << 24) | ((val & (0xffULL << 24)) << 8) |
         ((val & (0xffULL << 32)) >> 8) | ((val & (0xffULL << 40)) >> 24) |
         ((val & (0xffULL << 48)) >> 40) | ((val & (0xffULL << 56)) >> 56);
  return swap;
}


x86 assembly (clang, -O0):
<be64_to_cpu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1030 <tracecmd_host_bigendian@plt>
cmp    $0x0,%rax
je     113a <be64_to_cpu+0x2a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11e1 <be64_to_cpu+0xd1>
mov    -0x10(%rbp),%rax
and    $0xff,%rax
shl    $0x38,%rax
mov    -0x10(%rbp),%rcx
and    $0xff00,%rcx
shl    $0x28,%rcx
or     %rcx,%rax
mov    -0x10(%rbp),%rcx
and    $0xff0000,%rcx
shl    $0x18,%rcx
or     %rcx,%rax
movabs $0xff000000,%rcx
and    -0x10(%rbp),%rcx
shl    $0x8,%rcx
or     %rcx,%rax
movabs $0xff00000000,%rcx
and    -0x10(%rbp),%rcx
shr    $0x8,%rcx
or     %rcx,%rax
movabs $0xff0000000000,%rcx
and    -0x10(%rbp),%rcx
shr    $0x18,%rcx
or     %rcx,%rax
movabs $0xff000000000000,%rcx
and    -0x10(%rbp),%rcx
shr    $0x28,%rcx
or     %rcx,%rax
movabs $0xff00000000000000,%rcx
and    -0x10(%rbp),%rcx
shr    $0x38,%rcx
or     %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<be64_to_cpu>:
push   %rbx
mov    %rdi,%rbx
xor    %eax,%eax
call   1030 <tracecmd_host_bigendian@plt>
test   %rax,%rax
mov    %rbx,%rax
bswap  %rax
cmovne %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i64 @be64_to_cpu(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
store i64 %0, i64* %3
%5 = call i64 (...) @tracecmd_host_bigendian()
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = load i64, i64* %3
store i64 %8, i64* %2
br label %42
9: ; preds = %1
%10 = load i64, i64* %3
%11 = and i64 %10, 255
%12 = shl i64 %11, 56
%13 = load i64, i64* %3
%14 = and i64 %13, 65280
%15 = shl i64 %14, 40
%16 = or i64 %12, %15
%17 = load i64, i64* %3
%18 = and i64 %17, 16711680
%19 = shl i64 %18, 24
%20 = or i64 %16, %19
%21 = load i64, i64* %3
%22 = and i64 %21, 4278190080
%23 = shl i64 %22, 8
%24 = or i64 %20, %23
%25 = load i64, i64* %3
%26 = and i64 %25, 1095216660480
%27 = lshr i64 %26, 8
%28 = or i64 %24, %27
%29 = load i64, i64* %3
%30 = and i64 %29, 280375465082880
%31 = lshr i64 %30, 24
%32 = or i64 %28, %31
%33 = load i64, i64* %3
%34 = and i64 %33, 71776119061217280
%35 = lshr i64 %34, 40
%36 = or i64 %32, %35
%37 = load i64, i64* %3
%38 = and i64 %37, -72057594037927936
%39 = lshr i64 %38, 56
%40 = or i64 %36, %39
store i64 %40, i64* %4
%41 = load i64, i64* %4
store i64 %41, i64* %2
br label %42
42: ; preds = %9, %7
%43 = load i64, i64* %2
ret i64 %43
}

LLVM IR (-O2):
define i64 @be64_to_cpu(i64 %0) {
%2 = tail call i64 (...) @tracecmd_host_bigendian()
%3 = icmp eq i64 %2, 0
%4 = tail call i64 @llvm.bswap.i64(i64 %0)
%5 = select i1 %3, i64 %4, i64 %0
ret i64 %5
}