#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 cos(double);
int getPI();
double sin(double);
void dftreal_loopy(const int dftsize, const double *xreal_in, double *X_out) {
  int k, n;
  double TWO_PI = 2 * getPI();
  double *one_out = X_out;
  for (k = 0; k < dftsize; k++) {
    double ratio = -(TWO_PI * k) / dftsize;
    double real = 0;
    double imag = 0;
    for (n = 0; n < dftsize; n++) {
      double x_n = xreal_in[n];
      double angle = ratio * n;
      real += x_n * cos(angle);
      imag += x_n * sin(angle);
    }
    (*one_out) = real;
    one_out++;
    (*one_out) = imag;
    one_out++;
  }
}


x86 assembly (clang, -O0):
<dftreal_loopy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x0,%al
call   1030 <getPI@plt>
shl    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1296 <dftreal_loopy+0x166>
movsd  -0x28(%rbp),%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
cvtsi2sdl -0x4(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1256 <dftreal_loopy+0x126>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x38(%rbp),%xmm0
cvtsi2sdl -0x20(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x58(%rbp),%xmm0
call   1050 <cos@plt>
movaps %xmm0,%xmm2
movsd  -0x68(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x58(%rbp),%xmm0
call   1040 <sin@plt>
movaps %xmm0,%xmm2
movsd  -0x60(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11bb <dftreal_loopy+0x8b>
movsd  -0x40(%rbp),%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x30(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x30(%rbp)
movsd  -0x48(%rbp),%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x30(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x30(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1165 <dftreal_loopy+0x35>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dftreal_loopy>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%r15d
xor    %r13d,%r13d
xor    %eax,%eax
call   1030 <getPI@plt>
test   %r15d,%r15d
jle    1348 <dftreal_loopy+0x218>
add    %eax,%eax
cvtsi2sd %eax,%xmm0
xorpd  0xe95(%rip),%xmm0
movapd %xmm0,0x70(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %r15d,%xmm0
movsd  %xmm0,0x68(%rsp)
mov    %r15d,%ebp
mov    %rbp,0x60(%rsp)
and    $0xfffffffe,%ebp
xorpd  %xmm1,%xmm1
jmp    11b6 <dftreal_loopy+0x86>
mulpd  %xmm5,%xmm4
addpd  %xmm3,%xmm4
movupd %xmm4,(%r14)
add    $0x10,%r14
addsd  0xe67(%rip),%xmm1
add    $0x1,%r13d
cmp    %r15d,%r13d
je     1348 <dftreal_loopy+0x218>
movapd 0x70(%rsp),%xmm2
mulsd  %xmm1,%xmm2
divsd  0x68(%rsp),%xmm2
cmp    $0x1,%r15d
movsd  %xmm1,0x48(%rsp)
xorpd  %xmm0,%xmm0
jne    11f0 <dftreal_loopy+0xc0>
xor    %r12d,%r12d
testb  $0x1,0x60(%rsp)
je     1190 <dftreal_loopy+0x60>
jmp    12e6 <dftreal_loopy+0x1b6>
cs nopw 0x0(%rax,%rax,1)
nop
xor    %r12d,%r12d
movsd  %xmm2,0x8(%rsp)
nopl   0x0(%rax)
movapd %xmm0,0x30(%rsp)
xorps  %xmm1,%xmm1
cvtsi2sd %r12d,%xmm1
mulsd  %xmm2,%xmm1
movsd  %xmm1,0x10(%rsp)
movsd  (%rbx,%r12,8),%xmm0
movaps %xmm0,0x20(%rsp)
movapd %xmm1,%xmm0
call   1050 <cos@plt>
movapd %xmm0,0x50(%rsp)
movsd  0x10(%rsp),%xmm0
call   1040 <sin@plt>
movapd 0x20(%rsp),%xmm2
unpcklpd %xmm2,%xmm2
movapd 0x50(%rsp),%xmm1
unpcklpd %xmm0,%xmm1
mulpd  %xmm2,%xmm1
addpd  0x30(%rsp),%xmm1
movapd %xmm1,0x50(%rsp)
lea    0x1(%r12),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x30(%rsp)
movsd  0x8(%rbx,%r12,8),%xmm1
movapd %xmm1,0x20(%rsp)
call   1050 <cos@plt>
movapd %xmm0,0x10(%rsp)
movsd  0x30(%rsp),%xmm0
call   1040 <sin@plt>
movapd 0x10(%rsp),%xmm5
movapd 0x20(%rsp),%xmm4
movapd 0x50(%rsp),%xmm3
movsd  0x8(%rsp),%xmm2
unpcklpd %xmm4,%xmm4
unpcklpd %xmm0,%xmm5
movapd %xmm4,%xmm0
mulpd  %xmm5,%xmm0
addpd  %xmm3,%xmm0
add    $0x2,%r12
cmp    %rbp,%r12
jne    1200 <dftreal_loopy+0xd0>
movsd  0x48(%rsp),%xmm1
testb  $0x1,0x60(%rsp)
je     1190 <dftreal_loopy+0x60>
movapd %xmm0,0x30(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %r12d,%xmm0
mulsd  %xmm0,%xmm2
movsd  %xmm2,0x8(%rsp)
movsd  (%rbx,%r12,8),%xmm0
movaps %xmm0,0x20(%rsp)
movapd %xmm2,%xmm0
call   1050 <cos@plt>
movapd %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
call   1040 <sin@plt>
movapd 0x10(%rsp),%xmm5
movapd 0x20(%rsp),%xmm4
movsd  0x48(%rsp),%xmm1
unpcklpd %xmm4,%xmm4
unpcklpd %xmm0,%xmm5
movapd 0x30(%rsp),%xmm3
jmp    1190 <dftreal_loopy+0x60>
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @dftreal_loopy(i32 %0, double* %1, double* %2) {
%4 = alloca i32
%5 = alloca double*
%6 = alloca double*
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca double*
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
store i32 %0, i32* %4
store double* %1, double** %5
store double* %2, double** %6
%16 = call i32 (...) @getPI()
%17 = mul nsw i32 2, %16
%18 = sitofp i32 %17 to double
store double %18, double* %9
%19 = load double*, double** %6
store double* %19, double** %10
store i32 0, i32* %7
br label %20
20: ; preds = %69, %3
%21 = load i32, i32* %7
%22 = load i32, i32* %4
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %72
24: ; preds = %20
%25 = load double, double* %9
%26 = load i32, i32* %7
%27 = sitofp i32 %26 to double
%28 = fmul double %25, %27
%29 = fneg double %28
%30 = load i32, i32* %4
%31 = sitofp i32 %30 to double
%32 = fdiv double %29, %31
store double %32, double* %11
store double 0.000000e+00, double* %12
store double 0.000000e+00, double* %13
store i32 0, i32* %8
br label %33
33: ; preds = %57, %24
%34 = load i32, i32* %8
%35 = load i32, i32* %4
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %60
37: ; preds = %33
%38 = load double*, double** %5
%39 = load i32, i32* %8
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds double, double* %38, i64 %40
%42 = load double, double* %41
store double %42, double* %14
%43 = load double, double* %11
%44 = load i32, i32* %8
%45 = sitofp i32 %44 to double
%46 = fmul double %43, %45
store double %46, double* %15
%47 = load double, double* %14
%48 = load double, double* %15
%49 = call double @cos(double %48)
%50 = load double, double* %12
%51 = call double @llvm.fmuladd.f64(double %47, double %49, double %50)
store double %51, double* %12
%52 = load double, double* %14
%53 = load double, double* %15
%54 = call double @sin(double %53)
%55 = load double, double* %13
%56 = call double @llvm.fmuladd.f64(double %52, double %54, double %55)
store double %56, double* %13
br label %57
57: ; preds = %37
%58 = load i32, i32* %8
%59 = add nsw i32 %58, 1
store i32 %59, i32* %8
br label %33
60: ; preds = %33
%61 = load double, double* %12
%62 = load double*, double** %10
store double %61, double* %62
%63 = load double*, double** %10
%64 = getelementptr inbounds double, double* %63, i32 1
store double* %64, double** %10
%65 = load double, double* %13
%66 = load double*, double** %10
store double %65, double* %66
%67 = load double*, double** %10
%68 = getelementptr inbounds double, double* %67, i32 1
store double* %68, double** %10
br label %69
69: ; preds = %60
%70 = load i32, i32* %7
%71 = add nsw i32 %70, 1
store i32 %71, i32* %7
br label %20
72: ; preds = %20
ret void
}

LLVM IR (-O2):
define void @dftreal_loopy(i32 %0, double* nocapture %1, double* nocapture writeonly %2) {
%4 = tail call i32 (...) @getPI()
%5 = icmp sgt i32 %0, 0
br i1 %5, label %6, label %81
6: ; preds = %3
%7 = shl nsw i32 %4, 1
%8 = sitofp i32 %7 to double
%9 = fneg double %8
%10 = sitofp i32 %0 to double
%11 = zext i32 %0 to i64
%12 = and i64 %11, 1
%13 = icmp eq i32 %0, 1
%14 = and i64 %11, 4294967294
%15 = icmp eq i64 %12, 0
br label %16
16: ; preds = %72, %6
%17 = phi i32 [ 0, %6 ], [ %79, %72 ]
%18 = phi double* [ %2, %6 ], [ %78, %72 ]
%19 = sitofp i32 %17 to double
%20 = fmul double %9, %19
%21 = fdiv double %20, %10
br i1 %13, label %54, label %22
22: ; preds = %16, %22
%23 = phi i64 [ %51, %22 ], [ 0, %16 ]
%24 = phi <2 x double> [ %50, %22 ], [ zeroinitializer, %16 ]
%25 = phi i64 [ %52, %22 ], [ 0, %16 ]
%26 = getelementptr inbounds double, double* %1, i64 %23
%27 = load double, double* %26
%28 = trunc i64 %23 to i32
%29 = sitofp i32 %28 to double
%30 = fmul double %21, %29
%31 = tail call double @cos(double %30)
%32 = tail call double @sin(double %30)
%33 = insertelement <2 x double> poison, double %27, i64 0
%34 = shufflevector <2 x double> %33, <2 x double> poison, <2 x i32> zeroinitializer
%35 = insertelement <2 x double> poison, double %31, i64 0
%36 = insertelement <2 x double> %35, double %32, i64 1
%37 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %34, <2 x double> %36, <2 x double> %24)
%38 = or i64 %23, 1
%39 = getelementptr inbounds double, double* %1, i64 %38
%40 = load double, double* %39
%41 = trunc i64 %38 to i32
%42 = sitofp i32 %41 to double
%43 = fmul double %21, %42
%44 = tail call double @cos(double %43)
%45 = tail call double @sin(double %43)
%46 = insertelement <2 x double> poison, double %40, i64 0
%47 = shufflevector <2 x double> %46, <2 x double> poison, <2 x i32> zeroinitializer
%48 = insertelement <2 x double> poison, double %44, i64 0
%49 = insertelement <2 x double> %48, double %45, i64 1
%50 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %47, <2 x double> %49, <2 x double> %37)
%51 = add nuw nsw i64 %23, 2
%52 = add i64 %25, 2
%53 = icmp eq i64 %52, %14
br i1 %53, label %54, label %22
54: ; preds = %22, %16
%55 = phi <2 x double> [ undef, %16 ], [ %37, %22 ]
%56 = phi <2 x double> [ undef, %16 ], [ %47, %22 ]
%57 = phi <2 x double> [ undef, %16 ], [ %49, %22 ]
%58 = phi i64 [ 0, %16 ], [ %51, %22 ]
%59 = phi <2 x double> [ zeroinitializer, %16 ], [ %50, %22 ]
br i1 %15, label %72, label %60
60: ; preds = %54
%61 = getelementptr inbounds double, double* %1, i64 %58
%62 = load double, double* %61
%63 = trunc i64 %58 to i32
%64 = sitofp i32 %63 to double
%65 = fmul double %21, %64
%66 = tail call double @cos(double %65)
%67 = tail call double @sin(double %65)
%68 = insertelement <2 x double> poison, double %62, i64 0
%69 = shufflevector <2 x double> %68, <2 x double> poison, <2 x i32> zeroinitializer
%70 = insertelement <2 x double> poison, double %66, i64 0
%71 = insertelement <2 x double> %70, double %67, i64 1
br label %72
72: ; preds = %54, %60
%73 = phi <2 x double> [ %55, %54 ], [ %59, %60 ]
%74 = phi <2 x double> [ %56, %54 ], [ %69, %60 ]
%75 = phi <2 x double> [ %57, %54 ], [ %71, %60 ]
%76 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %74, <2 x double> %75, <2 x double> %73)
%77 = bitcast double* %18 to <2 x double>*
store <2 x double> %76, <2 x double>* %77
%78 = getelementptr inbounds double, double* %18, i64 2
%79 = add nuw nsw i32 %17, 1
%80 = icmp eq i32 %79, %0
br i1 %80, label %81, label %16
81: ; preds = %72, %3
ret void
}