#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;
typedef int int32_t;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ errx(int, char *, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ powFastSetTable(unsigned int *, int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  uint32_t precision = 11;
  if (argc > 1)
    precision = atoi(argv[1]);
  if (precision > 18)
    errx(1, "Invalid precision %d, must be [0,18]", precision);
  unsigned int *lookup_table;
  int table_size = (1 << precision);
  lookup_table = (unsigned int *)malloc(sizeof(unsigned int) * table_size);
  powFastSetTable(lookup_table, precision);
  printf("/* fast pow lookup table, precision %u, size %u */\n", precision,
         table_size);
  printf("const uint32_t fast_pow_precision = %u;\n", precision);
  printf("const uint32_t fast_pow_table_size = %u;\n", table_size);
  printf("const uint32_t fast_pow_table[%u] = {\n", table_size);
  int32_t i;
  for (i = 0; i < table_size; ++i)
    printf("%u, ", lookup_table[i]);
  printf(" };\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xb,-0x14(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1187 <main+0x37>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x12,-0x14(%rbp)
jle    11a5 <main+0x55>
mov    -0x14(%rbp),%edx
mov    $0x1,%edi
lea    0xe60(%rip),%rsi
call   1030 <errx@plt>
mov    -0x14(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,-0x24(%rbp)
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1060 <powFastSetTable@plt>
mov    -0x14(%rbp),%esi
mov    -0x24(%rbp),%edx
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%esi
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%esi
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1252 <main+0x102>
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    121f <main+0xcf>
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0xb,%r14d
cmp    $0x2,%edi
jl     1197 <main+0x37>
mov    0x8(%rsi),%rdi
call   1080 <atoi@plt>
mov    %eax,%r14d
cmp    $0x13,%eax
jl     1197 <main+0x37>
lea    0xe76(%rip),%rsi
mov    $0x1,%edi
mov    %r14d,%edx
call   1040 <errx@plt>
mov    $0x1,%r15d
mov    $0x1,%ebp
mov    %r14d,%ecx
shl    %cl,%ebp
lea    0x0(,%rbp,4),%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14d,%esi
call   1070 <powFastSetTable@plt>
lea    0xe5d(%rip),%rdi
mov    %r14d,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe7e(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe96(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeb0(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x1f,%r14d
je     1236 <main+0xd6>
cmp    $0x2,%ebp
cmovge %ebp,%r15d
lea    0xeba(%rip),%r14
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    (%rbx,%rbp,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1220 <main+0xc0>
lea    0xe9b(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [37 x i8] c"Invalid precision %d, must be [0,18]\00"
@.str.1 = [52 x i8] c"/* fast pow lookup table, precision %u, size %u */\0A\00"
@.str.2 = [41 x i8] c"const uint32_t fast_pow_precision = %u;\0A\00"
@.str.3 = [42 x i8] c"const uint32_t fast_pow_table_size = %u;\0A\00"
@.str.4 = [39 x i8] c"const uint32_t fast_pow_table[%u] = {\0A\00"
@.str.5 = [5 x i8] c"%u, \00"
@.str.6 = [5 x i8] c" };\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 11, i32* %6
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 1
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @atoi(i8* %15)
store i32 %16, i32* %6
br label %17
17: ; preds = %12, %2
%18 = load i32, i32* %6
%19 = icmp sgt i32 %18, 18
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load i32, i32* %6
%22 = call i32 @errx(i32 1, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %20, %17
%24 = load i32, i32* %6
%25 = shl i32 1, %24
store i32 %25, i32* %8
%26 = load i32, i32* %8
%27 = sext i32 %26 to i64
%28 = mul i64 4, %27
%29 = trunc i64 %28 to i32
%30 = call i64 @malloc(i32 %29)
%31 = inttoptr i64 %30 to i32*
store i32* %31, i32** %7
%32 = load i32*, i32** %7
%33 = load i32, i32* %6
%34 = call i32 @powFastSetTable(i32* %32, i32 %33)
%35 = load i32, i32* %6
%36 = load i32, i32* %8
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i32 %35, i32 %36)
%38 = load i32, i32* %6
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 %38)
%40 = load i32, i32* %8
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 %40)
%42 = load i32, i32* %8
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i32 %42)
store i32 0, i32* %9
br label %44
44: ; preds = %55, %23
%45 = load i32, i32* %9
%46 = load i32, i32* %8
%47 = icmp slt i32 %45, %46
br i1 %47, label %48, label %58
48: ; preds = %44
%49 = load i32*, i32** %7
%50 = load i32, i32* %9
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i32, i32* %49, i64 %51
%53 = load i32, i32* %52
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %53)
br label %55
55: ; preds = %48
%56 = load i32, i32* %9
%57 = add nsw i32 %56, 1
store i32 %57, i32* %9
br label %44
58: ; preds = %44
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [37 x i8] c"Invalid precision %d, must be [0,18]\00"
@.str.1 = [52 x i8] c"/* fast pow lookup table, precision %u, size %u */\0A\00"
@.str.2 = [41 x i8] c"const uint32_t fast_pow_precision = %u;\0A\00"
@.str.3 = [42 x i8] c"const uint32_t fast_pow_table_size = %u;\0A\00"
@.str.4 = [39 x i8] c"const uint32_t fast_pow_table[%u] = {\0A\00"
@.str.5 = [5 x i8] c"%u, \00"
@str = [4 x i8] c" };\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %11
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
%8 = icmp sgt i32 %7, 18
br i1 %8, label %9, label %11
9: ; preds = %4
%10 = tail call i32 @errx(i32 1, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %7)
br label %11
11: ; preds = %2, %9, %4
%12 = phi i32 [ %7, %9 ], [ %7, %4 ], [ 11, %2 ]
%13 = shl nuw i32 1, %12
%14 = shl i32 %13, 2
%15 = tail call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to i32*
%17 = tail call i32 @powFastSetTable(i32* %16, i32 %12)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i32 %12, i32 %13)
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 %12)
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 %13)
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i32 %13)
%22 = icmp eq i32 %12, 31
br i1 %22, label %33, label %23
23: ; preds = %11
%24 = call i32 @llvm.smax.i32(i32 %13, i32 1)
%25 = zext i32 %24 to i64
br label %26
26: ; preds = %23, %26
%27 = phi i64 [ 0, %23 ], [ %31, %26 ]
%28 = getelementptr inbounds i32, i32* %16, i64 %27
%29 = load i32, i32* %28
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %29)
%31 = add nuw nsw i64 %27, 1
%32 = icmp eq i64 %31, %25
br i1 %32, label %33, label %26
33: ; preds = %26, %11
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str, i64 0, i64 0))
ret i32 0
}