#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 */
int /*<<< orphan*/ add_arrays_inplace(double *, double *, int, int);
int /*<<< orphan*/ multiply_array_array(double *, double *, double *, int, int);
double calculate_dot(double *xi, double *yi, double *zi, double *xj, double *yj,
                     double *zj, int nlns) {
  int i;
  double tmp[nlns];
  double fnl[nlns];
  double out = 0.;
  multiply_array_array(fnl, xi, xj, 1, nlns);
  multiply_array_array(tmp, yi, yj, 1, nlns);
  add_arrays_inplace(fnl, tmp, 1, nlns);
  multiply_array_array(tmp, zi, zj, 1, nlns);
  add_arrays_inplace(fnl, tmp, 1, nlns);
  for (i = 0; i < nlns; i++)
    out += fnl[i];
  return out;
}


x86 assembly (clang, -O0):
<calculate_dot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    0x10(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x40(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x60(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x48(%rbp)
mov    0x10(%rbp),%eax
lea    0xf(,%rax,8),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x68(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x50(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    0x10(%rbp),%r8d
mov    $0x1,%ecx
call   1040 <multiply_array_array@plt>
mov    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    0x10(%rbp),%r8d
mov    $0x1,%ecx
call   1040 <multiply_array_array@plt>
mov    -0x68(%rbp),%rdi
mov    -0x60(%rbp),%rsi
mov    0x10(%rbp),%ecx
mov    $0x1,%edx
call   1030 <add_arrays_inplace@plt>
mov    -0x60(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    0x10(%rbp),%r8d
mov    $0x1,%ecx
call   1040 <multiply_array_array@plt>
mov    -0x68(%rbp),%rdi
mov    -0x60(%rbp),%rsi
mov    0x10(%rbp),%ecx
mov    $0x1,%edx
call   1030 <add_arrays_inplace@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    0x10(%rbp),%eax
jge    123e <calculate_dot+0x11e>
mov    -0x68(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    120d <calculate_dot+0xed>
movsd  -0x58(%rbp),%xmm0
mov    -0x40(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calculate_dot>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,-0x38(%rbp)
mov    %r8,%r15
mov    %rdx,-0x30(%rbp)
mov    %rsi,%r12
mov    %rdi,%rsi
mov    0x10(%rbp),%r14d
mov    %rsp,%r13
lea    0xf(,%r14,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %rcx,%rdx
mov    $0x1,%ecx
mov    %r14d,%r8d
call   1040 <multiply_array_array@plt>
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    $0x1,%ecx
mov    %r14d,%r8d
call   1040 <multiply_array_array@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    $0x1,%edx
mov    %r14d,%ecx
call   1030 <add_arrays_inplace@plt>
mov    %r13,%rdi
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    $0x1,%ecx
mov    %r14d,%r8d
call   1040 <multiply_array_array@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    $0x1,%edx
mov    %r14d,%ecx
call   1030 <add_arrays_inplace@plt>
test   %r14d,%r14d
jle    11e8 <calculate_dot+0xc8>
lea    -0x1(%r14),%rcx
mov    %r14d,%eax
and    $0x7,%eax
cmp    $0x7,%rcx
jae    11ee <calculate_dot+0xce>
xorpd  %xmm0,%xmm0
xor    %ecx,%ecx
jmp    1238 <calculate_dot+0x118>
xorpd  %xmm0,%xmm0
jmp    125e <calculate_dot+0x13e>
and    $0xfffffff8,%r14d
xorpd  %xmm0,%xmm0
xor    %ecx,%ecx
nopl   0x0(%rax,%rax,1)
addsd  (%rbx,%rcx,8),%xmm0
addsd  0x8(%rbx,%rcx,8),%xmm0
addsd  0x10(%rbx,%rcx,8),%xmm0
addsd  0x18(%rbx,%rcx,8),%xmm0
addsd  0x20(%rbx,%rcx,8),%xmm0
addsd  0x28(%rbx,%rcx,8),%xmm0
addsd  0x30(%rbx,%rcx,8),%xmm0
addsd  0x38(%rbx,%rcx,8),%xmm0
add    $0x8,%rcx
cmp    %rcx,%r14
jne    1200 <calculate_dot+0xe0>
test   %rax,%rax
je     125e <calculate_dot+0x13e>
lea    (%rbx,%rcx,8),%rcx
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
addsd  (%rcx,%rdx,8),%xmm0
add    $0x1,%rdx
cmp    %rdx,%rax
jne    1250 <calculate_dot+0x130>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @calculate_dot(double* %0, double* %1, double* %2, double* %3, double* %4, double* %5, i32 %6) {
%8 = alloca double*
%9 = alloca double*
%10 = alloca double*
%11 = alloca double*
%12 = alloca double*
%13 = alloca double*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i8*
%17 = alloca i64
%18 = alloca i64
%19 = alloca double
store double* %0, double** %8
store double* %1, double** %9
store double* %2, double** %10
store double* %3, double** %11
store double* %4, double** %12
store double* %5, double** %13
store i32 %6, i32* %14
%20 = load i32, i32* %14
%21 = zext i32 %20 to i64
%22 = call i8* @llvm.stacksave()
store i8* %22, i8** %16
%23 = alloca double, i64 %21
store i64 %21, i64* %17
%24 = load i32, i32* %14
%25 = zext i32 %24 to i64
%26 = alloca double, i64 %25
store i64 %25, i64* %18
store double 0.000000e+00, double* %19
%27 = load double*, double** %8
%28 = load double*, double** %11
%29 = load i32, i32* %14
%30 = call i32 @multiply_array_array(double* %26, double* %27, double* %28, i32 1, i32 %29)
%31 = load double*, double** %9
%32 = load double*, double** %12
%33 = load i32, i32* %14
%34 = call i32 @multiply_array_array(double* %23, double* %31, double* %32, i32 1, i32 %33)
%35 = load i32, i32* %14
%36 = call i32 @add_arrays_inplace(double* %26, double* %23, i32 1, i32 %35)
%37 = load double*, double** %10
%38 = load double*, double** %13
%39 = load i32, i32* %14
%40 = call i32 @multiply_array_array(double* %23, double* %37, double* %38, i32 1, i32 %39)
%41 = load i32, i32* %14
%42 = call i32 @add_arrays_inplace(double* %26, double* %23, i32 1, i32 %41)
store i32 0, i32* %15
br label %43
43: ; preds = %54, %7
%44 = load i32, i32* %15
%45 = load i32, i32* %14
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %57
47: ; preds = %43
%48 = load i32, i32* %15
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds double, double* %26, i64 %49
%51 = load double, double* %50
%52 = load double, double* %19
%53 = fadd double %52, %51
store double %53, double* %19
br label %54
54: ; preds = %47
%55 = load i32, i32* %15
%56 = add nsw i32 %55, 1
store i32 %56, i32* %15
br label %43
57: ; preds = %43
%58 = load double, double* %19
%59 = load i8*, i8** %16
ret double %58
}

LLVM IR (-O2):
define double @calculate_dot(double* %0, double* %1, double* %2, double* %3, double* %4, double* %5, i32 %6) {
%8 = zext i32 %6 to i64
%9 = alloca double, i64 %8
%10 = alloca double, i64 %8
%11 = call i32 @multiply_array_array(double* %10, double* %0, double* %3, i32 1, i32 %6)
%12 = call i32 @multiply_array_array(double* %9, double* %1, double* %4, i32 1, i32 %6)
%13 = call i32 @add_arrays_inplace(double* %10, double* %9, i32 1, i32 %6)
%14 = call i32 @multiply_array_array(double* %9, double* %2, double* %5, i32 1, i32 %6)
%15 = call i32 @add_arrays_inplace(double* %10, double* %9, i32 1, i32 %6)
%16 = icmp sgt i32 %6, 0
br i1 %16, label %17, label %76
17: ; preds = %7
%18 = add nsw i64 %8, -1
%19 = and i64 %8, 7
%20 = icmp ult i64 %18, 7
br i1 %20, label %61, label %21
21: ; preds = %17
%22 = and i64 %8, 4294967288
br label %23
23: ; preds = %23, %21
%24 = phi i64 [ 0, %21 ], [ %58, %23 ]
%25 = phi double [ 0.000000e+00, %21 ], [ %57, %23 ]
%26 = phi i64 [ 0, %21 ], [ %59, %23 ]
%27 = getelementptr inbounds double, double* %10, i64 %24
%28 = load double, double* %27
%29 = fadd double %25, %28
%30 = or i64 %24, 1
%31 = getelementptr inbounds double, double* %10, i64 %30
%32 = load double, double* %31
%33 = fadd double %29, %32
%34 = or i64 %24, 2
%35 = getelementptr inbounds double, double* %10, i64 %34
%36 = load double, double* %35
%37 = fadd double %33, %36
%38 = or i64 %24, 3
%39 = getelementptr inbounds double, double* %10, i64 %38
%40 = load double, double* %39
%41 = fadd double %37, %40
%42 = or i64 %24, 4
%43 = getelementptr inbounds double, double* %10, i64 %42
%44 = load double, double* %43
%45 = fadd double %41, %44
%46 = or i64 %24, 5
%47 = getelementptr inbounds double, double* %10, i64 %46
%48 = load double, double* %47
%49 = fadd double %45, %48
%50 = or i64 %24, 6
%51 = getelementptr inbounds double, double* %10, i64 %50
%52 = load double, double* %51
%53 = fadd double %49, %52
%54 = or i64 %24, 7
%55 = getelementptr inbounds double, double* %10, i64 %54
%56 = load double, double* %55
%57 = fadd double %53, %56
%58 = add nuw nsw i64 %24, 8
%59 = add i64 %26, 8
%60 = icmp eq i64 %59, %22
br i1 %60, label %61, label %23
61: ; preds = %23, %17
%62 = phi double [ undef, %17 ], [ %57, %23 ]
%63 = phi i64 [ 0, %17 ], [ %58, %23 ]
%64 = phi double [ 0.000000e+00, %17 ], [ %57, %23 ]
%65 = icmp eq i64 %19, 0
br i1 %65, label %76, label %66
66: ; preds = %61, %66
%67 = phi i64 [ %73, %66 ], [ %63, %61 ]
%68 = phi double [ %72, %66 ], [ %64, %61 ]
%69 = phi i64 [ %74, %66 ], [ 0, %61 ]
%70 = getelementptr inbounds double, double* %10, i64 %67
%71 = load double, double* %70
%72 = fadd double %68, %71
%73 = add nuw nsw i64 %67, 1
%74 = add i64 %69, 1
%75 = icmp eq i64 %74, %19
br i1 %75, label %76, label %66
76: ; preds = %61, %66, %7
%77 = phi double [ 0.000000e+00, %7 ], [ %62, %61 ], [ %72, %66 ]
ret double %77
}