#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 atan2(double, double);
void HC_to_polar2(long len, const double *freq, int conj, double scale,
                  double *amp2, double *phs) {
  int i;
  double rl, im;
  phs[0] = 0.0;
  amp2[0] = freq[0] * freq[0] / scale;
  for (i = 1; i < (len + 1) / 2; i++) {
    rl = freq[i];
    im = freq[len - i];
    amp2[i] = (rl * rl + im * im) / scale;
    if (amp2[i] > 0.0) {
      if (conj == 0)
        phs[i] = atan2(+im, rl);
      else
        phs[i] = atan2(-im, rl);
    } else {
      phs[i] = 0.0;
    }
  }
  if (len % 2 == 0) {
    phs[len / 2] = 0.0;
    amp2[len / 2] = freq[len / 2] * freq[len / 2] / scale;
  }
}


x86 assembly (clang, -O0):
<HC_to_polar2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movsd  %xmm0,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x30(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
mulsd  (%rax),%xmm0
divsd  -0x20(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x1,-0x34(%rbp)
movslq -0x34(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
cmp    %rcx,%rax
jge    1282 <HC_to_polar2+0x172>
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq -0x34(%rbp),%rdx
sub    %rdx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm2
movsd  -0x48(%rbp),%xmm1
mulsd  -0x48(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
divsd  -0x20(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    125f <HC_to_polar2+0x14f>
cmpl   $0x0,-0x14(%rbp)
jne    1227 <HC_to_polar2+0x117>
movsd  -0x48(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
call   1030 <atan2@plt>
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    125a <HC_to_polar2+0x14a>
movsd  -0x48(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  -0x40(%rbp),%xmm1
call   1030 <atan2@plt>
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    126f <HC_to_polar2+0x15f>
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
jmp    1274 <HC_to_polar2+0x164>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    115f <HC_to_polar2+0x4f>
mov    -0x8(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    132a <HC_to_polar2+0x21a>
mov    -0x30(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x8(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x70(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x8(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x68(%rbp),%rax
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x8(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x60(%rbp),%rax
mulsd  (%rax,%rcx,8),%xmm0
divsd  -0x20(%rbp),%xmm0
mov    -0x28(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x8(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x58(%rbp),%rax
movsd  %xmm0,(%rax,%rcx,8)
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HC_to_polar2>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,%r15
mov    %rcx,%r14
movapd %xmm0,%xmm4
mov    %edx,0x4(%rsp)
mov    %rsi,%rbx
movq   $0x0,(%r8)
movsd  (%rsi),%xmm0
mulsd  %xmm0,%xmm0
divsd  %xmm4,%xmm0
movsd  %xmm0,(%rcx)
mov    %rdi,0x8(%rsp)
cmp    $0x3,%rdi
jl     11e7 <HC_to_polar2+0xd7>
mov    0x8(%rsp),%rax
lea    0x1(%rax),%rbp
shr    %rbp
lea    (%rbx,%rax,8),%r12
add    $0xfffffffffffffff8,%r12
mov    $0x1,%r13d
movsd  %xmm4,0x10(%rsp)
jmp    11a2 <HC_to_polar2+0x92>
nopw   0x0(%rax,%rax,1)
call   1030 <atan2@plt>
movapd %xmm0,%xmm2
movsd  0x10(%rsp),%xmm4
movsd  %xmm2,(%r15,%r13,8)
add    $0x1,%r13
add    $0xfffffffffffffff8,%r12
cmp    %r13,%rbp
je     11e7 <HC_to_polar2+0xd7>
movsd  (%rbx,%r13,8),%xmm1
movsd  (%r12),%xmm0
movapd %xmm0,%xmm2
mulsd  %xmm0,%xmm2
movapd %xmm1,%xmm3
mulsd  %xmm1,%xmm3
addsd  %xmm2,%xmm3
divsd  %xmm4,%xmm3
movsd  %xmm3,(%r14,%r13,8)
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm3
jbe    118f <HC_to_polar2+0x7f>
cmpl   $0x0,0x4(%rsp)
je     1180 <HC_to_polar2+0x70>
xorpd  0xe1b(%rip),%xmm0
jmp    1180 <HC_to_polar2+0x70>
mov    0x8(%rsp),%rcx
test   $0x1,%cl
jne    121e <HC_to_polar2+0x10e>
mov    %rcx,%rax
shr    $0x3f,%rax
add    %rcx,%rax
shl    $0x2,%rax
and    $0xfffffffffffffff8,%rax
movq   $0x0,(%r15,%rax,1)
movsd  (%rbx,%rax,1),%xmm0
mulsd  %xmm0,%xmm0
divsd  %xmm4,%xmm0
movsd  %xmm0,(%r14,%rax,1)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @HC_to_polar2(i64 %0, double* nocapture %1, i32 %2, double %3, double* nocapture writeonly %4, double* nocapture writeonly %5) {
store double 0.000000e+00, double* %5
%7 = load double, double* %1
%8 = fmul double %7, %7
%9 = fdiv double %8, %3
store double %9, double* %4
%10 = icmp sgt i64 %0, 2
br i1 %10, label %11, label %36
11: ; preds = %6
%12 = add nuw nsw i64 %0, 1
%13 = lshr i64 %12, 1
%14 = icmp eq i32 %2, 0
br label %15
15: ; preds = %11, %31
%16 = phi i64 [ 1, %11 ], [ %34, %31 ]
%17 = getelementptr inbounds double, double* %1, i64 %16
%18 = load double, double* %17
%19 = sub nsw i64 %0, %16
%20 = getelementptr inbounds double, double* %1, i64 %19
%21 = load double, double* %20
%22 = fmul double %21, %21
%23 = tail call double @llvm.fmuladd.f64(double %18, double %18, double %22)
%24 = fdiv double %23, %3
%25 = getelementptr inbounds double, double* %4, i64 %16
store double %24, double* %25
%26 = fcmp ogt double %24, 0.000000e+00
br i1 %26, label %27, label %31
27: ; preds = %15
%28 = fneg double %21
%29 = select i1 %14, double %21, double %28
%30 = tail call double @atan2(double %29, double %18)
br label %31
31: ; preds = %27, %15
%32 = phi double [ 0.000000e+00, %15 ], [ %30, %27 ]
%33 = getelementptr inbounds double, double* %5, i64 %16
store double %32, double* %33
%34 = add nuw nsw i64 %16, 1
%35 = icmp eq i64 %34, %13
br i1 %35, label %36, label %15
36: ; preds = %31, %6
%37 = and i64 %0, 1
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %47
39: ; preds = %36
%40 = sdiv i64 %0, 2
%41 = getelementptr inbounds double, double* %5, i64 %40
store double 0.000000e+00, double* %41
%42 = getelementptr inbounds double, double* %1, i64 %40
%43 = load double, double* %42
%44 = fmul double %43, %43
%45 = fdiv double %44, %3
%46 = getelementptr inbounds double, double* %4, i64 %40
store double %45, double* %46
br label %47
47: ; preds = %39, %36
ret void
}