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


x86 assembly (clang, -O0):
<HC_to_polar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x28(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
mulsd  (%rax),%xmm0
call   1040 <sqrt@plt>
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x1,-0x2c(%rbp)
movslq -0x2c(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
cmp    %rcx,%rax
jge    128d <HC_to_polar+0x16d>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq -0x2c(%rbp),%rdx
sub    %rdx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm2
movsd  -0x40(%rbp),%xmm1
mulsd  -0x40(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    126a <HC_to_polar+0x14a>
cmpl   $0x0,-0x14(%rbp)
jne    1232 <HC_to_polar+0x112>
movsd  -0x40(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
call   1030 <atan2@plt>
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    1265 <HC_to_polar+0x145>
movsd  -0x40(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  -0x38(%rbp),%xmm1
call   1030 <atan2@plt>
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    127a <HC_to_polar+0x15a>
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
jmp    127f <HC_to_polar+0x15f>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    116a <HC_to_polar+0x4a>
mov    -0x8(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    1335 <HC_to_polar+0x215>
mov    -0x28(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x8(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x68(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
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
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x8(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x58(%rbp),%rax
mulsd  (%rax,%rcx,8),%xmm0
call   1040 <sqrt@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x8(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
movsd  %xmm0,(%rax,%rcx,8)
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HC_to_polar>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r8,%r15
mov    %rcx,%r14
mov    %edx,0xc(%rsp)
mov    %rsi,%rbx
mov    %rdi,%rbp
movq   $0x0,(%r8)
movsd  (%rsi),%xmm0
mulsd  %xmm0,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     115d <HC_to_polar+0x3d>
sqrtsd %xmm0,%xmm0
jmp    1162 <HC_to_polar+0x42>
call   1040 <sqrt@plt>
movsd  %xmm0,(%r14)
mov    %rbp,0x10(%rsp)
cmp    $0x3,%rbp
jl     1235 <HC_to_polar+0x115>
mov    0x10(%rsp),%rax
lea    0x1(%rax),%rbp
shr    %rbp
lea    (%rbx,%rax,8),%r12
add    $0xfffffffffffffff8,%r12
mov    $0x1,%r13d
jmp    11c0 <HC_to_polar+0xa0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movapd %xmm3,%xmm0
call   1030 <atan2@plt>
movapd %xmm0,%xmm2
movsd  %xmm2,(%r15,%r13,8)
add    $0x1,%r13
add    $0xfffffffffffffff8,%r12
cmp    %r13,%rbp
je     1235 <HC_to_polar+0x115>
movsd  (%rbx,%r13,8),%xmm1
movsd  (%r12),%xmm3
movapd %xmm3,%xmm2
mulsd  %xmm3,%xmm2
movapd %xmm1,%xmm0
mulsd  %xmm1,%xmm0
addsd  %xmm2,%xmm0
ucomisd 0xe28(%rip),%xmm0
jb     11f0 <HC_to_polar+0xd0>
sqrtsd %xmm0,%xmm0
jmp    120d <HC_to_polar+0xed>
movsd  %xmm1,0x18(%rsp)
movapd %xmm3,0x20(%rsp)
call   1040 <sqrt@plt>
movapd 0x20(%rsp),%xmm3
movsd  0x18(%rsp),%xmm1
movsd  %xmm0,(%r14,%r13,8)
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm0
jbe    11ad <HC_to_polar+0x8d>
cmpl   $0x0,0xc(%rsp)
je     11a0 <HC_to_polar+0x80>
xorpd  0xdd0(%rip),%xmm3
jmp    11a0 <HC_to_polar+0x80>
mov    0x10(%rsp),%rax
test   $0x1,%al
jne    1277 <HC_to_polar+0x157>
mov    %rax,%rbp
shr    $0x3f,%rbp
add    %rax,%rbp
sar    %rbp
movq   $0x0,(%r15,%rbp,8)
movsd  (%rbx,%rbp,8),%xmm0
mulsd  %xmm0,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     126c <HC_to_polar+0x14c>
sqrtsd %xmm0,%xmm0
jmp    1271 <HC_to_polar+0x151>
call   1040 <sqrt@plt>
movsd  %xmm0,(%r14,%rbp,8)
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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