#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 *dgetmem(int const);
int /*<<< orphan*/ fftr(double *, double *, int const);
int /*<<< orphan*/ free(double *);
double sqrt(double);
void spec(double *x, double *sp, const int leng) {
  int k, no;
  double *y, *mag;
  no = leng / 2;
  y = dgetmem(leng + no);
  mag = y + leng;
  fftr(x, y, leng);
  for (k = 1; k < no; k++) {
    mag[k] = x[k] * x[k] + y[k] * y[k];
    sp[k] = sqrt(mag[k]);
  }
  free(y);
}


x86 assembly (clang, -O0):
<spec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
add    -0x1c(%rbp),%edi
call   1060 <dgetmem@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x14(%rbp),%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <fftr@plt>
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    121c <spec+0xdc>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x28(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x28(%rbp),%rax
movslq -0x18(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x30(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1050 <sqrt@plt>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    119a <spec+0x5a>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spec>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r12d
mov    %rsi,%r14
mov    %rdi,%r13
mov    %edx,%ebx
shr    $0x1f,%ebx
add    %edx,%ebx
sar    %ebx
lea    (%rbx,%r12,1),%edi
call   1060 <dgetmem@plt>
mov    %rax,%r15
mov    %r13,%rdi
mov    %rax,%rsi
mov    %r12d,%edx
call   1040 <fftr@plt>
cmp    $0x4,%r12d
jl     12cd <spec+0x18d>
cmp    $0x3,%ebx
mov    $0x2,%ecx
cmovge %ebx,%ecx
movslq %r12d,%rax
mov    %rax,0x8(%rsp)
add    $0xffffffffffffffff,%rcx
mov    %rcx,0x10(%rsp)
mov    $0x1,%ebx
cmp    $0x6,%r12d
jge    11f4 <spec+0xb4>
testb  $0x1,0x10(%rsp)
je     12cd <spec+0x18d>
mov    0x8(%rsp),%rax
lea    (%r15,%rax,8),%rax
movsd  0x0(%r13,%rbx,8),%xmm0
movsd  (%r15,%rbx,8),%xmm1
mulsd  %xmm1,%xmm1
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rbx,8)
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     12c2 <spec+0x182>
sqrtsd %xmm0,%xmm0
jmp    12c7 <spec+0x187>
mov    0x8(%rsp),%rax
lea    (%r15,%rax,8),%rbp
add    $0x8,%rbp
mov    0x10(%rsp),%r12
and    $0xfffffffffffffffe,%r12
neg    %r12
mov    $0x1,%ebx
xorpd  %xmm2,%xmm2
jmp    1246 <spec+0x106>
nopl   0x0(%rax,%rax,1)
call   1050 <sqrt@plt>
xorpd  %xmm2,%xmm2
movsd  %xmm0,0x8(%r14,%rbx,8)
lea    (%r12,%rbx,1),%rax
add    $0x2,%rax
add    $0x2,%rbx
cmp    $0x1,%rax
je     11ab <spec+0x6b>
movsd  0x0(%r13,%rbx,8),%xmm0
movsd  (%r15,%rbx,8),%xmm1
mulsd  %xmm1,%xmm1
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp,%rbx,8)
ucomisd %xmm2,%xmm0
jb     1280 <spec+0x140>
sqrtsd %xmm0,%xmm0
jmp    1289 <spec+0x149>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
call   1050 <sqrt@plt>
xorpd  %xmm2,%xmm2
movsd  %xmm0,(%r14,%rbx,8)
movsd  0x8(%r13,%rbx,8),%xmm0
movsd  0x8(%r15,%rbx,8),%xmm1
mulsd  %xmm1,%xmm1
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x0(%rbp,%rbx,8)
ucomisd %xmm2,%xmm0
jb     1220 <spec+0xe0>
sqrtsd %xmm0,%xmm0
jmp    1229 <spec+0xe9>
call   1050 <sqrt@plt>
movsd  %xmm0,(%r14,%rbx,8)
mov    %r15,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
define void @spec(double* %0, double* %1, i32 %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca double*
%10 = alloca double*
store double* %0, double** %4
store double* %1, double** %5
store i32 %2, i32* %6
%11 = load i32, i32* %6
%12 = sdiv i32 %11, 2
store i32 %12, i32* %8
%13 = load i32, i32* %6
%14 = load i32, i32* %8
%15 = add nsw i32 %13, %14
%16 = call double* @dgetmem(i32 %15)
store double* %16, double** %9
%17 = load double*, double** %9
%18 = load i32, i32* %6
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds double, double* %17, i64 %19
store double* %20, double** %10
%21 = load double*, double** %4
%22 = load double*, double** %9
%23 = load i32, i32* %6
%24 = call i32 @fftr(double* %21, double* %22, i32 %23)
store i32 1, i32* %7
br label %25
25: ; preds = %66, %3
%26 = load i32, i32* %7
%27 = load i32, i32* %8
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %69
29: ; preds = %25
%30 = load double*, double** %4
%31 = load i32, i32* %7
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds double, double* %30, i64 %32
%34 = load double, double* %33
%35 = load double*, double** %4
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds double, double* %35, i64 %37
%39 = load double, double* %38
%40 = load double*, double** %9
%41 = load i32, i32* %7
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds double, double* %40, i64 %42
%44 = load double, double* %43
%45 = load double*, double** %9
%46 = load i32, i32* %7
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds double, double* %45, i64 %47
%49 = load double, double* %48
%50 = fmul double %44, %49
%51 = call double @llvm.fmuladd.f64(double %34, double %39, double %50)
%52 = load double*, double** %10
%53 = load i32, i32* %7
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds double, double* %52, i64 %54
store double %51, double* %55
%56 = load double*, double** %10
%57 = load i32, i32* %7
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds double, double* %56, i64 %58
%60 = load double, double* %59
%61 = call double @sqrt(double %60)
%62 = load double*, double** %5
%63 = load i32, i32* %7
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds double, double* %62, i64 %64
store double %61, double* %65
br label %66
66: ; preds = %29
%67 = load i32, i32* %7
%68 = add nsw i32 %67, 1
store i32 %68, i32* %7
br label %25
69: ; preds = %25
%70 = load double*, double** %9
%71 = call i32 @free(double* %70)
ret void
}

LLVM IR (-O2):
define void @spec(double* %0, double* nocapture writeonly %1, i32 %2) {
%4 = sdiv i32 %2, 2
%5 = add nsw i32 %4, %2
%6 = tail call double* @dgetmem(i32 %5)
%7 = sext i32 %2 to i64
%8 = getelementptr inbounds double, double* %6, i64 %7
%9 = tail call i32 @fftr(double* %0, double* %6, i32 %2)
%10 = icmp sgt i32 %2, 3
br i1 %10, label %11, label %57
11: ; preds = %3
%12 = call i32 @llvm.smax.i32(i32 %4, i32 2)
%13 = zext i32 %12 to i64
%14 = add nsw i64 %13, -1
%15 = and i64 %14, 1
%16 = icmp slt i32 %2, 6
br i1 %16, label %44, label %17
17: ; preds = %11
%18 = and i64 %14, -2
br label %19
19: ; preds = %19, %17
%20 = phi i64 [ 1, %17 ], [ %41, %19 ]
%21 = phi i64 [ 0, %17 ], [ %42, %19 ]
%22 = getelementptr inbounds double, double* %0, i64 %20
%23 = load double, double* %22
%24 = getelementptr inbounds double, double* %6, i64 %20
%25 = load double, double* %24
%26 = fmul double %25, %25
%27 = tail call double @llvm.fmuladd.f64(double %23, double %23, double %26)
%28 = getelementptr inbounds double, double* %8, i64 %20
store double %27, double* %28
%29 = tail call double @sqrt(double %27)
%30 = getelementptr inbounds double, double* %1, i64 %20
store double %29, double* %30
%31 = add nuw nsw i64 %20, 1
%32 = getelementptr inbounds double, double* %0, i64 %31
%33 = load double, double* %32
%34 = getelementptr inbounds double, double* %6, i64 %31
%35 = load double, double* %34
%36 = fmul double %35, %35
%37 = tail call double @llvm.fmuladd.f64(double %33, double %33, double %36)
%38 = getelementptr inbounds double, double* %8, i64 %31
store double %37, double* %38
%39 = tail call double @sqrt(double %37)
%40 = getelementptr inbounds double, double* %1, i64 %31
store double %39, double* %40
%41 = add nuw nsw i64 %20, 2
%42 = add i64 %21, 2
%43 = icmp eq i64 %42, %18
br i1 %43, label %44, label %19
44: ; preds = %19, %11
%45 = phi i64 [ 1, %11 ], [ %41, %19 ]
%46 = icmp eq i64 %15, 0
br i1 %46, label %57, label %47
47: ; preds = %44
%48 = getelementptr inbounds double, double* %0, i64 %45
%49 = load double, double* %48
%50 = getelementptr inbounds double, double* %6, i64 %45
%51 = load double, double* %50
%52 = fmul double %51, %51
%53 = tail call double @llvm.fmuladd.f64(double %49, double %49, double %52)
%54 = getelementptr inbounds double, double* %8, i64 %45
store double %53, double* %54
%55 = tail call double @sqrt(double %53)
%56 = getelementptr inbounds double, double* %1, i64 %45
store double %55, double* %56
br label %57
57: ; preds = %47, %44, %3
%58 = tail call i32 @free(double* %6)
ret void
}