#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int M_PI;
double cos(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
void gentbl_offscostab(FILE *f, unsigned int nbits) {
  int i;
  fprintf(f,
          "\n/*\n * small cosine table in U8 format\n */\n"
          "#define OFFSCOSTABBITS %u\n"
          "#define OFFSCOSTABSIZE (1<<OFFSCOSTABBITS)\n\n",
          nbits);
  fprintf(f, "static unsigned char offscostab[OFFSCOSTABSIZE] = {\n\t");
  for (i = 0; i < (1 << nbits); i++) {
    fprintf(f, "%4u", (int)(128 + 127.0 * cos(i * 2.0 * M_PI / (1 << nbits))));
    if (i < (1 << nbits) - 1)
      fprintf(f, "%s", (i & 7) == 7 ? ",\n\t" : ",");
  }
  fprintf(f,
          "\n};\n\n"
          "#define OFFSCOS(x) offscostab[((x)>>%d)&0x%x]\n\n",
          16 - nbits, (1 << nbits) - 1);
}


x86 assembly (clang, -O0):
<gentbl_offscostab>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xedb(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xf3b(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
cmp    %ecx,%eax
jge    123f <gentbl_offscostab+0x11f>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
cvtsi2sdl -0x10(%rbp),%xmm0
movsd  0xe87(%rip),%xmm1
mulsd  %xmm1,%xmm0
mov    0x2e54(%rip),%rax
cvtsi2sdl (%rax),%xmm1
mulsd  %xmm1,%xmm0
mov    -0xc(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <cos@plt>
mov    -0x18(%rbp),%rdi
movsd  0xe3d(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe39(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edx
lea    0xee2(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    122c <gentbl_offscostab+0x10c>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%ecx
and    $0x7,%ecx
lea    0xebb(%rip),%rdx
lea    0xeb0(%rip),%rax
cmp    $0x7,%ecx
cmove  %rax,%rdx
lea    0xe9f(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    1231 <gentbl_offscostab+0x111>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    115d <gentbl_offscostab+0x3d>
mov    -0x8(%rbp),%rdi
mov    $0x10,%edx
sub    -0xc(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,%ecx
sub    $0x1,%ecx
lea    0xe6c(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gentbl_offscostab>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r14d
mov    %rdi,%rbx
lea    0xebd(%rip),%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0xf1e(%rip),%rdi
mov    $0x35,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1060 <fwrite@plt>
mov    $0x1,%ebp
mov    $0x1,%eax
mov    %r14d,%ecx
shl    %cl,%eax
cmp    $0x1f,%r14d
jne    119e <gentbl_offscostab+0x5e>
add    $0xffffffff,%eax
mov    %eax,%r12d
jmp    125e <gentbl_offscostab+0x11e>
mov    %r14d,0x4(%rsp)
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x8(%rsp)
lea    -0x1(%rax),%r12d
cmp    $0x2,%eax
cmovge %eax,%ebp
xorpd  %xmm0,%xmm0
mov    0x2e26(%rip),%r13
lea    0xef7(%rip),%r15
xor    %r14d,%r14d
jmp    11e7 <gentbl_offscostab+0xa7>
xchg   %ax,%ax
movsd  0x10(%rsp),%xmm0
addsd  0xe32(%rip),%xmm0
add    $0x1,%r14d
cmp    %r14d,%ebp
je     1259 <gentbl_offscostab+0x119>
movsd  %xmm0,0x10(%rsp)
addsd  %xmm0,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sdl 0x0(%r13),%xmm1
mulsd  %xmm0,%xmm1
divsd  0x8(%rsp),%xmm1
cvttsd2si %xmm1,%edi
call   1050 <cos@plt>
mulsd  0xdeb(%rip),%xmm0
addsd  0xdeb(%rip),%xmm0
cvttsd2si %xmm0,%edx
mov    %rbx,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
cmp    %r12d,%r14d
jge    11d0 <gentbl_offscostab+0x90>
mov    %r14d,%eax
not    %eax
test   $0x7,%al
lea    0xe87(%rip),%rdi
lea    0xe7c(%rip),%rax
cmove  %rax,%rdi
mov    %rbx,%rsi
call   1030 <fputs@plt>
jmp    11d0 <gentbl_offscostab+0x90>
mov    0x4(%rsp),%r14d
mov    $0x10,%edx
sub    %r14d,%edx
lea    0xe5d(%rip),%rsi
mov    %rbx,%rdi
mov    %r12d,%ecx
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fprintf@plt>

LLVM IR (-O0):
@.str = [114 x i8] c"\0A/*\0A * small cosine table in U8 format\0A */\0A#define OFFSCOSTABBITS %u\0A#define OFFSCOSTABSIZE (1<<OFFSCOSTABBITS)\0A\0A\00"
@.str.1 = [54 x i8] c"static unsigned char offscostab[OFFSCOSTABSIZE] = {\0A\09\00"
@.str.2 = [4 x i8] c"%4u\00"
@M_PI = global i32 0
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [4 x i8] c",\0A\09\00"
@.str.5 = [2 x i8] c",\00"
@.str.6 = [53 x i8] c"\0A};\0A\0A#define OFFSCOS(x) offscostab[((x)>>%d)&0x%x]\0A\0A\00"
define void @gentbl_offscostab(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%6 = load i32*, i32** %3
%7 = load i32, i32* %4
%8 = call i32 (i32*, i8*, ...) @fprintf(i32* %6, i8* getelementptr inbounds ([114 x i8], [114 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = load i32*, i32** %3
%10 = call i32 (i32*, i8*, ...) @fprintf(i32* %9, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %5
br label %11
11: ; preds = %47, %2
%12 = load i32, i32* %5
%13 = load i32, i32* %4
%14 = shl i32 1, %13
%15 = icmp slt i32 %12, %14
br i1 %15, label %16, label %50
16: ; preds = %11
%17 = load i32*, i32** %3
%18 = load i32, i32* %5
%19 = sitofp i32 %18 to double
%20 = fmul double %19, 2.000000e+00
%21 = load i32, i32* @M_PI
%22 = sitofp i32 %21 to double
%23 = fmul double %20, %22
%24 = load i32, i32* %4
%25 = shl i32 1, %24
%26 = sitofp i32 %25 to double
%27 = fdiv double %23, %26
%28 = fptosi double %27 to i32
%29 = call double @cos(i32 %28)
%30 = call double @llvm.fmuladd.f64(double 1.270000e+02, double %29, double 1.280000e+02)
%31 = fptosi double %30 to i32
%32 = call i32 (i32*, i8*, ...) @fprintf(i32* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %31)
%33 = load i32, i32* %5
%34 = load i32, i32* %4
%35 = shl i32 1, %34
%36 = sub nsw i32 %35, 1
%37 = icmp slt i32 %33, %36
br i1 %37, label %38, label %46
38: ; preds = %16
%39 = load i32*, i32** %3
%40 = load i32, i32* %5
%41 = and i32 %40, 7
%42 = icmp eq i32 %41, 7
%43 = zext i1 %42 to i64
%44 = select i1 %42, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0)
%45 = call i32 (i32*, i8*, ...) @fprintf(i32* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %44)
br label %46
46: ; preds = %38, %16
br label %47
47: ; preds = %46
%48 = load i32, i32* %5
%49 = add nsw i32 %48, 1
store i32 %49, i32* %5
br label %11
50: ; preds = %11
%51 = load i32*, i32** %3
%52 = load i32, i32* %4
%53 = sub i32 16, %52
%54 = load i32, i32* %4
%55 = shl i32 1, %54
%56 = sub nsw i32 %55, 1
%57 = call i32 (i32*, i8*, ...) @fprintf(i32* %51, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.6, i64 0, i64 0), i32 %53, i32 %56)
ret void
}

LLVM IR (-O2):
@.str = [114 x i8] c"\0A/*\0A * small cosine table in U8 format\0A */\0A#define OFFSCOSTABBITS %u\0A#define OFFSCOSTABSIZE (1<<OFFSCOSTABBITS)\0A\0A\00"
@.str.1 = [54 x i8] c"static unsigned char offscostab[OFFSCOSTABSIZE] = {\0A\09\00"
@.str.2 = [4 x i8] c"%4u\00"
@M_PI = global i32 0
@.str.4 = [4 x i8] c",\0A\09\00"
@.str.5 = [2 x i8] c",\00"
@.str.6 = [53 x i8] c"\0A};\0A\0A#define OFFSCOS(x) offscostab[((x)>>%d)&0x%x]\0A\0A\00"
define void @gentbl_offscostab(i32* nocapture %0, i32 %1) {
%3 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([114 x i8], [114 x i8]* @.str, i64 0, i64 0), i32 %1)
%4 = tail call i64 @fwrite(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0), i64 53, i64 1, i32* %0)
%5 = shl nuw i32 1, %1
%6 = icmp eq i32 %1, 31
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = add nsw i32 %5, -1
br label %35
9: ; preds = %2
%10 = sitofp i32 %5 to double
%11 = add nsw i32 %5, -1
%12 = call i32 @llvm.smax.i32(i32 %5, i32 1)
br label %13
13: ; preds = %9, %32
%14 = phi i32 [ 0, %9 ], [ %33, %32 ]
%15 = sitofp i32 %14 to double
%16 = fmul double %15, 2.000000e+00
%17 = load i32, i32* @M_PI
%18 = sitofp i32 %17 to double
%19 = fmul double %16, %18
%20 = fdiv double %19, %10
%21 = fptosi double %20 to i32
%22 = tail call double @cos(i32 %21)
%23 = tail call double @llvm.fmuladd.f64(double %22, double 1.270000e+02, double 1.280000e+02)
%24 = fptosi double %23 to i32
%25 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %24)
%26 = icmp slt i32 %14, %11
br i1 %26, label %27, label %32
27: ; preds = %13
%28 = and i32 %14, 7
%29 = icmp eq i32 %28, 7
%30 = select i1 %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0)
%31 = tail call i32 @fputs(i8* %30, i32* %0)
br label %32
32: ; preds = %13, %27
%33 = add nuw nsw i32 %14, 1
%34 = icmp eq i32 %33, %12
br i1 %34, label %35, label %13
35: ; preds = %32, %7
%36 = phi i32 [ %8, %7 ], [ %11, %32 ]
%37 = sub i32 16, %1
%38 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.6, i64 0, i64 0), i32 %37, i32 %36)
ret void
}