#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 swap64(uint64_t x) {
  uint64_t out;
  out =
      (((x & 0xffull) << 56) | (((x & 0xff00ull) >> 8) << 48) |
       (((x & 0xff0000ull) >> 16) << 40) | (((x & 0xff000000ull) >> 24) << 32) |
       (((x & 0xff00000000ull) >> 32) << 24) |
       (((x & 0xff0000000000ull) >> 40) << 16) |
       (((x & 0xff000000000000ull) >> 48) << 8) |
       (((x & 0xff00000000000000ull) >> 56) << 0));
  return out;
}


x86 assembly (clang, -O0):
<swap64>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
movslq -0x4(%rbp),%rax
and    $0xff,%rax
shl    $0x38,%rax
movslq -0x4(%rbp),%rcx
and    $0xff00,%rcx
shr    $0x8,%rcx
shl    $0x30,%rcx
or     %rcx,%rax
movslq -0x4(%rbp),%rcx
and    $0xff0000,%rcx
shr    $0x10,%rcx
shl    $0x28,%rcx
or     %rcx,%rax
movslq -0x4(%rbp),%rcx
movabs $0xff000000,%rdx
and    %rdx,%rcx
shr    $0x18,%rcx
shl    $0x20,%rcx
or     %rcx,%rax
movslq -0x4(%rbp),%rcx
movabs $0xff00000000,%rdx
and    %rdx,%rcx
shr    $0x20,%rcx
shl    $0x18,%rcx
or     %rcx,%rax
movslq -0x4(%rbp),%rcx
movabs $0xff0000000000,%rdx
and    %rdx,%rcx
shr    $0x28,%rcx
shl    $0x10,%rcx
or     %rcx,%rax
movslq -0x4(%rbp),%rcx
movabs $0xff000000000000,%rdx
and    %rdx,%rcx
shr    $0x30,%rcx
shl    $0x8,%rcx
or     %rcx,%rax
movslq -0x4(%rbp),%rcx
movabs $0xff00000000000000,%rdx
and    %rdx,%rcx
shr    $0x38,%rcx
shl    $0x0,%rcx
or     %rcx,%rax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<swap64>:
movslq %edi,%rax
bswap  %rax
ret

LLVM IR (-O0):
define i32 @swap64(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = sext i32 %4 to i64
%6 = and i64 %5, 255
%7 = shl i64 %6, 56
%8 = load i32, i32* %2
%9 = sext i32 %8 to i64
%10 = and i64 %9, 65280
%11 = lshr i64 %10, 8
%12 = shl i64 %11, 48
%13 = or i64 %7, %12
%14 = load i32, i32* %2
%15 = sext i32 %14 to i64
%16 = and i64 %15, 16711680
%17 = lshr i64 %16, 16
%18 = shl i64 %17, 40
%19 = or i64 %13, %18
%20 = load i32, i32* %2
%21 = sext i32 %20 to i64
%22 = and i64 %21, 4278190080
%23 = lshr i64 %22, 24
%24 = shl i64 %23, 32
%25 = or i64 %19, %24
%26 = load i32, i32* %2
%27 = sext i32 %26 to i64
%28 = and i64 %27, 1095216660480
%29 = lshr i64 %28, 32
%30 = shl i64 %29, 24
%31 = or i64 %25, %30
%32 = load i32, i32* %2
%33 = sext i32 %32 to i64
%34 = and i64 %33, 280375465082880
%35 = lshr i64 %34, 40
%36 = shl i64 %35, 16
%37 = or i64 %31, %36
%38 = load i32, i32* %2
%39 = sext i32 %38 to i64
%40 = and i64 %39, 71776119061217280
%41 = lshr i64 %40, 48
%42 = shl i64 %41, 8
%43 = or i64 %37, %42
%44 = load i32, i32* %2
%45 = sext i32 %44 to i64
%46 = and i64 %45, -72057594037927936
%47 = lshr i64 %46, 56
%48 = shl i64 %47, 0
%49 = or i64 %43, %48
%50 = trunc i64 %49 to i32
store i32 %50, i32* %3
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
define i32 @swap64(i32 %0) {
%2 = sext i32 %0 to i64
%3 = tail call i64 @llvm.bswap.i64(i64 %2)
%4 = trunc i64 %3 to i32
ret i32 %4
}