#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 */
typedef int /*<<< orphan*/ __m128d;
typedef int /*<<< orphan*/ __m128;

/* Variables and functions */
int /*<<< orphan*/ _mm_add_pd(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_add_sd(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_cvtps_pd(int /*<<< orphan*/);
int /*<<< orphan*/ _mm_loadu_ps(float const *);
int /*<<< orphan*/ _mm_movehl_ps(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_mul_ps(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_setzero_pd();
int /*<<< orphan*/ _mm_store_sd(double *, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_unpackhi_pd(int /*<<< orphan*/, int /*<<< orphan*/);
double inner_product_double(const float *a, const float *b, unsigned int len) {
  int i;
  double ret;
  __m128d sum = _mm_setzero_pd();
  __m128 t;
  for (i = 0; i < len; i += 8) {
    t = _mm_mul_ps(_mm_loadu_ps(a + i), _mm_loadu_ps(b + i));
    sum = _mm_add_pd(sum, _mm_cvtps_pd(t));
    sum = _mm_add_pd(sum, _mm_cvtps_pd(_mm_movehl_ps(t, t)));
    t = _mm_mul_ps(_mm_loadu_ps(a + i + 4), _mm_loadu_ps(b + i + 4));
    sum = _mm_add_pd(sum, _mm_cvtps_pd(t));
    sum = _mm_add_pd(sum, _mm_cvtps_pd(_mm_movehl_ps(t, t)));
  }
  sum = _mm_add_sd(sum, _mm_unpackhi_pd(sum, sum));
  _mm_store_sd(&ret, sum);
  return ret;
}


x86 assembly (clang, -O0):
<inner_product_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    $0x0,%al
call   10a0 <_mm_setzero_pd@plt>
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    12c6 <inner_product_double+0x136>
mov    -0x8(%rbp),%rdi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
call   1050 <_mm_loadu_ps@plt>
mov    %eax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
call   1050 <_mm_loadu_ps@plt>
mov    -0x40(%rbp),%edi
mov    %eax,%esi
call   1070 <_mm_mul_ps@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x28(%rbp),%edi
call   1080 <_mm_cvtps_pd@plt>
mov    -0x3c(%rbp),%edi
mov    %eax,%esi
call   1040 <_mm_add_pd@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x28(%rbp),%edi
mov    -0x28(%rbp),%esi
call   1090 <_mm_movehl_ps@plt>
mov    %eax,%edi
call   1080 <_mm_cvtps_pd@plt>
mov    -0x38(%rbp),%edi
mov    %eax,%esi
call   1040 <_mm_add_pd@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
add    $0x10,%rdi
call   1050 <_mm_loadu_ps@plt>
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
add    $0x10,%rdi
call   1050 <_mm_loadu_ps@plt>
mov    -0x34(%rbp),%edi
mov    %eax,%esi
call   1070 <_mm_mul_ps@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%edi
call   1080 <_mm_cvtps_pd@plt>
mov    -0x30(%rbp),%edi
mov    %eax,%esi
call   1040 <_mm_add_pd@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%edi
mov    -0x28(%rbp),%esi
call   1090 <_mm_movehl_ps@plt>
mov    %eax,%edi
call   1080 <_mm_cvtps_pd@plt>
mov    -0x2c(%rbp),%edi
mov    %eax,%esi
call   1040 <_mm_add_pd@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0x18(%rbp)
jmp    11b4 <inner_product_double+0x24>
mov    -0x24(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x24(%rbp),%esi
call   1060 <_mm_unpackhi_pd@plt>
mov    -0x44(%rbp),%edi
mov    %eax,%esi
call   1030 <_mm_add_sd@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
lea    -0x20(%rbp),%rdi
call   10b0 <_mm_store_sd@plt>
movsd  -0x20(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inner_product_double>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%r13
xor    %eax,%eax
call   10a0 <_mm_setzero_pd@plt>
mov    %eax,%r12d
test   %r15d,%r15d
je     127f <inner_product_double+0xef>
mov    %r15d,%eax
mov    %rax,0x8(%rsp)
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r13,%rdi
call   1050 <_mm_loadu_ps@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1050 <_mm_loadu_ps@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1070 <_mm_mul_ps@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1080 <_mm_cvtps_pd@plt>
mov    %r12d,%edi
mov    %eax,%esi
call   1040 <_mm_add_pd@plt>
mov    %eax,%ebx
mov    %ebp,%edi
mov    %ebp,%esi
call   1090 <_mm_movehl_ps@plt>
mov    %eax,%edi
call   1080 <_mm_cvtps_pd@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1040 <_mm_add_pd@plt>
mov    %eax,%ebx
lea    0x10(%r13),%rdi
call   1050 <_mm_loadu_ps@plt>
mov    %eax,%ebp
lea    0x10(%r14),%rdi
call   1050 <_mm_loadu_ps@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1070 <_mm_mul_ps@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1080 <_mm_cvtps_pd@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1040 <_mm_add_pd@plt>
mov    %eax,%ebx
mov    %ebp,%edi
mov    %ebp,%esi
call   1090 <_mm_movehl_ps@plt>
mov    %eax,%edi
call   1080 <_mm_cvtps_pd@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1040 <_mm_add_pd@plt>
mov    %eax,%r12d
add    $0x8,%r15
add    $0x20,%r14
add    $0x20,%r13
cmp    0x8(%rsp),%r15
jb     11d0 <inner_product_double+0x40>
mov    %r12d,%edi
mov    %r12d,%esi
call   1060 <_mm_unpackhi_pd@plt>
mov    %r12d,%edi
mov    %eax,%esi
call   1030 <_mm_add_sd@plt>
lea    0x10(%rsp),%rdi
mov    %eax,%esi
call   10b0 <_mm_store_sd@plt>
movsd  0x10(%rsp),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @inner_product_double(float* %0, float* %1, i32 %2) {
%4 = alloca float*
%5 = alloca float*
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
%9 = alloca i32
%10 = alloca i32
store float* %0, float** %4
store float* %1, float** %5
store i32 %2, i32* %6
%11 = call i32 (...) @_mm_setzero_pd()
store i32 %11, i32* %9
store i32 0, i32* %7
br label %12
12: ; preds = %61, %3
%13 = load i32, i32* %7
%14 = load i32, i32* %6
%15 = icmp ult i32 %13, %14
br i1 %15, label %16, label %64
16: ; preds = %12
%17 = load float*, float** %4
%18 = load i32, i32* %7
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds float, float* %17, i64 %19
%21 = call i32 @_mm_loadu_ps(float* %20)
%22 = load float*, float** %5
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds float, float* %22, i64 %24
%26 = call i32 @_mm_loadu_ps(float* %25)
%27 = call i32 @_mm_mul_ps(i32 %21, i32 %26)
store i32 %27, i32* %10
%28 = load i32, i32* %9
%29 = load i32, i32* %10
%30 = call i32 @_mm_cvtps_pd(i32 %29)
%31 = call i32 @_mm_add_pd(i32 %28, i32 %30)
store i32 %31, i32* %9
%32 = load i32, i32* %9
%33 = load i32, i32* %10
%34 = load i32, i32* %10
%35 = call i32 @_mm_movehl_ps(i32 %33, i32 %34)
%36 = call i32 @_mm_cvtps_pd(i32 %35)
%37 = call i32 @_mm_add_pd(i32 %32, i32 %36)
store i32 %37, i32* %9
%38 = load float*, float** %4
%39 = load i32, i32* %7
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds float, float* %38, i64 %40
%42 = getelementptr inbounds float, float* %41, i64 4
%43 = call i32 @_mm_loadu_ps(float* %42)
%44 = load float*, float** %5
%45 = load i32, i32* %7
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds float, float* %44, i64 %46
%48 = getelementptr inbounds float, float* %47, i64 4
%49 = call i32 @_mm_loadu_ps(float* %48)
%50 = call i32 @_mm_mul_ps(i32 %43, i32 %49)
store i32 %50, i32* %10
%51 = load i32, i32* %9
%52 = load i32, i32* %10
%53 = call i32 @_mm_cvtps_pd(i32 %52)
%54 = call i32 @_mm_add_pd(i32 %51, i32 %53)
store i32 %54, i32* %9
%55 = load i32, i32* %9
%56 = load i32, i32* %10
%57 = load i32, i32* %10
%58 = call i32 @_mm_movehl_ps(i32 %56, i32 %57)
%59 = call i32 @_mm_cvtps_pd(i32 %58)
%60 = call i32 @_mm_add_pd(i32 %55, i32 %59)
store i32 %60, i32* %9
br label %61
61: ; preds = %16
%62 = load i32, i32* %7
%63 = add nsw i32 %62, 8
store i32 %63, i32* %7
br label %12
64: ; preds = %12
%65 = load i32, i32* %9
%66 = load i32, i32* %9
%67 = load i32, i32* %9
%68 = call i32 @_mm_unpackhi_pd(i32 %66, i32 %67)
%69 = call i32 @_mm_add_sd(i32 %65, i32 %68)
store i32 %69, i32* %9
%70 = load i32, i32* %9
%71 = call i32 @_mm_store_sd(double* %8, i32 %70)
%72 = load double, double* %8
ret double %72
}

LLVM IR (-O2):
define double @inner_product_double(float* %0, float* %1, i32 %2) {
%4 = alloca double
%5 = bitcast double* %4 to i8*
%6 = tail call i32 (...) @_mm_setzero_pd()
%7 = icmp eq i32 %2, 0
br i1 %7, label %35, label %8
8: ; preds = %3
%9 = zext i32 %2 to i64
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ 0, %8 ], [ %33, %10 ]
%12 = phi i32 [ %6, %8 ], [ %32, %10 ]
%13 = getelementptr inbounds float, float* %0, i64 %11
%14 = tail call i32 @_mm_loadu_ps(float* %13)
%15 = getelementptr inbounds float, float* %1, i64 %11
%16 = tail call i32 @_mm_loadu_ps(float* %15)
%17 = tail call i32 @_mm_mul_ps(i32 %14, i32 %16)
%18 = tail call i32 @_mm_cvtps_pd(i32 %17)
%19 = tail call i32 @_mm_add_pd(i32 %12, i32 %18)
%20 = tail call i32 @_mm_movehl_ps(i32 %17, i32 %17)
%21 = tail call i32 @_mm_cvtps_pd(i32 %20)
%22 = tail call i32 @_mm_add_pd(i32 %19, i32 %21)
%23 = getelementptr inbounds float, float* %13, i64 4
%24 = tail call i32 @_mm_loadu_ps(float* %23)
%25 = getelementptr inbounds float, float* %15, i64 4
%26 = tail call i32 @_mm_loadu_ps(float* %25)
%27 = tail call i32 @_mm_mul_ps(i32 %24, i32 %26)
%28 = tail call i32 @_mm_cvtps_pd(i32 %27)
%29 = tail call i32 @_mm_add_pd(i32 %22, i32 %28)
%30 = tail call i32 @_mm_movehl_ps(i32 %27, i32 %27)
%31 = tail call i32 @_mm_cvtps_pd(i32 %30)
%32 = tail call i32 @_mm_add_pd(i32 %29, i32 %31)
%33 = add nuw nsw i64 %11, 8
%34 = icmp ult i64 %33, %9
br i1 %34, label %10, label %35
35: ; preds = %10, %3
%36 = phi i32 [ %6, %3 ], [ %32, %10 ]
%37 = tail call i32 @_mm_unpackhi_pd(i32 %36, i32 %36)
%38 = tail call i32 @_mm_add_sd(i32 %36, i32 %37)
%39 = call i32 @_mm_store_sd(double* %4, i32 %38)
%40 = load double, double* %4
ret double %40
}