#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 ReverseBits32(uint32_t val) {
  val = ((val >> 1) & 0x55555555) | ((val << 1) & 0xaaaaaaaa);
  val = ((val >> 2) & 0x33333333) | ((val << 2) & 0xcccccccc);
  val = ((val >> 4) & 0x0f0f0f0f) | ((val << 4) & 0xf0f0f0f0);
  val = ((val >> 8) & 0x00ff00ff) | ((val << 8) & 0xff00ff00);
  val = ((val >> 16) & 0x0000ffff) | ((val << 16) & 0xffff0000);
  return val;
}


x86 assembly (clang, -O0):
<ReverseBits32>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x1,%eax
and    $0x55555555,%eax
mov    -0x4(%rbp),%ecx
shl    $0x1,%ecx
and    $0xaaaaaaaa,%ecx
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x2,%eax
and    $0x33333333,%eax
mov    -0x4(%rbp),%ecx
shl    $0x2,%ecx
and    $0xcccccccc,%ecx
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x4,%eax
and    $0xf0f0f0f,%eax
mov    -0x4(%rbp),%ecx
shl    $0x4,%ecx
and    $0xf0f0f0f0,%ecx
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x8,%eax
and    $0xff00ff,%eax
mov    -0x4(%rbp),%ecx
shl    $0x8,%ecx
and    $0xff00ff00,%ecx
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x10,%eax
and    $0xffff,%eax
mov    -0x4(%rbp),%ecx
shl    $0x10,%ecx
and    $0xffff0000,%ecx
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReverseBits32>:
bswap  %edi
mov    %edi,%eax
and    $0xf0f0f0f,%eax
shl    $0x4,%eax
shr    $0x4,%edi
and    $0xf0f0f0f,%edi
or     %eax,%edi
mov    %edi,%eax
and    $0x33333333,%eax
shr    $0x2,%edi
and    $0x33333333,%edi
lea    (%rdi,%rax,4),%eax
mov    %eax,%ecx
and    $0x55555555,%ecx
shr    %eax
and    $0x55555555,%eax
lea    (%rax,%rcx,2),%eax
ret

LLVM IR (-O0):
define i32 @ReverseBits32(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = ashr i32 %3, 1
%5 = and i32 %4, 1431655765
%6 = load i32, i32* %2
%7 = shl i32 %6, 1
%8 = and i32 %7, -1431655766
%9 = or i32 %5, %8
store i32 %9, i32* %2
%10 = load i32, i32* %2
%11 = ashr i32 %10, 2
%12 = and i32 %11, 858993459
%13 = load i32, i32* %2
%14 = shl i32 %13, 2
%15 = and i32 %14, -858993460
%16 = or i32 %12, %15
store i32 %16, i32* %2
%17 = load i32, i32* %2
%18 = ashr i32 %17, 4
%19 = and i32 %18, 252645135
%20 = load i32, i32* %2
%21 = shl i32 %20, 4
%22 = and i32 %21, -252645136
%23 = or i32 %19, %22
store i32 %23, i32* %2
%24 = load i32, i32* %2
%25 = ashr i32 %24, 8
%26 = and i32 %25, 16711935
%27 = load i32, i32* %2
%28 = shl i32 %27, 8
%29 = and i32 %28, -16711936
%30 = or i32 %26, %29
store i32 %30, i32* %2
%31 = load i32, i32* %2
%32 = ashr i32 %31, 16
%33 = and i32 %32, 65535
%34 = load i32, i32* %2
%35 = shl i32 %34, 16
%36 = and i32 %35, -65536
%37 = or i32 %33, %36
store i32 %37, i32* %2
%38 = load i32, i32* %2
ret i32 %38
}

LLVM IR (-O2):
define i32 @ReverseBits32(i32 %0) {
%2 = tail call i32 @llvm.bitreverse.i32(i32 %0)
ret i32 %2
}