#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*/ __m128;

/* Variables and functions */
int /*<<< orphan*/ _mm_add_ps(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_add_ss(int /*<<< orphan*/, 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_ps();
int /*<<< orphan*/ _mm_shuffle_ps(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ _mm_store_ss(float *, int /*<<< orphan*/);
float inner_product_single(const float *a, const float *b, unsigned int len) {
  int i;
  float ret;
  __m128 sum = _mm_setzero_ps();
  for (i = 0; i < len; i += 8) {
    sum = _mm_add_ps(sum, _mm_mul_ps(_mm_loadu_ps(a + i), _mm_loadu_ps(b + i)));
    sum = _mm_add_ps(
        sum, _mm_mul_ps(_mm_loadu_ps(a + i + 4), _mm_loadu_ps(b + i + 4)));
  }
  sum = _mm_add_ps(sum, _mm_movehl_ps(sum, sum));
  sum = _mm_add_ss(sum, _mm_shuffle_ps(sum, sum, 0x55));
  _mm_store_ss(&ret, sum);
  return ret;
}


x86 assembly (clang, -O0):
<inner_product_single>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    $0x0,%al
call   10a0 <_mm_setzero_ps@plt>
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    1256 <inner_product_single+0xd6>
mov    -0x20(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
call   1040 <_mm_loadu_ps@plt>
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
call   1040 <_mm_loadu_ps@plt>
mov    -0x30(%rbp),%edi
mov    %eax,%esi
call   1070 <_mm_mul_ps@plt>
mov    -0x2c(%rbp),%edi
mov    %eax,%esi
call   1080 <_mm_add_ps@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
add    $0x10,%rdi
call   1040 <_mm_loadu_ps@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
add    $0x10,%rdi
call   1040 <_mm_loadu_ps@plt>
mov    -0x28(%rbp),%edi
mov    %eax,%esi
call   1070 <_mm_mul_ps@plt>
mov    -0x24(%rbp),%edi
mov    %eax,%esi
call   1080 <_mm_add_ps@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0x18(%rbp)
jmp    11a4 <inner_product_single+0x24>
mov    -0x20(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1090 <_mm_movehl_ps@plt>
mov    -0x38(%rbp),%edi
mov    %eax,%esi
call   1080 <_mm_add_ps@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    $0x55,%edx
call   1030 <_mm_shuffle_ps@plt>
mov    -0x34(%rbp),%edi
mov    %eax,%esi
call   1060 <_mm_add_ss@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    -0x1c(%rbp),%rdi
call   1050 <_mm_store_ss@plt>
movss  -0x1c(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inner_product_single>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %eax,%eax
call   10a0 <_mm_setzero_ps@plt>
mov    %eax,%r12d
test   %r15d,%r15d
je     1225 <inner_product_single+0xa5>
mov    %r15d,%eax
mov    %rax,0x10(%rsp)
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <_mm_loadu_ps@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1040 <_mm_loadu_ps@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1070 <_mm_mul_ps@plt>
mov    %r12d,%edi
mov    %eax,%esi
call   1080 <_mm_add_ps@plt>
mov    %eax,%r15d
lea    0x10(%rbx),%rdi
call   1040 <_mm_loadu_ps@plt>
mov    %eax,%ebp
lea    0x10(%r14),%rdi
call   1040 <_mm_loadu_ps@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1070 <_mm_mul_ps@plt>
mov    %r15d,%edi
mov    %eax,%esi
call   1080 <_mm_add_ps@plt>
mov    %eax,%r12d
add    $0x8,%r13
add    $0x20,%r14
add    $0x20,%rbx
cmp    0x10(%rsp),%r13
jb     11c0 <inner_product_single+0x40>
mov    %r12d,%edi
mov    %r12d,%esi
call   1090 <_mm_movehl_ps@plt>
mov    %r12d,%edi
mov    %eax,%esi
call   1080 <_mm_add_ps@plt>
mov    %eax,%ebx
mov    %eax,%edi
mov    %eax,%esi
mov    $0x55,%edx
call   1030 <_mm_shuffle_ps@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1060 <_mm_add_ss@plt>
lea    0xc(%rsp),%rdi
mov    %eax,%esi
call   1050 <_mm_store_ss@plt>
movss  0xc(%rsp),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define float @inner_product_single(float* %0, float* %1, i32 %2) {
%4 = alloca float*
%5 = alloca float*
%6 = alloca i32
%7 = alloca i32
%8 = alloca float
%9 = alloca i32
store float* %0, float** %4
store float* %1, float** %5
store i32 %2, i32* %6
%10 = call i32 (...) @_mm_setzero_ps()
store i32 %10, i32* %9
store i32 0, i32* %7
br label %11
11: ; preds = %44, %3
%12 = load i32, i32* %7
%13 = load i32, i32* %6
%14 = icmp ult i32 %12, %13
br i1 %14, label %15, label %47
15: ; preds = %11
%16 = load i32, i32* %9
%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)
%28 = call i32 @_mm_add_ps(i32 %16, i32 %27)
store i32 %28, i32* %9
%29 = load i32, i32* %9
%30 = load float*, float** %4
%31 = load i32, i32* %7
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds float, float* %30, i64 %32
%34 = getelementptr inbounds float, float* %33, i64 4
%35 = call i32 @_mm_loadu_ps(float* %34)
%36 = load float*, float** %5
%37 = load i32, i32* %7
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds float, float* %36, i64 %38
%40 = getelementptr inbounds float, float* %39, i64 4
%41 = call i32 @_mm_loadu_ps(float* %40)
%42 = call i32 @_mm_mul_ps(i32 %35, i32 %41)
%43 = call i32 @_mm_add_ps(i32 %29, i32 %42)
store i32 %43, i32* %9
br label %44
44: ; preds = %15
%45 = load i32, i32* %7
%46 = add nsw i32 %45, 8
store i32 %46, i32* %7
br label %11
47: ; preds = %11
%48 = load i32, i32* %9
%49 = load i32, i32* %9
%50 = load i32, i32* %9
%51 = call i32 @_mm_movehl_ps(i32 %49, i32 %50)
%52 = call i32 @_mm_add_ps(i32 %48, i32 %51)
store i32 %52, i32* %9
%53 = load i32, i32* %9
%54 = load i32, i32* %9
%55 = load i32, i32* %9
%56 = call i32 @_mm_shuffle_ps(i32 %54, i32 %55, i32 85)
%57 = call i32 @_mm_add_ss(i32 %53, i32 %56)
store i32 %57, i32* %9
%58 = load i32, i32* %9
%59 = call i32 @_mm_store_ss(float* %8, i32 %58)
%60 = load float, float* %8
ret float %60
}

LLVM IR (-O2):
define float @inner_product_single(float* %0, float* %1, i32 %2) {
%4 = alloca float
%5 = bitcast float* %4 to i8*
%6 = tail call i32 (...) @_mm_setzero_ps()
%7 = icmp eq i32 %2, 0
br i1 %7, label %27, label %8
8: ; preds = %3
%9 = zext i32 %2 to i64
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ 0, %8 ], [ %25, %10 ]
%12 = phi i32 [ %6, %8 ], [ %24, %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_add_ps(i32 %12, i32 %17)
%19 = getelementptr inbounds float, float* %13, i64 4
%20 = tail call i32 @_mm_loadu_ps(float* %19)
%21 = getelementptr inbounds float, float* %15, i64 4
%22 = tail call i32 @_mm_loadu_ps(float* %21)
%23 = tail call i32 @_mm_mul_ps(i32 %20, i32 %22)
%24 = tail call i32 @_mm_add_ps(i32 %18, i32 %23)
%25 = add nuw nsw i64 %11, 8
%26 = icmp ult i64 %25, %9
br i1 %26, label %10, label %27
27: ; preds = %10, %3
%28 = phi i32 [ %6, %3 ], [ %24, %10 ]
%29 = tail call i32 @_mm_movehl_ps(i32 %28, i32 %28)
%30 = tail call i32 @_mm_add_ps(i32 %28, i32 %29)
%31 = tail call i32 @_mm_shuffle_ps(i32 %30, i32 %30, i32 85)
%32 = tail call i32 @_mm_add_ss(i32 %30, i32 %31)
%33 = call i32 @_mm_store_ss(float* %4, i32 %32)
%34 = load float, float* %4
ret float %34
}