#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 */
unsigned int fhtIntegerLog2(unsigned int);
unsigned int fhtRevBits(unsigned int, unsigned int);
void fhtbitReversalTbl(unsigned *dst, unsigned int n) {
  unsigned int bits = fhtIntegerLog2(n);
  for (unsigned int i = 0; i < n; ++i)
    dst[i] = fhtRevBits(i, bits);
}


x86 assembly (clang, -O0):
<fhtbitReversalTbl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <fhtIntegerLog2@plt>
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    1172 <fhtbitReversalTbl+0x52>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1040 <fhtRevBits@plt>
mov    %eax,%edx
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1141 <fhtbitReversalTbl+0x21>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fhtbitReversalTbl>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
mov    %esi,%edi
call   1030 <fhtIntegerLog2@plt>
test   %ebx,%ebx
je     1157 <fhtbitReversalTbl+0x37>
mov    %eax,%r15d
mov    %ebx,%ebp
xor    %ebx,%ebx
xchg   %ax,%ax
mov    %ebx,%edi
mov    %r15d,%esi
call   1040 <fhtRevBits@plt>
mov    %eax,(%r14,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1140 <fhtbitReversalTbl+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @fhtbitReversalTbl(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%7 = load i32, i32* %4
%8 = call i32 @fhtIntegerLog2(i32 %7)
store i32 %8, i32* %5
store i32 0, i32* %6
br label %9
9: ; preds = %21, %2
%10 = load i32, i32* %6
%11 = load i32, i32* %4
%12 = icmp ult i32 %10, %11
br i1 %12, label %13, label %24
13: ; preds = %9
%14 = load i32, i32* %6
%15 = load i32, i32* %5
%16 = call i32 @fhtRevBits(i32 %14, i32 %15)
%17 = load i32*, i32** %3
%18 = load i32, i32* %6
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds i32, i32* %17, i64 %19
store i32 %16, i32* %20
br label %21
21: ; preds = %13
%22 = load i32, i32* %6
%23 = add i32 %22, 1
store i32 %23, i32* %6
br label %9
24: ; preds = %9
ret void
}

LLVM IR (-O2):
define void @fhtbitReversalTbl(i32* nocapture writeonly %0, i32 %1) {
%3 = tail call i32 @fhtIntegerLog2(i32 %1)
%4 = icmp eq i32 %1, 0
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = zext i32 %1 to i64
br label %8
7: ; preds = %8, %2
ret void
8: ; preds = %5, %8
%9 = phi i64 [ 0, %5 ], [ %13, %8 ]
%10 = trunc i64 %9 to i32
%11 = tail call i32 @fhtRevBits(i32 %10, i32 %3)
%12 = getelementptr inbounds i32, i32* %0, i64 %9
store i32 %11, i32* %12
%13 = add nuw nsw i64 %9, 1
%14 = icmp eq i64 %13, %6
br i1 %14, label %7, label %8
}