#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 fabs(double);
double direct_prod(double a_real[], double a_imag[], double b_real[],
                   double b_imag[], int size) {
  int k;
  double dot_absq, dot_real = 0.0, dot_imag = 0.0;
  double ar, ai, br, bi;
  for (k = 0; k < size; k++) {
    ar = a_real[k];
    ai = a_imag[k];
    br = b_real[k];
    bi = b_imag[k];
    dot_real = dot_real + ar * br + ai * bi;
    dot_imag = dot_imag + ar * bi - ai * br;
  }
  dot_absq = dot_real * dot_real + dot_imag * dot_imag;
  dot_absq = fabs(dot_absq);
  return (dot_absq);
}


x86 assembly (clang, -O0):
<direct_prod>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1204 <direct_prod+0x104>
mov    -0x8(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm1
movsd  -0x58(%rbp),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm1
movsd  -0x60(%rbp),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    112f <direct_prod+0x2f>
movsd  -0x38(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm2
movsd  -0x40(%rbp),%xmm1
mulsd  -0x40(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movaps 0xdcf(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<direct_prod>:
test   %r8d,%r8d
jle    1173 <direct_prod+0x73>
mov    %r8d,%r8d
xorpd  %xmm2,%xmm2
xor    %eax,%eax
movapd 0xeea(%rip),%xmm1
cs nopw 0x0(%rax,%rax,1)
movsd  (%rdi,%rax,8),%xmm4
unpcklpd %xmm4,%xmm4
movsd  (%rdx,%rax,8),%xmm0
movsd  (%rcx,%rax,8),%xmm5
movapd %xmm5,%xmm3
unpcklpd %xmm0,%xmm3
mulpd  %xmm4,%xmm3
addpd  %xmm2,%xmm3
movsd  (%rsi,%rax,8),%xmm2
movapd %xmm2,%xmm4
xorpd  %xmm1,%xmm4
unpcklpd %xmm2,%xmm4
unpcklpd %xmm5,%xmm0
mulpd  %xmm4,%xmm0
movapd %xmm0,%xmm2
addpd  %xmm3,%xmm2
add    $0x1,%rax
cmp    %rax,%r8
jne    1120 <direct_prod+0x20>
addpd  %xmm3,%xmm0
jmp    1177 <direct_prod+0x77>
xorpd  %xmm0,%xmm0
movapd %xmm0,%xmm1
mulsd  %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
andpd  0xe7d(%rip),%xmm0
ret

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

LLVM IR (-O2):
define double @direct_prod(double* nocapture %0, double* nocapture %1, double* nocapture %2, double* nocapture %3, i32 %4) {
%6 = icmp sgt i32 %4, 0
br i1 %6, label %7, label %36
7: ; preds = %5
%8 = zext i32 %4 to i64
br label %9
9: ; preds = %7, %9
%10 = phi i64 [ 0, %7 ], [ %31, %9 ]
%11 = phi <2 x double> [ zeroinitializer, %7 ], [ %30, %9 ]
%12 = getelementptr inbounds double, double* %0, i64 %10
%13 = load double, double* %12
%14 = getelementptr inbounds double, double* %1, i64 %10
%15 = load double, double* %14
%16 = getelementptr inbounds double, double* %2, i64 %10
%17 = load double, double* %16
%18 = getelementptr inbounds double, double* %3, i64 %10
%19 = load double, double* %18
%20 = insertelement <2 x double> poison, double %13, i64 0
%21 = shufflevector <2 x double> %20, <2 x double> poison, <2 x i32> zeroinitializer
%22 = insertelement <2 x double> poison, double %19, i64 0
%23 = insertelement <2 x double> %22, double %17, i64 1
%24 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %21, <2 x double> %23, <2 x double> %11)
%25 = fneg double %15
%26 = insertelement <2 x double> poison, double %25, i64 0
%27 = insertelement <2 x double> %26, double %15, i64 1
%28 = insertelement <2 x double> poison, double %17, i64 0
%29 = insertelement <2 x double> %28, double %19, i64 1
%30 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %27, <2 x double> %29, <2 x double> %24)
%31 = add nuw nsw i64 %10, 1
%32 = icmp eq i64 %31, %8
br i1 %32, label %33, label %9
33: ; preds = %9
%34 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %21, <2 x double> %23, <2 x double> %11)
%35 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %27, <2 x double> %29, <2 x double> %34)
br label %36
36: ; preds = %33, %5
%37 = phi <2 x double> [ zeroinitializer, %5 ], [ %35, %33 ]
%38 = fmul <2 x double> %37, %37
%39 = extractelement <2 x double> %38, i64 0
%40 = extractelement <2 x double> %37, i64 1
%41 = tail call double @llvm.fmuladd.f64(double %40, double %40, double %39)
%42 = tail call double @llvm.fabs.f64(double %41)
ret double %42
}