#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 */
unsigned long long UINT64_C(int);
unsigned long long reverse_bits(unsigned long long x) {
  x = ((x & UINT64_C(0x0f0f0f0f0f0f0f0f)) << 4) |
      ((x & UINT64_C(0xf0f0f0f0f0f0f0f0)) >> 4);
  x = ((x & UINT64_C(0x3333333333333333)) << 2) |
      ((x & UINT64_C(0xcccccccccccccccc)) >> 2);
  x = ((x & UINT64_C(0x5555555555555555)) << 1) |
      ((x & UINT64_C(0xaaaaaaaaaaaaaaaa)) >> 1);
  return x;
}


x86 assembly (clang, -O0):
<reverse_bits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    $0xf0f0f0f,%edi
call   1030 <UINT64_C@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
and    %rcx,%rax
shl    $0x4,%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    $0xf0f0f0f0,%edi
call   1030 <UINT64_C@plt>
mov    -0x48(%rbp),%rcx
mov    %rax,%rdx
mov    -0x40(%rbp),%rax
and    %rdx,%rcx
shr    $0x4,%rcx
or     %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    $0x33333333,%edi
call   1030 <UINT64_C@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
and    %rcx,%rax
shl    $0x2,%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    $0xcccccccc,%edi
call   1030 <UINT64_C@plt>
mov    -0x30(%rbp),%rcx
mov    %rax,%rdx
mov    -0x28(%rbp),%rax
and    %rdx,%rcx
shr    $0x2,%rcx
or     %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    $0x55555555,%edi
call   1030 <UINT64_C@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
and    %rcx,%rax
shl    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    $0xaaaaaaaa,%edi
call   1030 <UINT64_C@plt>
mov    -0x18(%rbp),%rcx
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
and    %rdx,%rcx
shr    $0x1,%rcx
or     %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse_bits>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    $0xf0f0f0f,%edi
call   1030 <UINT64_C@plt>
mov    %rax,%r15
and    %r14,%r15
shl    $0x4,%r15
mov    $0xf0f0f0f0,%edi
call   1030 <UINT64_C@plt>
mov    %rax,%rbx
and    %r14,%rbx
shr    $0x4,%rbx
or     %r15,%rbx
mov    $0x33333333,%edi
call   1030 <UINT64_C@plt>
mov    %rax,%r14
and    %rbx,%r14
shl    $0x2,%r14
mov    $0xcccccccc,%edi
call   1030 <UINT64_C@plt>
mov    %rax,%r15
and    %rbx,%r15
shr    $0x2,%r15
or     %r14,%r15
mov    $0x55555555,%edi
call   1030 <UINT64_C@plt>
mov    %rax,%rbx
and    %r15,%rbx
add    %rbx,%rbx
mov    $0xaaaaaaaa,%edi
call   1030 <UINT64_C@plt>
and    %r15,%rax
shr    %rax
or     %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @reverse_bits(i64 %0) {
%2 = alloca i64
store i64 %0, i64* %2
%3 = load i64, i64* %2
%4 = call i64 @UINT64_C(i32 252645135)
%5 = and i64 %3, %4
%6 = shl i64 %5, 4
%7 = load i64, i64* %2
%8 = call i64 @UINT64_C(i32 -252645136)
%9 = and i64 %7, %8
%10 = lshr i64 %9, 4
%11 = or i64 %6, %10
store i64 %11, i64* %2
%12 = load i64, i64* %2
%13 = call i64 @UINT64_C(i32 858993459)
%14 = and i64 %12, %13
%15 = shl i64 %14, 2
%16 = load i64, i64* %2
%17 = call i64 @UINT64_C(i32 -858993460)
%18 = and i64 %16, %17
%19 = lshr i64 %18, 2
%20 = or i64 %15, %19
store i64 %20, i64* %2
%21 = load i64, i64* %2
%22 = call i64 @UINT64_C(i32 1431655765)
%23 = and i64 %21, %22
%24 = shl i64 %23, 1
%25 = load i64, i64* %2
%26 = call i64 @UINT64_C(i32 -1431655766)
%27 = and i64 %25, %26
%28 = lshr i64 %27, 1
%29 = or i64 %24, %28
store i64 %29, i64* %2
%30 = load i64, i64* %2
ret i64 %30
}

LLVM IR (-O2):
define i64 @reverse_bits(i64 %0) {
%2 = tail call i64 @UINT64_C(i32 252645135)
%3 = and i64 %2, %0
%4 = shl i64 %3, 4
%5 = tail call i64 @UINT64_C(i32 -252645136)
%6 = and i64 %5, %0
%7 = lshr i64 %6, 4
%8 = or i64 %7, %4
%9 = tail call i64 @UINT64_C(i32 858993459)
%10 = and i64 %8, %9
%11 = shl i64 %10, 2
%12 = tail call i64 @UINT64_C(i32 -858993460)
%13 = and i64 %8, %12
%14 = lshr i64 %13, 2
%15 = or i64 %11, %14
%16 = tail call i64 @UINT64_C(i32 1431655765)
%17 = and i64 %15, %16
%18 = shl i64 %17, 1
%19 = tail call i64 @UINT64_C(i32 -1431655766)
%20 = and i64 %15, %19
%21 = lshr i64 %20, 1
%22 = or i64 %18, %21
ret i64 %22
}