#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 */

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ printf(char *, unsigned int);
unsigned int reverse_bits(int);
int main() {
  unsigned u;
  u = reverse_bits(0x7fffffff);
  assert(u == 0xfffffffe);
  printf("u(%x)\n", u);
  u = reverse_bits(0x00ffffff);
  assert(u == 0xffffff00);
  printf("u(%x)\n", u);
  u = reverse_bits(0xffff00ff);
  assert(u == 0xff00ffff);
  printf("u(%x)\n", u);
  u = reverse_bits(0xffffff00);
  assert(u == 0x00ffffff);
  printf("u(%x)\n", u);
  u = reverse_bits(0xff00ffff);
  assert(u == 0xffff00ff);
  printf("u(%x)\n", u);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x7fffffff,%edi
call   1030 <reverse_bits@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xfffffffe,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%esi
lea    0xe99(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffff,%edi
call   1030 <reverse_bits@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffff00,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%esi
lea    0xe69(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffff00ff,%edi
call   1030 <reverse_bits@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xff00ffff,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%esi
lea    0xe39(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffff00,%edi
call   1030 <reverse_bits@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffff,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%esi
lea    0xe09(%rip),%rdi
call   1040 <printf@plt>
mov    $0xff00ffff,%edi
call   1030 <reverse_bits@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffff00ff,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%esi
lea    0xdd9(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    $0x7fffffff,%edi
call   1030 <reverse_bits@plt>
mov    %eax,%ebp
xor    %edi,%edi
cmp    $0xfffffffe,%eax
sete   %dil
call   1050 <assert@plt>
lea    0xeac(%rip),%rbx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
mov    $0xffffff,%edi
call   1030 <reverse_bits@plt>
mov    %eax,%ebp
xor    %edi,%edi
cmp    $0xffffff00,%eax
sete   %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
mov    $0xffff00ff,%edi
call   1030 <reverse_bits@plt>
mov    %eax,%ebp
xor    %edi,%edi
cmp    $0xff00ffff,%eax
sete   %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
mov    $0xffffff00,%edi
call   1030 <reverse_bits@plt>
mov    %eax,%ebp
xor    %edi,%edi
cmp    $0xffffff,%eax
sete   %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
mov    $0xff00ffff,%edi
call   1030 <reverse_bits@plt>
mov    %eax,%ebp
xor    %edi,%edi
cmp    $0xffff00ff,%eax
sete   %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"u(%x)\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 @reverse_bits(i32 2147483647)
store i32 %3, i32* %2
%4 = load i32, i32* %2
%5 = icmp eq i32 %4, -2
%6 = zext i1 %5 to i32
%7 = call i32 @assert(i32 %6)
%8 = load i32, i32* %2
%9 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = call i32 @reverse_bits(i32 16777215)
store i32 %10, i32* %2
%11 = load i32, i32* %2
%12 = icmp eq i32 %11, -256
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load i32, i32* %2
%16 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = call i32 @reverse_bits(i32 -65281)
store i32 %17, i32* %2
%18 = load i32, i32* %2
%19 = icmp eq i32 %18, -16711681
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
%22 = load i32, i32* %2
%23 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %22)
%24 = call i32 @reverse_bits(i32 -256)
store i32 %24, i32* %2
%25 = load i32, i32* %2
%26 = icmp eq i32 %25, 16777215
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
%29 = load i32, i32* %2
%30 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %29)
%31 = call i32 @reverse_bits(i32 -16711681)
store i32 %31, i32* %2
%32 = load i32, i32* %2
%33 = icmp eq i32 %32, -65281
%34 = zext i1 %33 to i32
%35 = call i32 @assert(i32 %34)
%36 = load i32, i32* %2
%37 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %36)
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"u(%x)\0A\00"
define i32 @main() {
%1 = tail call i32 @reverse_bits(i32 2147483647)
%2 = icmp eq i32 %1, -2
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
%5 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %1)
%6 = tail call i32 @reverse_bits(i32 16777215)
%7 = icmp eq i32 %6, -256
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %6)
%11 = tail call i32 @reverse_bits(i32 -65281)
%12 = icmp eq i32 %11, -16711681
%13 = zext i1 %12 to i32
%14 = tail call i32 @assert(i32 %13)
%15 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %11)
%16 = tail call i32 @reverse_bits(i32 -256)
%17 = icmp eq i32 %16, 16777215
%18 = zext i1 %17 to i32
%19 = tail call i32 @assert(i32 %18)
%20 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %16)
%21 = tail call i32 @reverse_bits(i32 -16711681)
%22 = icmp eq i32 %21, -65281
%23 = zext i1 %22 to i32
%24 = tail call i32 @assert(i32 %23)
%25 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %21)
ret i32 0
}