#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);
int /*<<< orphan*/ fht(double *);
void psycho_2_fft(double *x_real, double *energy, double *phi) {
  double imag, real;
  int i, j;
  fht(x_real);
  energy[0] = x_real[0] * x_real[0];
  for (i = 1, j = 1023; i < 512; i++, j--) {
    imag = x_real[i];
    real = x_real[j];
    energy[i] = (imag * imag + real * real) / 2.0;
    if (energy[i] < 0.0005) {
      energy[i] = 0.0005;
      phi[i] = 0;
    } else {
      phi[i] = atan2(-(double)imag, (double)real) + 3.14159265358979 / 4;
    }
  }
  energy[512] = x_real[512] * x_real[512];
  phi[512] = atan2(0.0, (double)x_real[512]);
}


x86 assembly (clang, -O0):
<psycho_2_fft>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <fht@plt>
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x8(%rbp),%rax
mulsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x1,-0x2c(%rbp)
movl   $0x3ff,-0x30(%rbp)
cmpl   $0x200,-0x2c(%rbp)
jge    1269 <psycho_2_fft+0x149>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm1
mulsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe50(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  0xe27(%rip),%xmm0
ucomisd (%rax,%rcx,8),%xmm0
jbe    120e <psycho_2_fft+0xee>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  0xe0c(%rip),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
jmp    124d <psycho_2_fft+0x12d>
movsd  -0x20(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  -0x28(%rbp),%xmm1
call   1030 <atan2@plt>
movsd  0xdd4(%rip),%xmm1
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    1252 <psycho_2_fft+0x132>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x30(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x30(%rbp)
jmp    1163 <psycho_2_fft+0x43>
mov    -0x8(%rbp),%rax
movsd  0x1000(%rax),%xmm0
mov    -0x8(%rbp),%rax
mulsd  0x1000(%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x1000(%rax)
mov    -0x8(%rbp),%rax
movsd  0x1000(%rax),%xmm1
xorps  %xmm0,%xmm0
call   1030 <atan2@plt>
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x1000(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<psycho_2_fft>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
call   1040 <fht@plt>
movsd  (%r12),%xmm0
mulsd  %xmm0,%xmm0
movsd  %xmm0,(%r15)
mov    $0x1,%ebx
mov    $0x1ff8,%r13d
movsd  0xea5(%rip),%xmm4
movsd  0xea5(%rip),%xmm5
movabs $0x3f40624dd2f1a9fc,%rbp
62 40 3f
jmp    11ac <psycho_2_fft+0x8c>
nop
xorpd  0xea8(%rip),%xmm0
call   1030 <atan2@plt>
movsd  0xe83(%rip),%xmm5
movsd  0xe73(%rip),%xmm4
addsd  0xe7b(%rip),%xmm0
movsd  %xmm0,(%r14,%rbx,8)
add    $0x1,%rbx
add    $0xfffffffffffffff8,%r13
cmp    $0x200,%rbx
je     11e6 <psycho_2_fft+0xc6>
movsd  (%r12,%rbx,8),%xmm0
movsd  (%r12,%r13,1),%xmm1
movapd %xmm1,%xmm2
mulsd  %xmm1,%xmm2
movapd %xmm0,%xmm3
mulsd  %xmm0,%xmm3
addsd  %xmm2,%xmm3
mulsd  %xmm4,%xmm3
movsd  %xmm3,(%r15,%rbx,8)
ucomisd %xmm3,%xmm5
jbe    1170 <psycho_2_fft+0x50>
mov    %rbp,(%r15,%rbx,8)
xorpd  %xmm0,%xmm0
jmp    1195 <psycho_2_fft+0x75>
movsd  0x1000(%r12),%xmm0
mulsd  %xmm0,%xmm0
movsd  %xmm0,0x1000(%r15)
movsd  0x1000(%r12),%xmm1
xorpd  %xmm0,%xmm0
call   1030 <atan2@plt>
movsd  %xmm0,0x1000(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @psycho_2_fft(double* %0, double* %1, double* %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca double*
%7 = alloca double
%8 = alloca double
%9 = alloca i32
%10 = alloca i32
store double* %0, double** %4
store double* %1, double** %5
store double* %2, double** %6
%11 = load double*, double** %4
%12 = call i32 @fht(double* %11)
%13 = load double*, double** %4
%14 = getelementptr inbounds double, double* %13, i64 0
%15 = load double, double* %14
%16 = load double*, double** %4
%17 = getelementptr inbounds double, double* %16, i64 0
%18 = load double, double* %17
%19 = fmul double %15, %18
%20 = load double*, double** %5
%21 = getelementptr inbounds double, double* %20, i64 0
store double %19, double* %21
store i32 1, i32* %9
store i32 1023, i32* %10
br label %22
22: ; preds = %73, %3
%23 = load i32, i32* %9
%24 = icmp slt i32 %23, 512
br i1 %24, label %25, label %78
25: ; preds = %22
%26 = load double*, double** %4
%27 = load i32, i32* %9
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double, double* %26, i64 %28
%30 = load double, double* %29
store double %30, double* %7
%31 = load double*, double** %4
%32 = load i32, i32* %10
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double, double* %31, i64 %33
%35 = load double, double* %34
store double %35, double* %8
%36 = load double, double* %7
%37 = load double, double* %7
%38 = load double, double* %8
%39 = load double, double* %8
%40 = fmul double %38, %39
%41 = call double @llvm.fmuladd.f64(double %36, double %37, double %40)
%42 = fdiv double %41, 2.000000e+00
%43 = load double*, double** %5
%44 = load i32, i32* %9
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds double, double* %43, i64 %45
store double %42, double* %46
%47 = load double*, double** %5
%48 = load i32, i32* %9
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds double, double* %47, i64 %49
%51 = load double, double* %50
%52 = fcmp olt double %51, 5.000000e-04
br i1 %52, label %53, label %62
53: ; preds = %25
%54 = load double*, double** %5
%55 = load i32, i32* %9
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds double, double* %54, i64 %56
store double 5.000000e-04, double* %57
%58 = load double*, double** %6
%59 = load i32, i32* %9
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds double, double* %58, i64 %60
store double 0.000000e+00, double* %61
br label %72
62: ; preds = %25
%63 = load double, double* %7
%64 = fneg double %63
%65 = load double, double* %8
%66 = call double @atan2(double %64, double %65)
%67 = fadd double %66, 0x3FE921FB54442D11
%68 = load double*, double** %6
%69 = load i32, i32* %9
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds double, double* %68, i64 %70
store double %67, double* %71
br label %72
72: ; preds = %62, %53
br label %73
73: ; preds = %72
%74 = load i32, i32* %9
%75 = add nsw i32 %74, 1
store i32 %75, i32* %9
%76 = load i32, i32* %10
%77 = add nsw i32 %76, -1
store i32 %77, i32* %10
br label %22
78: ; preds = %22
%79 = load double*, double** %4
%80 = getelementptr inbounds double, double* %79, i64 512
%81 = load double, double* %80
%82 = load double*, double** %4
%83 = getelementptr inbounds double, double* %82, i64 512
%84 = load double, double* %83
%85 = fmul double %81, %84
%86 = load double*, double** %5
%87 = getelementptr inbounds double, double* %86, i64 512
store double %85, double* %87
%88 = load double*, double** %4
%89 = getelementptr inbounds double, double* %88, i64 512
%90 = load double, double* %89
%91 = call double @atan2(double 0.000000e+00, double %90)
%92 = load double*, double** %6
%93 = getelementptr inbounds double, double* %92, i64 512
store double %91, double* %93
ret void
}

LLVM IR (-O2):
define void @psycho_2_fft(double* %0, double* nocapture writeonly %1, double* nocapture writeonly %2) {
%4 = tail call i32 @fht(double* %0)
%5 = load double, double* %0
%6 = fmul double %5, %5
store double %6, double* %1
br label %7
7: ; preds = %3, %24
%8 = phi i64 [ 1, %3 ], [ %27, %24 ]
%9 = phi i64 [ 1023, %3 ], [ %28, %24 ]
%10 = getelementptr inbounds double, double* %0, i64 %8
%11 = load double, double* %10
%12 = getelementptr inbounds double, double* %0, i64 %9
%13 = load double, double* %12
%14 = fmul double %13, %13
%15 = tail call double @llvm.fmuladd.f64(double %11, double %11, double %14)
%16 = fmul double %15, 5.000000e-01
%17 = getelementptr inbounds double, double* %1, i64 %8
store double %16, double* %17
%18 = fcmp olt double %16, 5.000000e-04
br i1 %18, label %19, label %20
19: ; preds = %7
store double 5.000000e-04, double* %17
br label %24
20: ; preds = %7
%21 = fneg double %11
%22 = tail call double @atan2(double %21, double %13)
%23 = fadd double %22, 0x3FE921FB54442D11
br label %24
24: ; preds = %19, %20
%25 = phi double [ 0.000000e+00, %19 ], [ %23, %20 ]
%26 = getelementptr inbounds double, double* %2, i64 %8
store double %25, double* %26
%27 = add nuw nsw i64 %8, 1
%28 = add nsw i64 %9, -1
%29 = icmp eq i64 %27, 512
br i1 %29, label %30, label %7
30: ; preds = %24
%31 = getelementptr inbounds double, double* %0, i64 512
%32 = load double, double* %31
%33 = fmul double %32, %32
%34 = getelementptr inbounds double, double* %1, i64 512
store double %33, double* %34
%35 = load double, double* %31
%36 = tail call double @atan2(double 0.000000e+00, double %35)
%37 = getelementptr inbounds double, double* %2, i64 512
store double %36, double* %37
ret void
}