#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_prod(const float *a, const float *b, int len) {
  int i;
  float ret;
  __m128 sum = _mm_setzero_ps();
  for (i = 0; i < (len >> 2); i += 2) {
    sum = _mm_add_ps(sum, _mm_mul_ps(_mm_loadu_ps(a + 0), _mm_loadu_ps(b + 0)));
    sum = _mm_add_ps(sum, _mm_mul_ps(_mm_loadu_ps(a + 4), _mm_loadu_ps(b + 4)));
    a += 8;
    b += 8;
  }
  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_prod>:
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
mov    -0x14(%rbp),%ecx
sar    $0x2,%ecx
cmp    %ecx,%eax
jge    1247 <inner_prod+0xc7>
mov    -0x20(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <_mm_loadu_ps@plt>
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%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
add    $0x10,%rdi
call   1040 <_mm_loadu_ps@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%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    -0x8(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x18(%rbp)
jmp    11a4 <inner_prod+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_prod>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%rbp
xor    %r13d,%r13d
xor    %eax,%eax
call   10a0 <_mm_setzero_ps@plt>
mov    %eax,%r15d
cmp    $0x4,%r14d
jl     1217 <inner_prod+0x97>
sar    $0x2,%r14d
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   1040 <_mm_loadu_ps@plt>
mov    %eax,%r12d
mov    %rbx,%rdi
call   1040 <_mm_loadu_ps@plt>
mov    %r12d,%edi
mov    %eax,%esi
call   1070 <_mm_mul_ps@plt>
mov    %r15d,%edi
mov    %eax,%esi
call   1080 <_mm_add_ps@plt>
mov    %eax,%r15d
lea    0x10(%rbp),%rdi
call   1040 <_mm_loadu_ps@plt>
mov    %eax,%r12d
lea    0x10(%rbx),%rdi
call   1040 <_mm_loadu_ps@plt>
mov    %r12d,%edi
mov    %eax,%esi
call   1070 <_mm_mul_ps@plt>
mov    %r15d,%edi
mov    %eax,%esi
call   1080 <_mm_add_ps@plt>
mov    %eax,%r15d
add    $0x2,%r13d
add    $0x20,%rbp
add    $0x20,%rbx
cmp    %r14d,%r13d
jl     11b0 <inner_prod+0x30>
mov    %r15d,%edi
mov    %r15d,%esi
call   1090 <_mm_movehl_ps@plt>
mov    %r15d,%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    0x4(%rsp),%rdi
mov    %eax,%esi
call   1050 <_mm_store_ss@plt>
movss  0x4(%rsp),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define float @inner_prod(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 = %39, %3
%12 = load i32, i32* %7
%13 = load i32, i32* %6
%14 = ashr i32 %13, 2
%15 = icmp slt i32 %12, %14
br i1 %15, label %16, label %42
16: ; preds = %11
%17 = load i32, i32* %9
%18 = load float*, float** %4
%19 = getelementptr inbounds float, float* %18, i64 0
%20 = call i32 @_mm_loadu_ps(float* %19)
%21 = load float*, float** %5
%22 = getelementptr inbounds float, float* %21, i64 0
%23 = call i32 @_mm_loadu_ps(float* %22)
%24 = call i32 @_mm_mul_ps(i32 %20, i32 %23)
%25 = call i32 @_mm_add_ps(i32 %17, i32 %24)
store i32 %25, i32* %9
%26 = load i32, i32* %9
%27 = load float*, float** %4
%28 = getelementptr inbounds float, float* %27, i64 4
%29 = call i32 @_mm_loadu_ps(float* %28)
%30 = load float*, float** %5
%31 = getelementptr inbounds float, float* %30, i64 4
%32 = call i32 @_mm_loadu_ps(float* %31)
%33 = call i32 @_mm_mul_ps(i32 %29, i32 %32)
%34 = call i32 @_mm_add_ps(i32 %26, i32 %33)
store i32 %34, i32* %9
%35 = load float*, float** %4
%36 = getelementptr inbounds float, float* %35, i64 8
store float* %36, float** %4
%37 = load float*, float** %5
%38 = getelementptr inbounds float, float* %37, i64 8
store float* %38, float** %5
br label %39
39: ; preds = %16
%40 = load i32, i32* %7
%41 = add nsw i32 %40, 2
store i32 %41, i32* %7
br label %11
42: ; preds = %11
%43 = load i32, i32* %9
%44 = load i32, i32* %9
%45 = load i32, i32* %9
%46 = call i32 @_mm_movehl_ps(i32 %44, i32 %45)
%47 = call i32 @_mm_add_ps(i32 %43, i32 %46)
store i32 %47, i32* %9
%48 = load i32, i32* %9
%49 = load i32, i32* %9
%50 = load i32, i32* %9
%51 = call i32 @_mm_shuffle_ps(i32 %49, i32 %50, i32 85)
%52 = call i32 @_mm_add_ss(i32 %48, i32 %51)
store i32 %52, i32* %9
%53 = load i32, i32* %9
%54 = call i32 @_mm_store_ss(float* %8, i32 %53)
%55 = load float, float* %8
ret float %55
}

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