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

/* Variables and functions */
int64_t reverseBits_fun_int64_t(int64_t x) {
  int64_t r = x;
  int i = 63;
  for (x = x >> 1 & 0x7fffffffffffffffll; x; x >>= 1) {
    r = (r << 1) | (x & 1);
    --i;
  }
  return r << i;
}


x86 assembly (clang, -O0):
<reverseBits_fun_int64_t>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
movl   $0x3f,-0xc(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x1,%eax
cltq
movabs $0x7fffffffffffffff,%rcx
ff ff 7f
and    %rcx,%rax
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     115e <reverseBits_fun_int64_t+0x5e>
mov    -0x8(%rbp),%eax
shl    $0x1,%eax
mov    -0x4(%rbp),%ecx
and    $0x1,%ecx
or     %ecx,%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    112c <reverseBits_fun_int64_t+0x2c>
mov    -0x8(%rbp),%eax
mov    -0xc(%rbp),%ecx
shl    %cl,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverseBits_fun_int64_t>:
mov    $0x3f,%ecx
cmp    $0x2,%edi
jae    110e <reverseBits_fun_int64_t+0xe>
mov    %edi,%eax
jmp    1134 <reverseBits_fun_int64_t+0x34>
mov    $0x3f,%ecx
mov    %edi,%eax
mov    %edi,%edx
nopw   0x0(%rax,%rax,1)
sar    %edx
mov    %edx,%esi
and    $0x1,%esi
lea    (%rsi,%rax,2),%eax
add    $0xffffffff,%ecx
cmp    $0x3,%edi
mov    %edx,%edi
ja     1120 <reverseBits_fun_int64_t+0x20>
shl    %cl,%eax
ret

LLVM IR (-O0):
define i32 @reverseBits_fun_int64_t(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
store i32 %5, i32* %3
store i32 63, i32* %4
%6 = load i32, i32* %2
%7 = ashr i32 %6, 1
%8 = sext i32 %7 to i64
%9 = and i64 %8, 9223372036854775807
%10 = trunc i64 %9 to i32
store i32 %10, i32* %2
br label %11
11: ; preds = %22, %1
%12 = load i32, i32* %2
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %25
14: ; preds = %11
%15 = load i32, i32* %3
%16 = shl i32 %15, 1
%17 = load i32, i32* %2
%18 = and i32 %17, 1
%19 = or i32 %16, %18
store i32 %19, i32* %3
%20 = load i32, i32* %4
%21 = add nsw i32 %20, -1
store i32 %21, i32* %4
br label %22
22: ; preds = %14
%23 = load i32, i32* %2
%24 = ashr i32 %23, 1
store i32 %24, i32* %2
br label %11
25: ; preds = %11
%26 = load i32, i32* %3
%27 = load i32, i32* %4
%28 = shl i32 %26, %27
ret i32 %28
}

LLVM IR (-O2):
define i32 @reverseBits_fun_int64_t(i32 %0) {
%2 = icmp ult i32 %0, 2
br i1 %2, label %13, label %3
3: ; preds = %1, %3
%4 = phi i32 [ %7, %3 ], [ %0, %1 ]
%5 = phi i32 [ %11, %3 ], [ 63, %1 ]
%6 = phi i32 [ %10, %3 ], [ %0, %1 ]
%7 = ashr i32 %4, 1
%8 = shl i32 %6, 1
%9 = and i32 %7, 1
%10 = or i32 %8, %9
%11 = add nsw i32 %5, -1
%12 = icmp ult i32 %4, 4
br i1 %12, label %13, label %3
13: ; preds = %3, %1
%14 = phi i32 [ %0, %1 ], [ %10, %3 ]
%15 = phi i32 [ 63, %1 ], [ %11, %3 ]
%16 = shl i32 %14, %15
ret i32 %16
}