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

/* Variables and functions */
int /*<<< orphan*/ host_is_little_endian();
uint64_t cpu_to_be64(uint64_t v) {
  unsigned char *x, *y;
  uint64_t answer;
  if (!host_is_little_endian())
    return v;
  x = (unsigned char *)&v;
  y = (unsigned char *)&answer;
  y[0] = x[7];
  y[1] = x[6];
  y[2] = x[5];
  y[3] = x[4];
  y[4] = x[3];
  y[5] = x[2];
  y[6] = x[1];
  y[7] = x[0];
  return answer;
}


x86 assembly (clang, -O0):
<cpu_to_be64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    $0x0,%al
call   1030 <host_is_little_endian@plt>
cmp    $0x0,%eax
jne    1136 <cpu_to_be64+0x26>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ba <cpu_to_be64+0xaa>
lea    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    -0x1c(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x7(%rax),%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
mov    0x6(%rax),%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x10(%rbp),%rax
mov    0x5(%rax),%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x3(%rax)
mov    -0x10(%rbp),%rax
mov    0x3(%rax),%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x4(%rax)
mov    -0x10(%rbp),%rax
mov    0x2(%rax),%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x5(%rax)
mov    -0x10(%rbp),%rax
mov    0x1(%rax),%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x6(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x7(%rax)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

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

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

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