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


x86 assembly (clang, -O0):
<polar_to_HC_scale>:
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    %r8d,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movslq -0x2c(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq -0x20(%rbp),%rdx
imul   %rdx,%rcx
cmp    %rcx,%rax
jge    117d <polar_to_HC_scale+0x5d>
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1146 <polar_to_HC_scale+0x26>
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    12d0 <polar_to_HC_scale+0x1b0>
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    1237 <polar_to_HC_scale+0x117>
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    1283 <polar_to_HC_scale+0x163>
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
mov    -0x2c(%rbp),%ecx
imul   -0x20(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x40(%rbp),%xmm0
mov    -0x28(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq -0x20(%rbp),%rdx
imul   %rdx,%rcx
mov    -0x2c(%rbp),%edx
imul   -0x20(%rbp),%edx
movslq %edx,%rdx
sub    %rdx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1194 <polar_to_HC_scale+0x74>
mov    -0x8(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    1317 <polar_to_HC_scale+0x1f7>
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    -0x28(%rbp),%rax
mov    -0x8(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<polar_to_HC_scale>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %r9,%r14
mov    %ecx,0xc(%rsp)
mov    %rdx,%rbp
mov    %rsi,%rbx
mov    %rdi,%r15
movslq %r8d,%rdx
mov    %rdx,%r13
imul   %rdi,%rdx
test   %rdx,%rdx
jle    116b <polar_to_HC_scale+0x3b>
shl    $0x3,%rdx
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <memset@plt>
movsd  (%rbx),%xmm0
mov    %r14,0x10(%rsp)
movsd  %xmm0,(%r14)
mov    %r15,0x18(%rsp)
cmp    $0x3,%r15
jl     127a <polar_to_HC_scale+0x14a>
mov    0x18(%rsp),%rax
lea    0x1(%rax),%rcx
shr    %rcx
mov    %rcx,0x48(%rsp)
mov    0x10(%rsp),%rcx
lea    (%rcx,%r13,8),%r15
add    $0xffffffffffffffff,%rax
imul   %r13,%rax
shl    $0x3,%r13
lea    (%rcx,%rax,8),%r12
mov    %r13,0x50(%rsp)
neg    %r13
mov    $0x1,%r14d
jmp    1228 <polar_to_HC_scale+0xf8>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xorps  0xe29(%rip),%xmm2
movaps %xmm2,0x30(%rsp)
movsd  0x0(%rbp,%r14,8),%xmm0
call   1040 <sin@plt>
movsd  0x20(%rsp),%xmm2
movapd %xmm0,%xmm1
movapd 0x30(%rsp),%xmm0
movapd %xmm1,%xmm3
movsd  0x28(%rsp),%xmm1
mulsd  %xmm3,%xmm0
mulsd  %xmm2,%xmm1
movsd  %xmm1,(%r15)
movsd  %xmm0,(%r12)
add    $0x1,%r14
add    0x50(%rsp),%r15
add    %r13,%r12
cmp    %r14,0x48(%rsp)
je     127a <polar_to_HC_scale+0x14a>
movsd  (%rbx,%r14,8),%xmm0
movsd  %xmm0,0x28(%rsp)
movsd  0x0(%rbp,%r14,8),%xmm0
call   1050 <cos@plt>
movapd %xmm0,%xmm1
movsd  (%rbx,%r14,8),%xmm2
cmpl   $0x0,0xc(%rsp)
movsd  %xmm0,0x20(%rsp)
jne    11d0 <polar_to_HC_scale+0xa0>
movsd  0x0(%rbp,%r14,8),%xmm0
movaps %xmm2,0x30(%rsp)
call   1040 <sin@plt>
movapd 0x30(%rsp),%xmm3
movsd  0x20(%rsp),%xmm2
jmp    11fc <polar_to_HC_scale+0xcc>
mov    0x18(%rsp),%rcx
test   $0x1,%cl
jne    12a1 <polar_to_HC_scale+0x171>
mov    %rcx,%rax
shr    $0x3f,%rax
add    %rcx,%rax
and    $0xfffffffffffffffe,%rax
movsd  (%rbx,%rax,4),%xmm0
mov    0x10(%rsp),%rax
movsd  %xmm0,(%rax,%rcx,8)
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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