#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 */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ copyarr(double *, double *, int);
int /*<<< orphan*/ fatalx(char *, int);
int /*<<< orphan*/ free(double *);
int /*<<< orphan*/ vzero(double *, int);
void circconv(double *jp, double *c, double *jmean, int g) {
  double *ww;
  int i, k;
  if ((ww = (double *)calloc((2 * g), sizeof(double))) == NULL)
    fatalx("Unable to allocate %d unit(s) for item \n", 2 * g);
  copyarr(c, ww, g);
  copyarr(c, ww + g, g);
  vzero(jp, g);
  for (i = 0; i < g; i++) {
    for (k = 0; k < g; k++) {
      jp[i] += jmean[k] * ww[g + i - k];
    }
  }
  free(ww);
}


x86 assembly (clang, -O0):
<circconv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
shl    $0x1,%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1197 <circconv+0x47>
mov    -0x1c(%rbp),%esi
shl    $0x1,%esi
lea    0xe6e(%rip),%rdi
call   1040 <fatalx@plt>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1070 <copyarr@plt>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
movslq -0x1c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
mov    -0x1c(%rbp),%edx
call   1070 <copyarr@plt>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1060 <vzero@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1251 <circconv+0x101>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    123e <circconv+0xee>
mov    -0x18(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    -0x2c(%rbp),%ecx
sub    -0x30(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm2
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    11e8 <circconv+0x98>
jmp    1243 <circconv+0xf3>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11d5 <circconv+0x85>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<circconv>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rsi,%r13
mov    %rdi,%r12
lea    (%r14,%r14,1),%ebp
mov    %ebp,%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    118d <circconv+0x3d>
lea    0xe7a(%rip),%rdi
mov    %ebp,%esi
call   1040 <fatalx@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1070 <copyarr@plt>
movslq %r14d,%rax
lea    (%rbx,%rax,8),%rsi
mov    %r13,%rdi
mov    %r14d,%edx
call   1070 <copyarr@plt>
mov    %r12,%rdi
mov    %r14d,%esi
call   1060 <vzero@plt>
test   %r14d,%r14d
jle    1277 <circconv+0x127>
mov    %r14d,%r8d
mov    %r8d,%ecx
and    $0xfffffffe,%ecx
xor    %edx,%edx
mov    %r14d,%esi
jmp    11f0 <circconv+0xa0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rdx
add    $0x1,%esi
cmp    %r8,%rdx
je     1277 <circconv+0x127>
movsd  (%r12,%rdx,8),%xmm0
cmp    $0x1,%r14d
jne    1200 <circconv+0xb0>
xor    %edi,%edi
jmp    124f <circconv+0xff>
mov    %esi,%ebp
xor    %edi,%edi
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  (%r15,%rdi,8),%xmm1
movslq %ebp,%rbp
mulsd  (%rbx,%rbp,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%r12,%rdx,8)
movsd  0x8(%r15,%rdi,8),%xmm0
lea    -0x1(%rbp),%eax
cltq
mulsd  (%rbx,%rax,8),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%r12,%rdx,8)
add    $0x2,%rdi
add    $0xfffffffe,%ebp
cmp    %rdi,%rcx
jne    1210 <circconv+0xc0>
test   $0x1,%r8b
je     11e0 <circconv+0x90>
lea    (%rdx,%r14,1),%eax
movsd  (%r15,%rdi,8),%xmm1
sub    %edi,%eax
cltq
mulsd  (%rbx,%rax,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%r12,%rdx,8)
jmp    11e0 <circconv+0x90>
mov    %rbx,%rdi
add    $0x8,%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 @circconv(double* %0, double* %1, double* %2, i32 %3) {
%5 = alloca double*
%6 = alloca double*
%7 = alloca double*
%8 = alloca i32
%9 = alloca double*
%10 = alloca i32
%11 = alloca i32
store double* %0, double** %5
store double* %1, double** %6
store double* %2, double** %7
store i32 %3, i32* %8
%12 = load i32, i32* %8
%13 = mul nsw i32 2, %12
%14 = call i64 @calloc(i32 %13, i32 8)
%15 = inttoptr i64 %14 to double*
store double* %15, double** %9
%16 = icmp eq double* %15, null
br i1 %16, label %17, label %21
17: ; preds = %4
%18 = load i32, i32* %8
%19 = mul nsw i32 2, %18
%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 = %17, %4
%22 = load double*, double** %6
%23 = load double*, double** %9
%24 = load i32, i32* %8
%25 = call i32 @copyarr(double* %22, double* %23, i32 %24)
%26 = load double*, double** %6
%27 = load double*, double** %9
%28 = load i32, i32* %8
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds double, double* %27, i64 %29
%31 = load i32, i32* %8
%32 = call i32 @copyarr(double* %26, double* %30, i32 %31)
%33 = load double*, double** %5
%34 = load i32, i32* %8
%35 = call i32 @vzero(double* %33, i32 %34)
store i32 0, i32* %10
br label %36
36: ; preds = %70, %21
%37 = load i32, i32* %10
%38 = load i32, i32* %8
%39 = icmp slt i32 %37, %38
br i1 %39, label %40, label %73
40: ; preds = %36
store i32 0, i32* %11
br label %41
41: ; preds = %66, %40
%42 = load i32, i32* %11
%43 = load i32, i32* %8
%44 = icmp slt i32 %42, %43
br i1 %44, label %45, label %69
45: ; preds = %41
%46 = load double*, double** %7
%47 = load i32, i32* %11
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds double, double* %46, i64 %48
%50 = load double, double* %49
%51 = load double*, double** %9
%52 = load i32, i32* %8
%53 = load i32, i32* %10
%54 = add nsw i32 %52, %53
%55 = load i32, i32* %11
%56 = sub nsw i32 %54, %55
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds double, double* %51, i64 %57
%59 = load double, double* %58
%60 = load double*, double** %5
%61 = load i32, i32* %10
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds double, double* %60, i64 %62
%64 = load double, double* %63
%65 = call double @llvm.fmuladd.f64(double %50, double %59, double %64)
store double %65, double* %63
br label %66
66: ; preds = %45
%67 = load i32, i32* %11
%68 = add nsw i32 %67, 1
store i32 %68, i32* %11
br label %41
69: ; preds = %41
br label %70
70: ; preds = %69
%71 = load i32, i32* %10
%72 = add nsw i32 %71, 1
store i32 %72, i32* %10
br label %36
73: ; preds = %36
%74 = load double*, double** %9
%75 = call i32 @free(double* %74)
ret void
}

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