#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 */
double cos(double);
int /*<<< orphan*/ printf(char *, ...);
double sin(double);
void set_up_one_table(int length) {
  int index;
  double angle;
  double scale;
  scale = 3.141592653589793238462 / (double)(4 * length);
  printf("static const cos_msin_t cos_msin_%d[%d] =\n", length, length);
  printf("{\n");
  for (index = 0; index < length - 1; index++) {
    angle = scale * ((double)index + 0.5);
    printf("    {%.15ef, %.15ef},\n", cos(angle), -sin(angle));
  }
  angle = scale * ((double)index + 0.5);
  printf("    {%.15ef, %.15ef}\n", cos(angle), -sin(angle));
  printf("};\n\n");
}


x86 assembly (clang, -O0):
<set_up_one_table>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
shl    $0x2,%eax
cvtsi2sd %eax,%xmm1
movsd  0xeb3(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x4(%rbp),%esi
mov    -0x4(%rbp),%edx
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    -0x4(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1203 <set_up_one_table+0xd3>
movsd  -0x18(%rbp),%xmm0
cvtsi2sdl -0x8(%rbp),%xmm1
movsd  0xe66(%rip),%xmm2
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1050 <cos@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
lea    0xe50(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    117f <set_up_one_table+0x4f>
movsd  -0x18(%rbp),%xmm0
cvtsi2sdl -0x8(%rbp),%xmm1
movsd  0xdf3(%rip),%xmm2
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1050 <cos@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
lea    0xdf4(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_up_one_table>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %edi,%r14d
lea    0x0(,%r14,4),%eax
cvtsi2sd %eax,%xmm0
movsd  0xea1(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
lea    0xec1(%rip),%rdi
mov    %r14d,%esi
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf05(%rip),%rdi
call   1030 <puts@plt>
cmp    $0x2,%r14d
jl     1220 <set_up_one_table+0xe0>
add    $0xffffffff,%r14d
xorpd  %xmm0,%xmm0
lea    0xeba(%rip),%rbx
mov    %r14d,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  %xmm0,0x8(%rsp)
addsd  0xe4a(%rip),%xmm0
mulsd  (%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
call   1060 <cos@plt>
movsd  %xmm0,0x18(%rsp)
movsd  0x10(%rsp),%xmm0
call   1050 <sin@plt>
movapd %xmm0,%xmm1
xorpd  0xe35(%rip),%xmm1
mov    %rbx,%rdi
movsd  0x18(%rsp),%xmm0
mov    $0x2,%al
call   1040 <printf@plt>
movsd  0x8(%rsp),%xmm0
addsd  0xe07(%rip),%xmm0
add    $0xffffffff,%ebp
jne    11b0 <set_up_one_table+0x70>
xorps  %xmm1,%xmm1
cvtsi2sd %r14d,%xmm1
addsd  0xdea(%rip),%xmm1
jmp    1228 <set_up_one_table+0xe8>
movsd  0xde0(%rip),%xmm1
movsd  (%rsp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp)
call   1060 <cos@plt>
movsd  %xmm0,0x8(%rsp)
movsd  (%rsp),%xmm0
call   1050 <sin@plt>
movaps %xmm0,%xmm1
xorps  0xdcb(%rip),%xmm1
lea    0xe16(%rip),%rdi
movsd  0x8(%rsp),%xmm0
mov    $0x2,%al
call   1040 <printf@plt>
lea    0xe1a(%rip),%rdi
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [43 x i8] c"static const cos_msin_t cos_msin_%d[%d] =\0A\00"
@.str.1 = [3 x i8] c"{\0A\00"
@.str.2 = [23 x i8] c" {%.15ef, %.15ef},\0A\00"
@.str.3 = [22 x i8] c" {%.15ef, %.15ef}\0A\00"
@.str.4 = [5 x i8] c"};\0A\0A\00"
define void @set_up_one_table(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca double
%5 = alloca double
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = mul nsw i32 4, %6
%8 = sitofp i32 %7 to double
%9 = fdiv double 0x400921FB54442D18, %8
store double %9, double* %5
%10 = load i32, i32* %2
%11 = load i32, i32* %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %11)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %14
14: ; preds = %31, %1
%15 = load i32, i32* %3
%16 = load i32, i32* %2
%17 = sub nsw i32 %16, 1
%18 = icmp slt i32 %15, %17
br i1 %18, label %19, label %34
19: ; preds = %14
%20 = load double, double* %5
%21 = load i32, i32* %3
%22 = sitofp i32 %21 to double
%23 = fadd double %22, 5.000000e-01
%24 = fmul double %20, %23
store double %24, double* %4
%25 = load double, double* %4
%26 = call double @cos(double %25)
%27 = load double, double* %4
%28 = call double @sin(double %27)
%29 = fneg double %28
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), double %26, double %29)
br label %31
31: ; preds = %19
%32 = load i32, i32* %3
%33 = add nsw i32 %32, 1
store i32 %33, i32* %3
br label %14
34: ; preds = %14
%35 = load double, double* %5
%36 = load i32, i32* %3
%37 = sitofp i32 %36 to double
%38 = fadd double %37, 5.000000e-01
%39 = fmul double %35, %38
store double %39, double* %4
%40 = load double, double* %4
%41 = call double @cos(double %40)
%42 = load double, double* %4
%43 = call double @sin(double %42)
%44 = fneg double %43
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), double %41, double %44)
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [43 x i8] c"static const cos_msin_t cos_msin_%d[%d] =\0A\00"
@.str.2 = [23 x i8] c" {%.15ef, %.15ef},\0A\00"
@.str.3 = [22 x i8] c" {%.15ef, %.15ef}\0A\00"
@str = [2 x i8] c"{\00"
@str.5 = [4 x i8] c"};\0A\00"
define void @set_up_one_table(i32 %0) {
%2 = shl nsw i32 %0, 2
%3 = sitofp i32 %2 to double
%4 = fdiv double 0x400921FB54442D18, %3
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %0)
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%7 = add i32 %0, -1
%8 = icmp sgt i32 %0, 1
br i1 %8, label %9, label %23
9: ; preds = %1, %9
%10 = phi i32 [ %18, %9 ], [ 0, %1 ]
%11 = sitofp i32 %10 to double
%12 = fadd double %11, 5.000000e-01
%13 = fmul double %4, %12
%14 = tail call double @cos(double %13)
%15 = tail call double @sin(double %13)
%16 = fneg double %15
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), double %14, double %16)
%18 = add nuw nsw i32 %10, 1
%19 = icmp eq i32 %18, %7
br i1 %19, label %20, label %9
20: ; preds = %9
%21 = sitofp i32 %7 to double
%22 = fadd double %21, 5.000000e-01
br label %23
23: ; preds = %20, %1
%24 = phi double [ 5.000000e-01, %1 ], [ %22, %20 ]
%25 = fmul double %4, %24
%26 = tail call double @cos(double %25)
%27 = tail call double @sin(double %25)
%28 = fneg double %27
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), double %26, double %28)
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.5, i64 0, i64 0))
ret void
}