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


x86 assembly (clang, -O0):
<polar_to_HC>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x28(%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    127a <polar_to_HC+0x15a>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1040 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    11f5 <polar_to_HC+0xd5>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1030 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x58(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    1241 <polar_to_HC+0x121>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1030 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x60(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x40(%rbp),%xmm0
mov    -0x28(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq -0x2c(%rbp),%rdx
sub    %rdx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1152 <polar_to_HC+0x32>
mov    -0x8(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    12d6 <polar_to_HC+0x1b6>
mov    -0x10(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x8(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x70(%rbp),%rax
movsd  (%rax,%rcx,8),%xmm0
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
movsd  %xmm0,(%rax,%rcx,8)
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<polar_to_HC>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%rbx
movsd  (%rsi),%xmm0
mov    %r8,(%rsp)
movsd  %xmm0,(%r8)
mov    %rdi,0x8(%rsp)
cmp    $0x3,%rdi
jl     1226 <polar_to_HC+0x106>
mov    %ecx,%r12d
mov    %rdx,%rbp
mov    0x8(%rsp),%rcx
lea    0x1(%rcx),%r13
shr    %r13
mov    (%rsp),%rax
lea    (%rax,%rcx,8),%r15
add    $0xfffffffffffffff8,%r15
mov    $0x1,%r14d
jmp    11d6 <polar_to_HC+0xb6>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xorps  0xe79(%rip),%xmm2
movaps %xmm2,0x20(%rsp)
movsd  0x0(%rbp,%r14,8),%xmm0
call   1030 <sin@plt>
movsd  0x10(%rsp),%xmm2
movapd %xmm0,%xmm1
movapd 0x20(%rsp),%xmm0
movapd %xmm1,%xmm3
movsd  0x18(%rsp),%xmm1
mulsd  %xmm3,%xmm0
mulsd  %xmm2,%xmm1
mov    (%rsp),%rax
movsd  %xmm1,(%rax,%r14,8)
movsd  %xmm0,(%r15)
add    $0x1,%r14
add    $0xfffffffffffffff8,%r15
cmp    %r14,%r13
je     1226 <polar_to_HC+0x106>
movsd  (%rbx,%r14,8),%xmm0
movsd  %xmm0,0x18(%rsp)
movsd  0x0(%rbp,%r14,8),%xmm0
call   1040 <cos@plt>
movapd %xmm0,%xmm1
movsd  (%rbx,%r14,8),%xmm2
test   %r12d,%r12d
movsd  %xmm0,0x10(%rsp)
jne    1180 <polar_to_HC+0x60>
movsd  0x0(%rbp,%r14,8),%xmm0
movaps %xmm2,0x20(%rsp)
call   1030 <sin@plt>
movapd 0x20(%rsp),%xmm3
movsd  0x10(%rsp),%xmm2
jmp    11ac <polar_to_HC+0x8c>
mov    0x8(%rsp),%rcx
test   $0x1,%cl
jne    1250 <polar_to_HC+0x130>
mov    %rcx,%rax
shr    $0x3f,%rax
add    %rcx,%rax
shl    $0x2,%rax
and    $0xfffffffffffffff8,%rax
movsd  (%rbx,%rax,1),%xmm0
mov    (%rsp),%rcx
movsd  %xmm0,(%rcx,%rax,1)
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @polar_to_HC(i64 %0, double* %1, double* %2, i32 %3, double* %4) {
%6 = alloca i64
%7 = alloca double*
%8 = alloca double*
%9 = alloca i32
%10 = alloca double*
%11 = alloca i32
%12 = alloca double
%13 = alloca double
store i64 %0, i64* %6
store double* %1, double** %7
store double* %2, double** %8
store i32 %3, i32* %9
store double* %4, double** %10
%14 = load double*, double** %7
%15 = getelementptr inbounds double, double* %14, i64 0
%16 = load double, double* %15
%17 = load double*, double** %10
%18 = getelementptr inbounds double, double* %17, i64 0
store double %16, double* %18
store i32 1, i32* %11
br label %19
19: ; preds = %81, %5
%20 = load i32, i32* %11
%21 = sext i32 %20 to i64
%22 = load i64, i64* %6
%23 = add nsw i64 %22, 1
%24 = sdiv i64 %23, 2
%25 = icmp slt i64 %21, %24
br i1 %25, label %26, label %84
26: ; preds = %19
%27 = load double*, double** %7
%28 = load i32, i32* %11
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds double, double* %27, i64 %29
%31 = load double, double* %30
%32 = load double*, double** %8
%33 = load i32, i32* %11
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds double, double* %32, i64 %34
%36 = load double, double* %35
%37 = call double @cos(double %36)
%38 = fmul double %31, %37
store double %38, double* %12
%39 = load i32, i32* %9
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %54
41: ; preds = %26
%42 = load double*, double** %7
%43 = load i32, i32* %11
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds double, double* %42, i64 %44
%46 = load double, double* %45
%47 = load double*, double** %8
%48 = load i32, i32* %11
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds double, double* %47, i64 %49
%51 = load double, double* %50
%52 = call double @sin(double %51)
%53 = fmul double %46, %52
store double %53, double* %13
br label %68
54: ; preds = %26
%55 = load double*, double** %7
%56 = load i32, i32* %11
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds double, double* %55, i64 %57
%59 = load double, double* %58
%60 = fneg double %59
%61 = load double*, double** %8
%62 = load i32, i32* %11
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds double, double* %61, i64 %63
%65 = load double, double* %64
%66 = call double @sin(double %65)
%67 = fmul double %60, %66
store double %67, double* %13
br label %68
68: ; preds = %54, %41
%69 = load double, double* %12
%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
%74 = load double, double* %13
%75 = load double*, double** %10
%76 = load i64, i64* %6
%77 = load i32, i32* %11
%78 = sext i32 %77 to i64
%79 = sub nsw i64 %76, %78
%80 = getelementptr inbounds double, double* %75, i64 %79
store double %74, double* %80
br label %81
81: ; preds = %68
%82 = load i32, i32* %11
%83 = add nsw i32 %82, 1
store i32 %83, i32* %11
br label %19
84: ; preds = %19
%85 = load i64, i64* %6
%86 = srem i64 %85, 2
%87 = icmp eq i64 %86, 0
br i1 %87, label %88, label %98
88: ; preds = %84
%89 = load double*, double** %7
%90 = load i64, i64* %6
%91 = sdiv i64 %90, 2
%92 = getelementptr inbounds double, double* %89, i64 %91
%93 = load double, double* %92
%94 = load double*, double** %10
%95 = load i64, i64* %6
%96 = sdiv i64 %95, 2
%97 = getelementptr inbounds double, double* %94, i64 %96
store double %93, double* %97
br label %98
98: ; preds = %88, %84
ret void
}

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