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

/* Variables and functions */
uint32_t reverseBits_fast(uint32_t n) {
  uint32_t result = 0;
  uint32_t masks[] = {
      0x00000001, 0x00000002, 0x00000004, 0x00000008, 0x00000010, 0x00000020,
      0x00000040, 0x00000080, 0x00000100, 0x00000200, 0x00000400, 0x00000800,
      0x00001000, 0x00002000, 0x00004000, 0x00008000, 0x00010000, 0x00020000,
      0x00040000, 0x00080000, 0x00100000, 0x00200000, 0x00400000, 0x00800000,
      0x01000000, 0x02000000, 0x04000000, 0x08000000, 0x10000000, 0x20000000,
      0x40000000, 0x80000000};
  int i;
  for (i = 0; i < 32; i++) {
    if ((n & masks[i]))
      result |= masks[31 - i];
  }
  return result;
}


x86 assembly (clang, -O0):
<reverseBits_fast>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    -0x90(%rbp),%rdi
lea    0xecd(%rip),%rsi
mov    $0x80,%edx
call   1030 <memcpy@plt>
movl   $0x0,-0x94(%rbp)
cmpl   $0x20,-0x94(%rbp)
jge    11a1 <reverseBits_fast+0x91>
mov    -0x4(%rbp),%eax
movslq -0x94(%rbp),%rcx
and    -0x90(%rbp,%rcx,4),%eax
cmp    $0x0,%eax
je     1188 <reverseBits_fast+0x78>
mov    $0x1f,%eax
sub    -0x94(%rbp),%eax
cltq
mov    -0x90(%rbp,%rax,4),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    118d <reverseBits_fast+0x7d>
mov    -0x94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
jmp    1147 <reverseBits_fast+0x37>
mov    -0x8(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverseBits_fast>:
xor    %eax,%eax
lea    0xefb(%rip),%rcx
mov    $0x20,%edx
lea    0xeeb(%rip),%rsi
jmp    112a <reverseBits_fast+0x2a>
nopw   0x0(%rax,%rax,1)
add    $0x8,%rcx
add    $0xfffffffffffffffe,%rdx
je     113d <reverseBits_fast+0x3d>
test   %edi,-0x4(%rcx)
je     1133 <reverseBits_fast+0x33>
or     -0x4(%rsi,%rdx,4),%eax
test   %edi,(%rcx)
je     1120 <reverseBits_fast+0x20>
or     -0x8(%rsi,%rdx,4),%eax
jmp    1120 <reverseBits_fast+0x20>
ret

LLVM IR (-O0):
@__const.reverseBits_fast.masks = [32 x i32] [i32 1, i32 2, i32 4, i32 8, i32 16, i32 32, i32 64, i32 128, i32 256, i32 512, i32 1024, i32 2048, i32 4096, i32 8192, i32 16384, i32 32768, i32 65536, i32 131072, i32 262144, i32 524288, i32 1048576, i32 2097152, i32 4194304, i32 8388608, i32 16777216, i32 33554432, i32 67108864, i32 134217728, i32 268435456, i32 536870912, i32 1073741824, i32 -2147483648]
define i32 @reverseBits_fast(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [32 x i32]
%5 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
%6 = bitcast [32 x i32]* %4 to i8*
store i32 0, i32* %5
br label %7
7: ; preds = %27, %1
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 32
br i1 %9, label %10, label %30
10: ; preds = %7
%11 = load i32, i32* %2
%12 = load i32, i32* %5
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [32 x i32], [32 x i32]* %4, i64 0, i64 %13
%15 = load i32, i32* %14
%16 = and i32 %11, %15
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %26
18: ; preds = %10
%19 = load i32, i32* %5
%20 = sub nsw i32 31, %19
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [32 x i32], [32 x i32]* %4, i64 0, i64 %21
%23 = load i32, i32* %22
%24 = load i32, i32* %3
%25 = or i32 %24, %23
store i32 %25, i32* %3
br label %26
26: ; preds = %18, %10
br label %27
27: ; preds = %26
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
store i32 %29, i32* %5
br label %7
30: ; preds = %7
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@__const.reverseBits_fast.masks = [32 x i32] [i32 1, i32 2, i32 4, i32 8, i32 16, i32 32, i32 64, i32 128, i32 256, i32 512, i32 1024, i32 2048, i32 4096, i32 8192, i32 16384, i32 32768, i32 65536, i32 131072, i32 262144, i32 524288, i32 1048576, i32 2097152, i32 4194304, i32 8388608, i32 16777216, i32 33554432, i32 67108864, i32 134217728, i32 268435456, i32 536870912, i32 1073741824, i32 -2147483648]
define i32 @reverseBits_fast(i32 %0) {
br label %2
2: ; preds = %26, %1
%3 = phi i64 [ 0, %1 ], [ %28, %26 ]
%4 = phi i32 [ 0, %1 ], [ %27, %26 ]
%5 = getelementptr inbounds [32 x i32], [32 x i32]* @__const.reverseBits_fast.masks, i64 0, i64 %3
%6 = load i32, i32* %5
%7 = and i32 %6, %0
%8 = icmp eq i32 %7, 0
br i1 %8, label %14, label %9
9: ; preds = %2
%10 = sub nuw nsw i64 31, %3
%11 = getelementptr inbounds [32 x i32], [32 x i32]* @__const.reverseBits_fast.masks, i64 0, i64 %10
%12 = load i32, i32* %11
%13 = or i32 %12, %4
br label %14
14: ; preds = %2, %9
%15 = phi i32 [ %13, %9 ], [ %4, %2 ]
%16 = or i64 %3, 1
%17 = getelementptr inbounds [32 x i32], [32 x i32]* @__const.reverseBits_fast.masks, i64 0, i64 %16
%18 = load i32, i32* %17
%19 = and i32 %18, %0
%20 = icmp eq i32 %19, 0
br i1 %20, label %26, label %21
21: ; preds = %14
%22 = sub nsw i64 30, %3
%23 = getelementptr inbounds [32 x i32], [32 x i32]* @__const.reverseBits_fast.masks, i64 0, i64 %22
%24 = load i32, i32* %23
%25 = or i32 %24, %15
br label %26
26: ; preds = %21, %14
%27 = phi i32 [ %25, %21 ], [ %15, %14 ]
%28 = add nuw nsw i64 %3, 2
%29 = icmp eq i64 %28, 32
br i1 %29, label %30, label %2
30: ; preds = %26
ret i32 %27
}