#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 acos(double);
scalar_t__ calloc(int, int);
double cos(double);
int /*<<< orphan*/ fatalx(char *, int);
int /*<<< orphan*/ free(double *);
double sqrt(double);
int /*<<< orphan*/ vst(double *, double *, double, int);
int /*<<< orphan*/ vzero(double *, int);
void calcfc(double *c, int g, double rho) {
  double *l, *d;
  int i, k;
  double pi;
  pi = 2.0 * acos(0.0);
  if ((l = (double *)calloc((g), sizeof(double))) == NULL)
    fatalx("Unable to allocate %d unit(s) for item \n", g);
  if ((d = (double *)calloc((g), sizeof(double))) == NULL)
    fatalx("Unable to allocate %d unit(s) for item \n", g);
  for (k = 0; k < g; k++) {
    l[k] = 1 + 2 * rho * cos((2.0 * pi * k) / g);
    d[k] = 1.0 / sqrt(l[k]);
  }
  vzero(c, g);
  for (i = 0; i < g; i++) {
    c[i] = 0;
    for (k = 0; k < g; k++) {
      c[i] += d[k] * cos((2.0 * pi * k * i) / (double)g);
    }
  }
  vst(c, c, 1.0 / (double)g, g);
  free(l);
  free(d);
}


x86 assembly (clang, -O0):
<calcfc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
call   1060 <acos@plt>
movaps %xmm0,%xmm1
movsd  0xe59(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0xc(%rbp),%edi
mov    $0x8,%esi
call   1070 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11da <calcfc+0x5a>
mov    -0xc(%rbp),%esi
lea    0xe3b(%rip),%rdi
call   1050 <fatalx@plt>
mov    -0xc(%rbp),%edi
mov    $0x8,%esi
call   1070 <calloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1204 <calcfc+0x84>
mov    -0xc(%rbp),%esi
lea    0xe11(%rip),%rdi
call   1050 <fatalx@plt>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12ae <calcfc+0x12e>
movsd  0xde1(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xdcf(%rip),%xmm0
mulsd  -0x38(%rbp),%xmm0
cvtsi2sdl -0x30(%rbp),%xmm1
mulsd  %xmm1,%xmm0
cvtsi2sdl -0xc(%rbp),%xmm1
divsd  %xmm1,%xmm0
call   1090 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  0xda7(%rip),%xmm1
addsd  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   10a0 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  0xd79(%rip),%xmm0
divsd  %xmm1,%xmm0
mov    -0x28(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    120b <calcfc+0x8b>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1080 <vzero@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1372 <calcfc+0x1f2>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    135f <calcfc+0x1df>
mov    -0x28(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  0xcf6(%rip),%xmm0
mulsd  -0x38(%rbp),%xmm0
cvtsi2sdl -0x30(%rbp),%xmm1
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x2c(%rbp),%xmm1
mulsd  %xmm1,%xmm0
cvtsi2sdl -0xc(%rbp),%xmm1
divsd  %xmm1,%xmm0
call   1090 <cos@plt>
movaps %xmm0,%xmm2
movsd  -0x48(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    12e4 <calcfc+0x164>
jmp    1364 <calcfc+0x1e4>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    12c1 <calcfc+0x141>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
cvtsi2sdl -0xc(%rbp),%xmm1
movsd  0xc81(%rip),%xmm0
divsd  %xmm1,%xmm0
mov    -0xc(%rbp),%edx
call   1040 <vst@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calcfc>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
movsd  %xmm0,0x8(%rsp)
mov    %esi,%ebx
mov    %rdi,%r15
mov    %esi,%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    11ab <calcfc+0x3b>
lea    0xe74(%rip),%rdi
mov    %ebx,%esi
call   1050 <fatalx@plt>
mov    %ebx,%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,%r12
test   %rax,%rax
je     131e <calcfc+0x1ae>
test   %ebx,%ebx
jle    1334 <calcfc+0x1c4>
mov    %ebx,%r14d
movsd  0x8(%rsp),%xmm0
addsd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
movsd  %xmm0,0x10(%rsp)
xor    %r13d,%r13d
movsd  0xe0a(%rip),%xmm1
jmp    1228 <calcfc+0xb8>
nopl   0x0(%rax,%rax,1)
call   1090 <sqrt@plt>
movsd  0xdfb(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%r12,%r13,8)
add    $0x1,%r13
cmp    %r13,%r14
movsd  0xdda(%rip),%xmm1
je     1268 <calcfc+0xf8>
xorps  %xmm0,%xmm0
cvtsi2sd %r13d,%xmm0
mulsd  %xmm1,%xmm0
divsd  0x10(%rsp),%xmm0
call   1080 <cos@plt>
movsd  0xdc1(%rip),%xmm1
mulsd  0x8(%rsp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x0(%rbp,%r13,8)
ucomisd 0xdb0(%rip),%xmm0
jb     1200 <calcfc+0x90>
sqrtsd %xmm0,%xmm0
jmp    120d <calcfc+0x9d>
mov    %r15,%rdi
mov    %ebx,%esi
call   1070 <vzero@plt>
test   %ebx,%ebx
jle    133e <calcfc+0x1ce>
mov    %rbp,0x18(%rsp)
mov    %ebx,%r13d
xorps  %xmm1,%xmm1
cvtsi2sd %r14d,%xmm1
xor    %ebp,%ebp
movsd  %xmm1,0x20(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movq   $0x0,(%r15,%rbp,8)
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
movsd  %xmm0,0x10(%rsp)
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
movsd  (%r12,%rbx,8),%xmm2
movsd  %xmm2,0x8(%rsp)
mulsd  0xd25(%rip),%xmm0
mulsd  0x10(%rsp),%xmm0
divsd  %xmm1,%xmm0
call   1080 <cos@plt>
movsd  0x20(%rsp),%xmm1
mulsd  0x8(%rsp),%xmm0
addsd  (%r15,%rbp,8),%xmm0
movsd  %xmm0,(%r15,%rbp,8)
add    $0x1,%rbx
cmp    %rbx,%r14
jne    12c0 <calcfc+0x150>
add    $0x1,%rbp
cmp    %r14,%rbp
jne    12a0 <calcfc+0x130>
mov    %r13d,%ebx
mov    0x18(%rsp),%rbp
jmp    1345 <calcfc+0x1d5>
lea    0xcf3(%rip),%rdi
mov    %ebx,%esi
call   1050 <fatalx@plt>
test   %ebx,%ebx
jg     11cb <calcfc+0x5b>
mov    %r15,%rdi
mov    %ebx,%esi
call   1070 <vzero@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %ebx,%xmm1
movsd  0xcbb(%rip),%xmm0
divsd  %xmm1,%xmm0
mov    %r15,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1040 <vst@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [41 x i8] c"Unable to allocate %d unit(s) for item \0A\00"
define void @calcfc(double* %0, i32 %1, double %2) {
%4 = alloca double*
%5 = alloca i32
%6 = alloca double
%7 = alloca double*
%8 = alloca double*
%9 = alloca i32
%10 = alloca i32
%11 = alloca double
store double* %0, double** %4
store i32 %1, i32* %5
store double %2, double* %6
%12 = call double @acos(double 0.000000e+00)
%13 = fmul double 2.000000e+00, %12
store double %13, double* %11
%14 = load i32, i32* %5
%15 = call i64 @calloc(i32 %14, i32 8)
%16 = inttoptr i64 %15 to double*
store double* %16, double** %7
%17 = icmp eq double* %16, null
br i1 %17, label %18, label %21
18: ; preds = %3
%19 = load i32, i32* %5
%20 = call i32 @fatalx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %18, %3
%22 = load i32, i32* %5
%23 = call i64 @calloc(i32 %22, i32 8)
%24 = inttoptr i64 %23 to double*
store double* %24, double** %8
%25 = icmp eq double* %24, null
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = load i32, i32* %5
%28 = call i32 @fatalx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %26, %21
store i32 0, i32* %10
br label %30
30: ; preds = %62, %29
%31 = load i32, i32* %10
%32 = load i32, i32* %5
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %65
34: ; preds = %30
%35 = load double, double* %6
%36 = fmul double 2.000000e+00, %35
%37 = load double, double* %11
%38 = fmul double 2.000000e+00, %37
%39 = load i32, i32* %10
%40 = sitofp i32 %39 to double
%41 = fmul double %38, %40
%42 = load i32, i32* %5
%43 = sitofp i32 %42 to double
%44 = fdiv double %41, %43
%45 = call double @cos(double %44)
%46 = call double @llvm.fmuladd.f64(double %36, double %45, double 1.000000e+00)
%47 = load double*, double** %7
%48 = load i32, i32* %10
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds double, double* %47, i64 %49
store double %46, double* %50
%51 = load double*, double** %7
%52 = load i32, i32* %10
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds double, double* %51, i64 %53
%55 = load double, double* %54
%56 = call double @sqrt(double %55)
%57 = fdiv double 1.000000e+00, %56
%58 = load double*, double** %8
%59 = load i32, i32* %10
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds double, double* %58, i64 %60
store double %57, double* %61
br label %62
62: ; preds = %34
%63 = load i32, i32* %10
%64 = add nsw i32 %63, 1
store i32 %64, i32* %10
br label %30
65: ; preds = %30
%66 = load double*, double** %4
%67 = load i32, i32* %5
%68 = call i32 @vzero(double* %66, i32 %67)
store i32 0, i32* %9
br label %69
69: ; preds = %110, %65
%70 = load i32, i32* %9
%71 = load i32, i32* %5
%72 = icmp slt i32 %70, %71
br i1 %72, label %73, label %113
73: ; preds = %69
%74 = load double*, double** %4
%75 = load i32, i32* %9
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds double, double* %74, i64 %76
store double 0.000000e+00, double* %77
store i32 0, i32* %10
br label %78
78: ; preds = %106, %73
%79 = load i32, i32* %10
%80 = load i32, i32* %5
%81 = icmp slt i32 %79, %80
br i1 %81, label %82, label %109
82: ; preds = %78
%83 = load double*, double** %8
%84 = load i32, i32* %10
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds double, double* %83, i64 %85
%87 = load double, double* %86
%88 = load double, double* %11
%89 = fmul double 2.000000e+00, %88
%90 = load i32, i32* %10
%91 = sitofp i32 %90 to double
%92 = fmul double %89, %91
%93 = load i32, i32* %9
%94 = sitofp i32 %93 to double
%95 = fmul double %92, %94
%96 = load i32, i32* %5
%97 = sitofp i32 %96 to double
%98 = fdiv double %95, %97
%99 = call double @cos(double %98)
%100 = load double*, double** %4
%101 = load i32, i32* %9
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds double, double* %100, i64 %102
%104 = load double, double* %103
%105 = call double @llvm.fmuladd.f64(double %87, double %99, double %104)
store double %105, double* %103
br label %106
106: ; preds = %82
%107 = load i32, i32* %10
%108 = add nsw i32 %107, 1
store i32 %108, i32* %10
br label %78
109: ; preds = %78
br label %110
110: ; preds = %109
%111 = load i32, i32* %9
%112 = add nsw i32 %111, 1
store i32 %112, i32* %9
br label %69
113: ; preds = %69
%114 = load double*, double** %4
%115 = load double*, double** %4
%116 = load i32, i32* %5
%117 = sitofp i32 %116 to double
%118 = fdiv double 1.000000e+00, %117
%119 = load i32, i32* %5
%120 = call i32 @vst(double* %114, double* %115, double %118, i32 %119)
%121 = load double*, double** %7
%122 = call i32 @free(double* %121)
%123 = load double*, double** %8
%124 = call i32 @free(double* %123)
ret void
}

LLVM IR (-O2):
@.str = [41 x i8] c"Unable to allocate %d unit(s) for item \0A\00"
define void @calcfc(double* %0, i32 %1, double %2) {
%4 = tail call i64 @calloc(i32 %1, i32 8)
%5 = inttoptr i64 %4 to double*
%6 = icmp eq i64 %4, 0
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @fatalx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %1)
br label %9
9: ; preds = %7, %3
%10 = tail call i64 @calloc(i32 %1, i32 8)
%11 = inttoptr i64 %10 to double*
%12 = icmp eq i64 %10, 0
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = tail call i32 @fatalx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %1)
br label %15
15: ; preds = %13, %9
%16 = icmp sgt i32 %1, 0
br i1 %16, label %19, label %17
17: ; preds = %15
%18 = tail call i32 @vzero(double* %0, i32 %1)
br label %39
19: ; preds = %15
%20 = fmul double %2, 2.000000e+00
%21 = sitofp i32 %1 to double
%22 = zext i32 %1 to i64
br label %23
23: ; preds = %19, %23
%24 = phi i64 [ 0, %19 ], [ %35, %23 ]
%25 = trunc i64 %24 to i32
%26 = sitofp i32 %25 to double
%27 = fmul double %26, 0x401921FB54442D18
%28 = fdiv double %27, %21
%29 = tail call double @cos(double %28)
%30 = tail call double @llvm.fmuladd.f64(double %20, double %29, double 1.000000e+00)
%31 = getelementptr inbounds double, double* %5, i64 %24
store double %30, double* %31
%32 = tail call double @sqrt(double %30)
%33 = fdiv double 1.000000e+00, %32
%34 = getelementptr inbounds double, double* %11, i64 %24
store double %33, double* %34
%35 = add nuw nsw i64 %24, 1
%36 = icmp eq i64 %35, %22
br i1 %36, label %37, label %23
37: ; preds = %23
%38 = tail call i32 @vzero(double* %0, i32 %1)
br i1 %16, label %41, label %39
39: ; preds = %17, %37
%40 = sitofp i32 %1 to double
br label %66
41: ; preds = %37
%42 = sitofp i32 %1 to double
%43 = zext i32 %1 to i64
br label %44
44: ; preds = %63, %41
%45 = phi i64 [ 0, %41 ], [ %64, %63 ]
%46 = getelementptr inbounds double, double* %0, i64 %45
store double 0.000000e+00, double* %46
%47 = trunc i64 %45 to i32
%48 = sitofp i32 %47 to double
br label %49
49: ; preds = %44, %49
%50 = phi i64 [ 0, %44 ], [ %61, %49 ]
%51 = getelementptr inbounds double, double* %11, i64 %50
%52 = load double, double* %51
%53 = trunc i64 %50 to i32
%54 = sitofp i32 %53 to double
%55 = fmul double %54, 0x401921FB54442D18
%56 = fmul double %55, %48
%57 = fdiv double %56, %42
%58 = tail call double @cos(double %57)
%59 = load double, double* %46
%60 = tail call double @llvm.fmuladd.f64(double %52, double %58, double %59)
store double %60, double* %46
%61 = add nuw nsw i64 %50, 1
%62 = icmp eq i64 %61, %43
br i1 %62, label %63, label %49
63: ; preds = %49
%64 = add nuw nsw i64 %45, 1
%65 = icmp eq i64 %64, %43
br i1 %65, label %66, label %44
66: ; preds = %63, %39
%67 = phi double [ %40, %39 ], [ %42, %63 ]
%68 = fdiv double 1.000000e+00, %67
%69 = tail call i32 @vst(double* %0, double* %0, double %68, i32 %1)
%70 = tail call i32 @free(double* %5)
%71 = tail call i32 @free(double* %11)
ret void
}