#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_load1_ps(float const *);
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 interpolate_product_single(const float *a, const float *b,
                                 unsigned int len,
                                 const unsigned int oversample, float *frac) {
  int i;
  float ret;
  if (1) {
    __m128 sum = _mm_setzero_ps();
    __m128 f = _mm_loadu_ps(frac);
    for (i = 0; i < len; i += 2) {
      sum = _mm_add_ps(sum, _mm_mul_ps(_mm_load1_ps(a + i),
                                       _mm_loadu_ps(b + i * oversample)));
      sum = _mm_add_ps(sum, _mm_mul_ps(_mm_load1_ps(a + i + 1),
                                       _mm_loadu_ps(b + (i + 1) * oversample)));
    }
    sum = _mm_mul_ps(f, sum);
    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);
  } else {
    float accum[4] = {0, 0, 0, 0};
    for (i = 0; i < len; i++) {
      const float curr_in = a[i];
      accum[0] += curr_in * b[i * oversample + 0];
      accum[1] += curr_in * b[i * oversample + 1];
      accum[2] += curr_in * b[i * oversample + 2];
      accum[3] += curr_in * b[i * oversample + 3];
    }
    ret = accum[0] * frac[0] + accum[1] * frac[1] + accum[2] * frac[2] +
          accum[3] * frac[3];
  }
  return ret;
}


x86 assembly (clang, -O0):
<interpolate_product_single>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    $0x0,%al
call   10b0 <_mm_setzero_ps@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <_mm_loadu_ps@plt>
mov    %eax,-0x30(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    1282 <interpolate_product_single+0xf2>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
call   10a0 <_mm_load1_ps@plt>
mov    %eax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%eax
imul   -0x18(%rbp),%eax
mov    %eax,%eax
shl    $0x2,%rax
add    %rax,%rdi
call   1040 <_mm_loadu_ps@plt>
mov    -0x40(%rbp),%edi
mov    %eax,%esi
call   1070 <_mm_mul_ps@plt>
mov    -0x3c(%rbp),%edi
mov    %eax,%esi
call   1080 <_mm_add_ps@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
add    $0x4,%rdi
call   10a0 <_mm_load1_ps@plt>
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%eax
add    $0x1,%eax
imul   -0x18(%rbp),%eax
mov    %eax,%eax
shl    $0x2,%rax
add    %rax,%rdi
call   1040 <_mm_loadu_ps@plt>
mov    -0x38(%rbp),%edi
mov    %eax,%esi
call   1070 <_mm_mul_ps@plt>
mov    -0x34(%rbp),%edi
mov    %eax,%esi
call   1080 <_mm_add_ps@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x24(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x24(%rbp)
jmp    11c7 <interpolate_product_single+0x37>
mov    -0x30(%rbp),%edi
mov    -0x2c(%rbp),%esi
call   1070 <_mm_mul_ps@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x2c(%rbp),%esi
call   1090 <_mm_movehl_ps@plt>
mov    -0x48(%rbp),%edi
mov    %eax,%esi
call   1080 <_mm_add_ps@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x2c(%rbp),%esi
mov    $0x55,%edx
call   1030 <_mm_shuffle_ps@plt>
mov    -0x44(%rbp),%edi
mov    %eax,%esi
call   1060 <_mm_add_ss@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%esi
lea    -0x28(%rbp),%rdi
call   1050 <_mm_store_ss@plt>
movss  -0x28(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<interpolate_product_single>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8,%r14
mov    %rcx,0x18(%rsp)
mov    %edx,%ebp
mov    %rsi,%r15
mov    %rdi,%rbx
xor    %r13d,%r13d
xor    %eax,%eax
call   10b0 <_mm_setzero_ps@plt>
mov    %eax,%r12d
mov    %r14,%rdi
call   1040 <_mm_loadu_ps@plt>
mov    %eax,0xc(%rsp)
test   %ebp,%ebp
je     1262 <interpolate_product_single+0xd2>
mov    %ebp,%eax
mov    %rax,0x20(%rsp)
mov    0x18(%rsp),%rax
add    %eax,%eax
mov    %eax,0x10(%rsp)
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   10a0 <_mm_load1_ps@plt>
mov    %eax,%ebp
mov    %r13d,%eax
lea    (%r15,%rax,4),%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,%r12d
lea    0x4(%rbx),%rdi
call   10a0 <_mm_load1_ps@plt>
mov    %eax,%ebp
mov    0x18(%rsp),%rax
add    %r13d,%eax
lea    (%r15,%rax,4),%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,%r12d
add    $0x2,%r14
add    0x10(%rsp),%r13d
add    $0x8,%rbx
cmp    0x20(%rsp),%r14
jb     11f0 <interpolate_product_single+0x60>
mov    0xc(%rsp),%edi
mov    %r12d,%esi
call   1070 <_mm_mul_ps@plt>
mov    %eax,%ebx
mov    %eax,%edi
mov    %eax,%esi
call   1090 <_mm_movehl_ps@plt>
mov    %ebx,%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    0x14(%rsp),%rdi
mov    %eax,%esi
call   1050 <_mm_store_ss@plt>
movss  0x14(%rsp),%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define float @interpolate_product_single(float* %0, float* %1, i32 %2, i32 %3, float* %4) {
%6 = alloca float
%7 = bitcast float* %6 to i8*
%8 = tail call i32 (...) @_mm_setzero_ps()
%9 = tail call i32 @_mm_loadu_ps(float* %4)
%10 = icmp eq i32 %2, 0
br i1 %10, label %37, label %11
11: ; preds = %5
%12 = zext i32 %2 to i64
br label %13
13: ; preds = %11, %13
%14 = phi i64 [ 0, %11 ], [ %35, %13 ]
%15 = phi i32 [ %8, %11 ], [ %34, %13 ]
%16 = getelementptr inbounds float, float* %0, i64 %14
%17 = tail call i32 @_mm_load1_ps(float* %16)
%18 = trunc i64 %14 to i32
%19 = mul i32 %18, %3
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds float, float* %1, i64 %20
%22 = tail call i32 @_mm_loadu_ps(float* %21)
%23 = tail call i32 @_mm_mul_ps(i32 %17, i32 %22)
%24 = tail call i32 @_mm_add_ps(i32 %15, i32 %23)
%25 = getelementptr inbounds float, float* %16, i64 1
%26 = tail call i32 @_mm_load1_ps(float* %25)
%27 = trunc i64 %14 to i32
%28 = or i32 %27, 1
%29 = mul i32 %28, %3
%30 = zext i32 %29 to i64
%31 = getelementptr inbounds float, float* %1, i64 %30
%32 = tail call i32 @_mm_loadu_ps(float* %31)
%33 = tail call i32 @_mm_mul_ps(i32 %26, i32 %32)
%34 = tail call i32 @_mm_add_ps(i32 %24, i32 %33)
%35 = add nuw nsw i64 %14, 2
%36 = icmp ult i64 %35, %12
br i1 %36, label %13, label %37
37: ; preds = %13, %5
%38 = phi i32 [ %8, %5 ], [ %34, %13 ]
%39 = tail call i32 @_mm_mul_ps(i32 %9, i32 %38)
%40 = tail call i32 @_mm_movehl_ps(i32 %39, i32 %39)
%41 = tail call i32 @_mm_add_ps(i32 %39, i32 %40)
%42 = tail call i32 @_mm_shuffle_ps(i32 %41, i32 %41, i32 85)
%43 = tail call i32 @_mm_add_ss(i32 %41, i32 %42)
%44 = call i32 @_mm_store_ss(float* %6, i32 %43)
%45 = load float, float* %6
ret float %45
}