#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 abs(int const);
scalar_t__ calloc(int, int const);
double cos(double const);
int /*<<< orphan*/ fgError(char *);
int /*<<< orphan*/ free(double *);
double sin(double const);
void fghCircleTable(double **sint, double **cost, const int n) {
  int i;
  const int size = abs(n);
  const double angle = 2 * 3.14159265358979323846 / (double)((n == 0) ? 1 : n);
  *sint = (double *)calloc(sizeof(double), size + 1);
  *cost = (double *)calloc(sizeof(double), size + 1);
  if (!(*sint) || !(*cost)) {
    free(*sint);
    free(*cost);
    fgError("Failed to allocate memory in fghCircleTable");
  }
  (*sint)[0] = 0.0;
  (*cost)[0] = 1.0;
  for (i = 1; i < size; i++) {
    (*sint)[i] = sin(angle * i);
    (*cost)[i] = cos(angle * i);
  }
  (*sint)[size] = (*sint)[0];
  (*cost)[size] = (*cost)[0];
}


x86 assembly (clang, -O0):
<fghCircleTable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <abs@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1195 <fghCircleTable+0x35>
mov    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    119b <fghCircleTable+0x3b>
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cvtsi2sd %eax,%xmm1
movsd  0xe56(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x1c(%rbp),%esi
add    $0x1,%esi
mov    $0x8,%edi
call   1060 <calloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x1c(%rbp),%esi
add    $0x1,%esi
mov    $0x8,%edi
call   1060 <calloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
je     1203 <fghCircleTable+0xa3>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1227 <fghCircleTable+0xc7>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
lea    0xdee(%rip),%rdi
call   1050 <fgError@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsd  0xdc4(%rip),%xmm0
movsd  %xmm0,(%rax)
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    12af <fghCircleTable+0x14f>
movsd  -0x28(%rbp),%xmm0
cvtsi2sdl -0x18(%rbp),%xmm1
mulsd  %xmm1,%xmm0
call   1070 <sin@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movslq -0x18(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x28(%rbp),%xmm0
cvtsi2sdl -0x18(%rbp),%xmm1
mulsd  %xmm1,%xmm0
call   1080 <cos@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movslq -0x18(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    124f <fghCircleTable+0xef>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movsd  (%rax),%xmm0
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fghCircleTable>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%r13
mov    %edx,%ebp
neg    %ebp
cmovs  %edx,%ebp
mov    $0x1,%r12d
cmovb  %edx,%r12d
lea    0x1(%rbp),%r15d
mov    $0x8,%edi
mov    %r15d,%esi
call   1050 <calloc@plt>
mov    %rax,0x0(%r13)
mov    $0x8,%edi
mov    %r15d,%esi
call   1050 <calloc@plt>
mov    %rax,(%r14)
mov    0x0(%r13),%rdi
test   %rdi,%rdi
je     11a8 <fghCircleTable+0x58>
test   %rax,%rax
jne    11c8 <fghCircleTable+0x78>
call   1030 <free@plt>
mov    (%r14),%rdi
call   1030 <free@plt>
lea    0xe4c(%rip),%rdi
call   1040 <fgError@plt>
mov    0x0(%r13),%rdi
mov    (%r14),%rax
movq   $0x0,(%rdi)
movabs $0x3ff0000000000000,%rcx
mov    %rcx,(%rax)
mov    %ebp,%r15d
cmp    $0x2,%ebp
jb     12ec <fghCircleTable+0x19c>
cvtsi2sd %r12d,%xmm0
movsd  0xe0b(%rip),%xmm1
divsd  %xmm0,%xmm1
lea    -0x1(%r15),%rbx
cmp    $0x2,%ebp
jne    1215 <fghCircleTable+0xc5>
mov    $0x1,%ebp
test   $0x1,%bl
jne    12b4 <fghCircleTable+0x164>
jmp    12e8 <fghCircleTable+0x198>
mov    %rbx,0x10(%rsp)
and    $0xfffffffffffffffe,%rbx
mov    $0x1,%ebp
movsd  %xmm1,(%rsp)
nopl   0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
call   1060 <sin@plt>
mov    0x0(%r13),%rax
movsd  %xmm0,(%rax,%rbp,8)
movsd  0x8(%rsp),%xmm0
call   1070 <cos@plt>
mov    (%r14),%rax
movsd  %xmm0,(%rax,%rbp,8)
lea    0x1(%rbp),%r12
xorps  %xmm0,%xmm0
cvtsi2sd %r12d,%xmm0
mulsd  (%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
call   1060 <sin@plt>
mov    0x0(%r13),%rax
movsd  %xmm0,0x8(%rax,%rbp,8)
movsd  0x8(%rsp),%xmm0
call   1070 <cos@plt>
movsd  (%rsp),%xmm1
mov    (%r14),%rax
movsd  %xmm0,0x8(%rax,%rbp,8)
add    $0x2,%rbp
cmp    %rbx,%r12
jne    1230 <fghCircleTable+0xe0>
mov    0x10(%rsp),%rbx
test   $0x1,%bl
je     12e8 <fghCircleTable+0x198>
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mulsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movapd %xmm1,%xmm0
call   1060 <sin@plt>
mov    0x0(%r13),%rax
movsd  %xmm0,(%rax,%rbp,8)
movsd  (%rsp),%xmm0
call   1070 <cos@plt>
mov    (%r14),%rax
movsd  %xmm0,(%rax,%rbp,8)
mov    0x0(%r13),%rdi
movsd  (%rdi),%xmm0
movsd  %xmm0,(%rdi,%r15,8)
movsd  (%rax),%xmm0
movsd  %xmm0,(%rax,%r15,8)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [44 x i8] c"Failed to allocate memory in fghCircleTable\00"
define void @fghCircleTable(double** %0, double** %1, i32 %2) {
%4 = alloca double**
%5 = alloca double**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
store double** %0, double*** %4
store double** %1, double*** %5
store i32 %2, i32* %6
%10 = load i32, i32* %6
%11 = call i32 @abs(i32 %10)
store i32 %11, i32* %8
%12 = load i32, i32* %6
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %3
br label %17
15: ; preds = %3
%16 = load i32, i32* %6
br label %17
17: ; preds = %15, %14
%18 = phi i32 [ 1, %14 ], [ %16, %15 ]
%19 = sitofp i32 %18 to double
%20 = fdiv double 0x401921FB54442D18, %19
store double %20, double* %9
%21 = load i32, i32* %8
%22 = add nsw i32 %21, 1
%23 = call i64 @calloc(i32 8, i32 %22)
%24 = inttoptr i64 %23 to double*
%25 = load double**, double*** %4
store double* %24, double** %25
%26 = load i32, i32* %8
%27 = add nsw i32 %26, 1
%28 = call i64 @calloc(i32 8, i32 %27)
%29 = inttoptr i64 %28 to double*
%30 = load double**, double*** %5
store double* %29, double** %30
%31 = load double**, double*** %4
%32 = load double*, double** %31
%33 = icmp ne double* %32, null
br i1 %33, label %34, label %38
34: ; preds = %17
%35 = load double**, double*** %5
%36 = load double*, double** %35
%37 = icmp ne double* %36, null
br i1 %37, label %46, label %38
38: ; preds = %34, %17
%39 = load double**, double*** %4
%40 = load double*, double** %39
%41 = call i32 @free(double* %40)
%42 = load double**, double*** %5
%43 = load double*, double** %42
%44 = call i32 @free(double* %43)
%45 = call i32 @fgError(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
br label %46
46: ; preds = %38, %34
%47 = load double**, double*** %4
%48 = load double*, double** %47
%49 = getelementptr inbounds double, double* %48, i64 0
store double 0.000000e+00, double* %49
%50 = load double**, double*** %5
%51 = load double*, double** %50
%52 = getelementptr inbounds double, double* %51, i64 0
store double 1.000000e+00, double* %52
store i32 1, i32* %7
br label %53
53: ; preds = %78, %46
%54 = load i32, i32* %7
%55 = load i32, i32* %8
%56 = icmp slt i32 %54, %55
br i1 %56, label %57, label %81
57: ; preds = %53
%58 = load double, double* %9
%59 = load i32, i32* %7
%60 = sitofp i32 %59 to double
%61 = fmul double %58, %60
%62 = call double @sin(double %61)
%63 = load double**, double*** %4
%64 = load double*, double** %63
%65 = load i32, i32* %7
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds double, double* %64, i64 %66
store double %62, double* %67
%68 = load double, double* %9
%69 = load i32, i32* %7
%70 = sitofp i32 %69 to double
%71 = fmul double %68, %70
%72 = call double @cos(double %71)
%73 = load double**, double*** %5
%74 = load double*, double** %73
%75 = load i32, i32* %7
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds double, double* %74, i64 %76
store double %72, double* %77
br label %78
78: ; preds = %57
%79 = load i32, i32* %7
%80 = add nsw i32 %79, 1
store i32 %80, i32* %7
br label %53
81: ; preds = %53
%82 = load double**, double*** %4
%83 = load double*, double** %82
%84 = getelementptr inbounds double, double* %83, i64 0
%85 = load double, double* %84
%86 = load double**, double*** %4
%87 = load double*, double** %86
%88 = load i32, i32* %8
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds double, double* %87, i64 %89
store double %85, double* %90
%91 = load double**, double*** %5
%92 = load double*, double** %91
%93 = getelementptr inbounds double, double* %92, i64 0
%94 = load double, double* %93
%95 = load double**, double*** %5
%96 = load double*, double** %95
%97 = load i32, i32* %8
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds double, double* %96, i64 %98
store double %94, double* %99
ret void
}

LLVM IR (-O2):
@.str = [44 x i8] c"Failed to allocate memory in fghCircleTable\00"
define void @fghCircleTable(double** nocapture %0, double** nocapture %1, i32 %2) {
%4 = tail call i32 @llvm.abs.i32(i32 %2, i1 true)
%5 = icmp eq i32 %2, 0
%6 = select i1 %5, i32 1, i32 %2
%7 = sitofp i32 %6 to double
%8 = fdiv double 0x401921FB54442D18, %7
%9 = add nuw nsw i32 %4, 1
%10 = tail call i64 @calloc(i32 8, i32 %9)
%11 = inttoptr i64 %10 to double*
store double* %11, double** %0
%12 = tail call i64 @calloc(i32 8, i32 %9)
%13 = inttoptr i64 %12 to double*
store double* %13, double** %1
%14 = load double*, double** %0
%15 = icmp eq double* %14, null
%16 = icmp eq i64 %12, 0
%17 = select i1 %15, i1 true, i1 %16
br i1 %17, label %18, label %25
18: ; preds = %3
%19 = tail call i32 @free(double* %14)
%20 = load double*, double** %1
%21 = tail call i32 @free(double* %20)
%22 = tail call i32 @fgError(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%23 = load double*, double** %0
%24 = load double*, double** %1
br label %25
25: ; preds = %3, %18
%26 = phi double* [ %13, %3 ], [ %24, %18 ]
%27 = phi double* [ %14, %3 ], [ %23, %18 ]
store double 0.000000e+00, double* %27
store double 1.000000e+00, double* %26
%28 = icmp ugt i32 %4, 1
%29 = zext i32 %4 to i64
br i1 %28, label %30, label %78
30: ; preds = %25
%31 = add nsw i64 %29, -1
%32 = and i64 %31, 1
%33 = icmp eq i32 %4, 2
br i1 %33, label %61, label %34
34: ; preds = %30
%35 = and i64 %31, -2
br label %36
36: ; preds = %36, %34
%37 = phi i64 [ 1, %34 ], [ %58, %36 ]
%38 = phi i64 [ 0, %34 ], [ %59, %36 ]
%39 = trunc i64 %37 to i32
%40 = sitofp i32 %39 to double
%41 = fmul double %8, %40
%42 = tail call double @sin(double %41)
%43 = load double*, double** %0
%44 = getelementptr inbounds double, double* %43, i64 %37
store double %42, double* %44
%45 = tail call double @cos(double %41)
%46 = load double*, double** %1
%47 = getelementptr inbounds double, double* %46, i64 %37
store double %45, double* %47
%48 = add nuw nsw i64 %37, 1
%49 = trunc i64 %48 to i32
%50 = sitofp i32 %49 to double
%51 = fmul double %8, %50
%52 = tail call double @sin(double %51)
%53 = load double*, double** %0
%54 = getelementptr inbounds double, double* %53, i64 %48
store double %52, double* %54
%55 = tail call double @cos(double %51)
%56 = load double*, double** %1
%57 = getelementptr inbounds double, double* %56, i64 %48
store double %55, double* %57
%58 = add nuw nsw i64 %37, 2
%59 = add i64 %38, 2
%60 = icmp eq i64 %59, %35
br i1 %60, label %61, label %36
61: ; preds = %36, %30
%62 = phi double* [ undef, %30 ], [ %56, %36 ]
%63 = phi i64 [ 1, %30 ], [ %58, %36 ]
%64 = icmp eq i64 %32, 0
br i1 %64, label %75, label %65
65: ; preds = %61
%66 = trunc i64 %63 to i32
%67 = sitofp i32 %66 to double
%68 = fmul double %8, %67
%69 = tail call double @sin(double %68)
%70 = load double*, double** %0
%71 = getelementptr inbounds double, double* %70, i64 %63
store double %69, double* %71
%72 = tail call double @cos(double %68)
%73 = load double*, double** %1
%74 = getelementptr inbounds double, double* %73, i64 %63
store double %72, double* %74
br label %75
75: ; preds = %61, %65
%76 = phi double* [ %62, %61 ], [ %73, %65 ]
%77 = load double*, double** %0
br label %78
78: ; preds = %25, %75
%79 = phi double* [ %76, %75 ], [ %26, %25 ]
%80 = phi double* [ %77, %75 ], [ %27, %25 ]
%81 = load double, double* %80
%82 = getelementptr inbounds double, double* %80, i64 %29
store double %81, double* %82
%83 = load double, double* %79
%84 = getelementptr inbounds double, double* %79, i64 %29
store double %83, double* %84
ret void
}