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

/* Variables and functions */
u_int32_t bitreverse(u_int32_t x) {
  u_int32_t m;
  x = (x >> 16) | (x << 16);
  m = 0xff00ff00;
  x = ((x & m) >> 8) | ((x & ~m) << 8);
  m = 0xf0f0f0f0;
  x = ((x & m) >> 4) | ((x & ~m) << 4);
  m = 0xcccccccc;
  x = ((x & m) >> 2) | ((x & ~m) << 2);
  m = 0xaaaaaaaa;
  x = ((x & m) >> 1) | ((x & ~m) << 1);
  return x;
}


x86 assembly (clang, -O0):
<bitreverse>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x10,%eax
mov    -0x4(%rbp),%ecx
shl    $0x10,%ecx
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
movl   $0xff00ff00,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    -0x8(%rbp),%eax
sar    $0x8,%eax
mov    -0x4(%rbp),%ecx
mov    -0x8(%rbp),%edx
xor    $0xffffffff,%edx
and    %edx,%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
movl   $0xf0f0f0f0,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    -0x8(%rbp),%eax
sar    $0x4,%eax
mov    -0x4(%rbp),%ecx
mov    -0x8(%rbp),%edx
xor    $0xffffffff,%edx
and    %edx,%ecx
shl    $0x4,%ecx
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
movl   $0xcccccccc,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    -0x8(%rbp),%eax
sar    $0x2,%eax
mov    -0x4(%rbp),%ecx
mov    -0x8(%rbp),%edx
xor    $0xffffffff,%edx
and    %edx,%ecx
shl    $0x2,%ecx
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
movl   $0xaaaaaaaa,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    -0x8(%rbp),%eax
sar    $0x1,%eax
mov    -0x4(%rbp),%ecx
mov    -0x8(%rbp),%edx
xor    $0xffffffff,%edx
and    %edx,%ecx
shl    $0x1,%ecx
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<bitreverse>:
mov    %edi,%eax
sar    $0x10,%eax
shl    $0x10,%edi
or     %edi,%eax
mov    %eax,%ecx
sar    $0x8,%ecx
and    $0xffff00ff,%ecx
shl    $0x8,%eax
and    $0xff00ff00,%eax
or     %ecx,%eax
mov    %eax,%ecx
sar    $0x4,%ecx
and    $0xff0f0f0f,%ecx
shl    $0x4,%eax
and    $0xf0f0f0f0,%eax
or     %ecx,%eax
mov    %eax,%ecx
sar    $0x2,%ecx
and    $0xf3333333,%ecx
shl    $0x2,%eax
and    $0xcccccccc,%eax
or     %ecx,%eax
mov    %eax,%ecx
sar    %ecx
and    $0xd5555555,%ecx
add    %eax,%eax
and    $0xaaaaaaaa,%eax
or     %ecx,%eax
ret

LLVM IR (-O0):
define i32 @bitreverse(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = ashr i32 %4, 16
%6 = load i32, i32* %2
%7 = shl i32 %6, 16
%8 = or i32 %5, %7
store i32 %8, i32* %2
store i32 -16711936, i32* %3
%9 = load i32, i32* %2
%10 = load i32, i32* %3
%11 = and i32 %9, %10
%12 = ashr i32 %11, 8
%13 = load i32, i32* %2
%14 = load i32, i32* %3
%15 = xor i32 %14, -1
%16 = and i32 %13, %15
%17 = shl i32 %16, 8
%18 = or i32 %12, %17
store i32 %18, i32* %2
store i32 -252645136, i32* %3
%19 = load i32, i32* %2
%20 = load i32, i32* %3
%21 = and i32 %19, %20
%22 = ashr i32 %21, 4
%23 = load i32, i32* %2
%24 = load i32, i32* %3
%25 = xor i32 %24, -1
%26 = and i32 %23, %25
%27 = shl i32 %26, 4
%28 = or i32 %22, %27
store i32 %28, i32* %2
store i32 -858993460, i32* %3
%29 = load i32, i32* %2
%30 = load i32, i32* %3
%31 = and i32 %29, %30
%32 = ashr i32 %31, 2
%33 = load i32, i32* %2
%34 = load i32, i32* %3
%35 = xor i32 %34, -1
%36 = and i32 %33, %35
%37 = shl i32 %36, 2
%38 = or i32 %32, %37
store i32 %38, i32* %2
store i32 -1431655766, i32* %3
%39 = load i32, i32* %2
%40 = load i32, i32* %3
%41 = and i32 %39, %40
%42 = ashr i32 %41, 1
%43 = load i32, i32* %2
%44 = load i32, i32* %3
%45 = xor i32 %44, -1
%46 = and i32 %43, %45
%47 = shl i32 %46, 1
%48 = or i32 %42, %47
store i32 %48, i32* %2
%49 = load i32, i32* %2
ret i32 %49
}

LLVM IR (-O2):
define i32 @bitreverse(i32 %0) {
%2 = ashr i32 %0, 16
%3 = shl i32 %0, 16
%4 = or i32 %2, %3
%5 = ashr i32 %4, 8
%6 = and i32 %5, -65281
%7 = shl i32 %4, 8
%8 = and i32 %7, -16711936
%9 = or i32 %6, %8
%10 = ashr i32 %9, 4
%11 = and i32 %10, -15790321
%12 = shl i32 %9, 4
%13 = and i32 %12, -252645136
%14 = or i32 %11, %13
%15 = ashr i32 %14, 2
%16 = and i32 %15, -214748365
%17 = shl i32 %14, 2
%18 = and i32 %17, -858993460
%19 = or i32 %16, %18
%20 = ashr i32 %19, 1
%21 = and i32 %20, -715827883
%22 = shl i32 %19, 1
%23 = and i32 %22, -1431655766
%24 = or i32 %21, %23
ret i32 %24
}