#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 */
void rev32(uint32_t *x) {
  *x = ((*x) & 0x55555555) << 1 | ((*x) & 0xAAAAAAAA) >> 1;
  *x = ((*x) & 0x33333333) << 2 | ((*x) & 0xCCCCCCCC) >> 2;
  *x = ((*x) & 0x0F0F0F0F) << 4 | ((*x) & 0xF0F0F0F0) >> 4;
  *x = ((*x) & 0x00FF00FF) << 8 | ((*x) & 0xFF00FF00) >> 8;
  *x = ((*x) & 0x0000FFFF) << 16 | ((*x) & 0xFFFF0000) >> 16;
}


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

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

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

LLVM IR (-O2):
define void @rev32(i32* nocapture %0) {
%2 = load i32, i32* %0
%3 = tail call i32 @llvm.bitreverse.i32(i32 %2)
store i32 %3, i32* %0
ret void
}