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

/* Variables and functions */
uint64_t u64_to_be(uint64_t value, int is_be) {
  uint64_t res = 0;
  if (is_be)
    res = value;
  else {
    uint64_t mask = 0xff00000000000000;
    res = ((value & (mask >> 0)) >> 56) | ((value & (mask >> 8)) >> 40) |
          ((value & (mask >> 16)) >> 24) | ((value & (mask >> 24)) >> 8) |
          ((value & (mask >> 32)) << 8) | ((value & (mask >> 40)) << 24) |
          ((value & (mask >> 48)) << 40) | ((value & (mask >> 56)) << 56);
  }
  return res;
}


x86 assembly (clang, -O0):
<u64_to_be>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1126 <u64_to_be+0x26>
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    11e4 <u64_to_be+0xe4>
movl   $0x0,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    -0x10(%rbp),%ecx
sar    $0x0,%ecx
and    %ecx,%eax
mov    $0x38,%ecx
sar    %cl,%eax
mov    -0x4(%rbp),%edx
mov    -0x10(%rbp),%ecx
sar    $0x8,%ecx
and    %ecx,%edx
mov    $0x28,%ecx
sar    %cl,%edx
mov    %edx,%ecx
or     %ecx,%eax
mov    -0x4(%rbp),%ecx
mov    -0x10(%rbp),%edx
sar    $0x10,%edx
and    %edx,%ecx
sar    $0x18,%ecx
or     %ecx,%eax
mov    -0x4(%rbp),%ecx
mov    -0x10(%rbp),%edx
sar    $0x18,%edx
and    %edx,%ecx
sar    $0x8,%ecx
or     %ecx,%eax
mov    -0x4(%rbp),%ecx
mov    %ecx,-0x18(%rbp)
mov    -0x10(%rbp),%edx
mov    $0x20,%ecx
sar    %cl,%edx
mov    -0x18(%rbp),%ecx
and    %edx,%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    -0x4(%rbp),%ecx
mov    %ecx,-0x14(%rbp)
mov    -0x10(%rbp),%edx
mov    $0x28,%ecx
sar    %cl,%edx
mov    -0x14(%rbp),%ecx
and    %edx,%ecx
shl    $0x18,%ecx
or     %ecx,%eax
mov    -0x4(%rbp),%edx
mov    -0x10(%rbp),%esi
mov    $0x30,%ecx
sar    %cl,%esi
mov    %esi,%ecx
and    %ecx,%edx
mov    $0x28,%ecx
shl    %cl,%edx
mov    %edx,%ecx
or     %ecx,%eax
mov    -0x4(%rbp),%edx
mov    -0x10(%rbp),%esi
mov    $0x38,%ecx
sar    %cl,%esi
mov    %esi,%ecx
and    %ecx,%edx
mov    $0x38,%ecx
shl    %cl,%edx
mov    %edx,%ecx
or     %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<u64_to_be>:
mov    %edi,%eax
ret

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

LLVM IR (-O2):
define i32 @u64_to_be(i32 returned %0, i32 %1) {
ret i32 %0
}