#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 reverse(uint32_t x) {
  x = ((x & 0x55555555) << 1) | ((x >> 1) & 0x55555555);
  x = ((x & 0x33333333) << 2) | ((x >> 2) & 0x33333333);
  x = ((x & 0x0F0F0F0F) << 4) | ((x >> 4) & 0x0F0F0F0F);
  x = (x << 24) | ((x & 0xFF00) << 8) | ((x >> 8) & 0xFF00) | (x >> 24);
  return x;
}


x86 assembly (clang, -O0):
<reverse>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
and    $0x55555555,%eax
shl    $0x1,%eax
mov    -0x4(%rbp),%ecx
sar    $0x1,%ecx
and    $0x55555555,%ecx
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
and    $0x33333333,%eax
shl    $0x2,%eax
mov    -0x4(%rbp),%ecx
sar    $0x2,%ecx
and    $0x33333333,%ecx
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
and    $0xf0f0f0f,%eax
shl    $0x4,%eax
mov    -0x4(%rbp),%ecx
sar    $0x4,%ecx
and    $0xf0f0f0f,%ecx
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
shl    $0x18,%eax
mov    -0x4(%rbp),%ecx
and    $0xff00,%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    -0x4(%rbp),%ecx
sar    $0x8,%ecx
and    $0xff00,%ecx
or     %ecx,%eax
mov    -0x4(%rbp),%ecx
sar    $0x18,%ecx
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse>:
mov    %edi,%eax
and    $0xd5555555,%eax
mov    %edi,%ecx
shr    %ecx
and    $0x55555555,%ecx
lea    (%rcx,%rax,2),%eax
mov    %eax,%ecx
and    $0xf3333333,%ecx
shr    $0x2,%eax
and    $0x33333333,%eax
lea    (%rax,%rcx,4),%eax
mov    %eax,%ecx
shl    $0x4,%ecx
and    $0xf0000000,%ecx
shr    $0x4,%eax
or     %ecx,%eax
bswap  %edi
mov    %edi,%ecx
and    $0xf0f0f0f,%ecx
shl    $0x4,%ecx
shr    $0x4,%edi
and    $0xf0f0f0f,%edi
or     %ecx,%edi
mov    %edi,%ecx
and    $0x33333333,%ecx
shr    $0x2,%edi
and    $0x33333333,%edi
lea    (%rdi,%rcx,4),%ecx
mov    %ecx,%edx
and    $0x55555500,%edx
shr    %ecx
and    $0x55555500,%ecx
lea    (%rcx,%rdx,2),%ecx
sar    $0x18,%eax
or     %ecx,%eax
ret

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

LLVM IR (-O2):
define i32 @reverse(i32 %0) {
%2 = shl i32 %0, 1
%3 = and i32 %2, -1431655766
%4 = lshr i32 %0, 1
%5 = and i32 %4, 1431655765
%6 = or i32 %3, %5
%7 = shl i32 %6, 2
%8 = and i32 %7, -858993460
%9 = lshr i32 %6, 2
%10 = and i32 %9, 858993459
%11 = or i32 %8, %10
%12 = shl i32 %11, 4
%13 = and i32 %12, -268435456
%14 = lshr i32 %11, 4
%15 = or i32 %13, %14
%16 = tail call i32 @llvm.bitreverse.i32(i32 %0)
%17 = and i32 %16, -256
%18 = ashr i32 %15, 24
%19 = or i32 %18, %17
ret i32 %19
}