#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*/ printf(char *, ...);
void gen_bit_reverse_table(bool header) {
  int i, j;
  if (header)
    printf("extern ");
  printf("const uint8_t bit_reverse_byte [0x100]");
  if (header) {
    printf(";\n");
    return;
  }
  printf(" =\n");
  printf("{\n");
  for (i = 0; i < 0x100; i++) {
    if ((i & 7) == 0)
      printf("  ");
    j = (((i & 0x01) << 7) | ((i & 0x02) << 5) | ((i & 0x04) << 3) |
         ((i & 0x08) << 1) | ((i & 0x10) >> 1) | ((i & 0x20) >> 3) |
         ((i & 0x40) >> 5) | ((i & 0x80) >> 7));
    printf("0x%02x", j);
    if (i != 0xff)
      printf(",");
    if ((i & 7) == 7)
      printf("\n");
    else
      printf(" ");
  }
  printf("};\n");
}


x86 assembly (clang, -O0):
<gen_bit_reverse_table>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     1133 <gen_bit_reverse_table+0x23>
lea    0xed4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xece(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x4(%rbp)
je     115e <gen_bit_reverse_table+0x4e>
lea    0xef1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1284 <gen_bit_reverse_table+0x174>
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x100,-0x8(%rbp)
jge    1276 <gen_bit_reverse_table+0x166>
mov    -0x8(%rbp),%eax
and    $0x7,%eax
cmp    $0x0,%eax
jne    11ab <gen_bit_reverse_table+0x9b>
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
and    $0x1,%eax
shl    $0x7,%eax
mov    -0x8(%rbp),%ecx
and    $0x2,%ecx
shl    $0x5,%ecx
or     %ecx,%eax
mov    -0x8(%rbp),%ecx
and    $0x4,%ecx
shl    $0x3,%ecx
or     %ecx,%eax
mov    -0x8(%rbp),%ecx
and    $0x8,%ecx
shl    $0x1,%ecx
or     %ecx,%eax
mov    -0x8(%rbp),%ecx
and    $0x10,%ecx
sar    $0x1,%ecx
or     %ecx,%eax
mov    -0x8(%rbp),%ecx
and    $0x20,%ecx
sar    $0x3,%ecx
or     %ecx,%eax
mov    -0x8(%rbp),%ecx
and    $0x40,%ecx
sar    $0x5,%ecx
or     %ecx,%eax
mov    -0x8(%rbp),%ecx
and    $0x80,%ecx
sar    $0x7,%ecx
or     %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0xff,-0x8(%rbp)
je     1233 <gen_bit_reverse_table+0x123>
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
and    $0x7,%eax
cmp    $0x7,%eax
jne    1255 <gen_bit_reverse_table+0x145>
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1263 <gen_bit_reverse_table+0x153>
lea    0xddb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1268 <gen_bit_reverse_table+0x158>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1181 <gen_bit_reverse_table+0x71>
lea    0xdc5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_bit_reverse_table>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edi,%edi
je     1178 <gen_bit_reverse_table+0x48>
lea    0xeba(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeb4(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xedd(%rip),%r14
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <puts@plt>
lea    0xe89(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeac(%rip),%rdi
call   1040 <puts@plt>
lea    0xea3(%rip),%rdi
call   1040 <puts@plt>
lea    0xe8a(%rip),%r15
lea    0xe86(%rip),%r13
lea    0xe8b(%rip),%r14
mov    $0xa,%r12d
xor    %ebp,%ebp
jmp    11d0 <gen_bit_reverse_table+0xa0>
nopl   (%rax)
call   1030 <putchar@plt>
add    $0x1,%ebp
cmp    $0x100,%ebp
je     1162 <gen_bit_reverse_table+0x32>
mov    %ebp,%ebx
and    $0x7,%ebx
jne    11e1 <gen_bit_reverse_table+0xb1>
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%eax
rol    $0x4,%al
mov    %eax,%ecx
and    $0x33,%cl
shl    $0x2,%cl
shr    $0x2,%al
and    $0x33,%al
or     %cl,%al
mov    %eax,%ecx
and    $0x55,%cl
add    %cl,%cl
shr    %al
and    $0x55,%al
or     %cl,%al
movzbl %al,%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
cmp    $0xff,%ebp
je     11c0 <gen_bit_reverse_table+0x90>
mov    $0x2c,%edi
call   1030 <putchar@plt>
cmp    $0x7,%ebx
mov    $0x20,%edi
cmove  %r12d,%edi
jmp    11c0 <gen_bit_reverse_table+0x90>

LLVM IR (-O0):
@.str = [8 x i8] c"extern \00"
@.str.1 = [39 x i8] c"const uint8_t bit_reverse_byte [0x100]\00"
@.str.2 = [3 x i8] c";\0A\00"
@.str.3 = [4 x i8] c" =\0A\00"
@.str.4 = [3 x i8] c"{\0A\00"
@.str.5 = [3 x i8] c" \00"
@.str.6 = [7 x i8] c"0x%02x\00"
@.str.7 = [2 x i8] c",\00"
@.str.8 = [2 x i8] c"\0A\00"
@.str.9 = [2 x i8] c" \00"
@.str.10 = [4 x i8] c"};\0A\00"
define void @gen_bit_reverse_table(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = icmp ne i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %1
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
%11 = load i32, i32* %2
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %79
15: ; preds = %9
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
br label %18
18: ; preds = %74, %15
%19 = load i32, i32* %3
%20 = icmp slt i32 %19, 256
br i1 %20, label %21, label %77
21: ; preds = %18
%22 = load i32, i32* %3
%23 = and i32 %22, 7
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %27
27: ; preds = %25, %21
%28 = load i32, i32* %3
%29 = and i32 %28, 1
%30 = shl i32 %29, 7
%31 = load i32, i32* %3
%32 = and i32 %31, 2
%33 = shl i32 %32, 5
%34 = or i32 %30, %33
%35 = load i32, i32* %3
%36 = and i32 %35, 4
%37 = shl i32 %36, 3
%38 = or i32 %34, %37
%39 = load i32, i32* %3
%40 = and i32 %39, 8
%41 = shl i32 %40, 1
%42 = or i32 %38, %41
%43 = load i32, i32* %3
%44 = and i32 %43, 16
%45 = ashr i32 %44, 1
%46 = or i32 %42, %45
%47 = load i32, i32* %3
%48 = and i32 %47, 32
%49 = ashr i32 %48, 3
%50 = or i32 %46, %49
%51 = load i32, i32* %3
%52 = and i32 %51, 64
%53 = ashr i32 %52, 5
%54 = or i32 %50, %53
%55 = load i32, i32* %3
%56 = and i32 %55, 128
%57 = ashr i32 %56, 7
%58 = or i32 %54, %57
store i32 %58, i32* %4
%59 = load i32, i32* %4
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 %59)
%61 = load i32, i32* %3
%62 = icmp ne i32 %61, 255
br i1 %62, label %63, label %65
63: ; preds = %27
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %65
65: ; preds = %63, %27
%66 = load i32, i32* %3
%67 = and i32 %66, 7
%68 = icmp eq i32 %67, 7
br i1 %68, label %69, label %71
69: ; preds = %65
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
br label %73
71: ; preds = %65
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
br label %73
73: ; preds = %71, %69
br label %74
74: ; preds = %73
%75 = load i32, i32* %3
%76 = add nsw i32 %75, 1
store i32 %76, i32* %3
br label %18
77: ; preds = %18
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0))
br label %79
79: ; preds = %77, %13
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"extern \00"
@.str.1 = [39 x i8] c"const uint8_t bit_reverse_byte [0x100]\00"
@.str.5 = [3 x i8] c" \00"
@.str.6 = [7 x i8] c"0x%02x\00"
@str = [3 x i8] c" =\00"
@str.11 = [2 x i8] c"{\00"
@str.12 = [3 x i8] c"};\00"
@str.13 = [2 x i8] c";\00"
define void @gen_bit_reverse_table(i32 %0) {
%2 = icmp eq i32 %0, 0
br i1 %2, label %6, label %3
3: ; preds = %1
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
br label %31
6: ; preds = %1
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.11, i64 0, i64 0))
br label %10
10: ; preds = %6, %26
%11 = phi i32 [ 0, %6 ], [ %29, %26 ]
%12 = and i32 %11, 7
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %16
16: ; preds = %14, %10
%17 = trunc i32 %11 to i8
%18 = tail call i8 @llvm.bitreverse.i8(i8 %17)
%19 = zext i8 %18 to i32
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 %19)
%21 = icmp eq i32 %11, 255
br i1 %21, label %26, label %22
22: ; preds = %16
%23 = tail call i32 @putchar(i32 44)
%24 = icmp eq i32 %12, 7
%25 = select i1 %24, i32 10, i32 32
br label %26
26: ; preds = %22, %16
%27 = phi i32 [ 10, %16 ], [ %25, %22 ]
%28 = tail call i32 @putchar(i32 %27)
%29 = add nuw nsw i32 %11, 1
%30 = icmp eq i32 %29, 256
br i1 %30, label %31, label %10
31: ; preds = %26, %3
%32 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @str.13, i64 0, i64 0), %3 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @str.12, i64 0, i64 0), %26 ]
%33 = tail call i32 @puts(i8* dereferenceable(1) %32)
ret void
}