#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;

/* Variables and functions */
int /*<<< orphan*/ _MM_SHUFFLE2(int /*<<< orphan*/, int);
int /*<<< orphan*/ _mm_add_pd(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_load1_pd(double const *);
int /*<<< orphan*/ _mm_load_pd(double const *);
int /*<<< orphan*/ _mm_mul_pd(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_setzero_pd();
int /*<<< orphan*/ _mm_shuffle_pd(int /*<<< orphan*/, int /*<<< orphan*/,
                                  int /*<<< orphan*/);
int /*<<< orphan*/ _mm_storeu_pd(double *, int /*<<< orphan*/);
double sse_filtering_misaligned(const double *restrict filt,
                                const double *restrict signal, const int K) {
  __m128d v = _mm_setzero_pd();
  __m128d s = _mm_load1_pd(signal);
  int k = 0;
  for (; k < K - 4; k += 4) {
    __m128d f = _mm_load_pd(filt + k);
    __m128d s2 = _mm_load_pd(signal + k + 1);
    s = _mm_shuffle_pd(s, s2, _MM_SHUFFLE2(0, 1));
    v = _mm_add_pd(v, _mm_mul_pd(f, s));
    f = _mm_load_pd(filt + k + 2);
    s = _mm_load_pd(signal + k + 3);
    s2 = _mm_shuffle_pd(s2, s, _MM_SHUFFLE2(0, 1));
    v = _mm_add_pd(v, _mm_mul_pd(f, s2));
  }
  double tmp[2];
  _mm_storeu_pd(tmp, v);
  for (; k < K; ++k)
    tmp[0] += filt[k] * signal[k];
  return tmp[0] + tmp[1];
}


x86 assembly (clang, -O0):
<sse_filtering_misaligned>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    $0x0,%al
call   1080 <_mm_setzero_pd@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <_mm_load1_pd@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x4,%ecx
cmp    %ecx,%eax
jge    12c3 <sse_filtering_misaligned+0x143>
mov    -0x8(%rbp),%rdi
movslq -0x20(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
call   1070 <_mm_load_pd@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x20(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
add    $0x8,%rdi
call   1070 <_mm_load_pd@plt>
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x54(%rbp)
xor    %edi,%edi
mov    $0x1,%esi
call   1030 <_MM_SHUFFLE2@plt>
mov    -0x58(%rbp),%edi
mov    -0x54(%rbp),%esi
mov    %eax,%edx
call   1060 <_mm_shuffle_pd@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   10a0 <_mm_mul_pd@plt>
mov    -0x50(%rbp),%edi
mov    %eax,%esi
call   1050 <_mm_add_pd@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x20(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
add    $0x10,%rdi
call   1070 <_mm_load_pd@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x20(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
add    $0x18,%rdi
call   1070 <_mm_load_pd@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x48(%rbp)
xor    %edi,%edi
mov    $0x1,%esi
call   1030 <_MM_SHUFFLE2@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%esi
mov    %eax,%edx
call   1060 <_mm_shuffle_pd@plt>
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x28(%rbp),%esi
call   10a0 <_mm_mul_pd@plt>
mov    -0x44(%rbp),%edi
mov    %eax,%esi
call   1050 <_mm_add_pd@plt>
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x20(%rbp)
jmp    11b0 <sse_filtering_misaligned+0x30>
lea    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1090 <_mm_storeu_pd@plt>
mov    -0x20(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1315 <sse_filtering_misaligned+0x195>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x40(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    12cf <sse_filtering_misaligned+0x14f>
movsd  -0x40(%rbp),%xmm0
addsd  -0x38(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sse_filtering_misaligned>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %edx,%r15d
mov    %rsi,%rbx
mov    %rdi,%r12
xor    %eax,%eax
call   1080 <_mm_setzero_pd@plt>
mov    %eax,(%rsp)
mov    %rbx,%rdi
call   1040 <_mm_load1_pd@plt>
cmp    $0x5,%r15d
mov    %r15,0x18(%rsp)
mov    %rbx,0x10(%rsp)
mov    %r12,0x8(%rsp)
jl     1288 <sse_filtering_misaligned+0x108>
mov    %eax,%r14d
lea    -0x4(%r15),%eax
mov    %eax,0x4(%rsp)
lea    0x18(%rbx),%r13
xor    %ebp,%ebp
mov    %r12,%rbx
mov    (%rsp),%r15d
nopw   0x0(%rax,%rax,1)
mov    %ebp,(%rsp)
mov    %rbx,%rdi
call   1070 <_mm_load_pd@plt>
mov    %eax,%r12d
lea    -0x10(%r13),%rdi
call   1070 <_mm_load_pd@plt>
mov    %eax,%ebp
xor    %edi,%edi
mov    $0x1,%esi
call   1030 <_MM_SHUFFLE2@plt>
mov    %r14d,%edi
mov    %ebp,%esi
mov    %eax,%edx
call   1060 <_mm_shuffle_pd@plt>
mov    %r12d,%edi
mov    %eax,%esi
call   10a0 <_mm_mul_pd@plt>
mov    %r15d,%edi
mov    %eax,%esi
call   1050 <_mm_add_pd@plt>
mov    %eax,%r15d
lea    0x10(%rbx),%rdi
call   1070 <_mm_load_pd@plt>
mov    %eax,%r12d
mov    %r13,%rdi
call   1070 <_mm_load_pd@plt>
mov    %eax,%r14d
xor    %edi,%edi
mov    $0x1,%esi
call   1030 <_MM_SHUFFLE2@plt>
mov    %ebp,%edi
mov    (%rsp),%ebp
mov    %r14d,%esi
mov    %eax,%edx
call   1060 <_mm_shuffle_pd@plt>
mov    %r12d,%edi
mov    %eax,%esi
call   10a0 <_mm_mul_pd@plt>
mov    %r15d,%edi
mov    %eax,%esi
call   1050 <_mm_add_pd@plt>
mov    %eax,%r15d
add    $0x20,%r13
add    $0x20,%rbx
add    $0x4,%ebp
cmp    %ebp,0x4(%rsp)
jg     11e0 <sse_filtering_misaligned+0x60>
jmp    128e <sse_filtering_misaligned+0x10e>
xor    %ebp,%ebp
mov    (%rsp),%r15d
lea    0x20(%rsp),%rdi
mov    %r15d,%esi
call   1090 <_mm_storeu_pd@plt>
movsd  0x20(%rsp),%xmm0
mov    0x18(%rsp),%rdx
cmp    %edx,%ebp
jge    1336 <sse_filtering_misaligned+0x1b6>
mov    %ebp,%eax
mov    %edx,%ecx
sub    %ebp,%ecx
not    %ebp
add    %edx,%ebp
and    $0x3,%ecx
je     134b <sse_filtering_misaligned+0x1cb>
mov    0x10(%rsp),%rsi
mov    0x8(%rsp),%rdi
nopl   0x0(%rax,%rax,1)
movsd  (%rdi,%rax,8),%xmm1
mulsd  (%rsi,%rax,8),%xmm1
addsd  %xmm1,%xmm0
add    $0x1,%rax
add    $0xffffffff,%ecx
jne    12d0 <sse_filtering_misaligned+0x150>
cmp    $0x3,%ebp
jb     1336 <sse_filtering_misaligned+0x1b6>
nopl   0x0(%rax)
movsd  (%rdi,%rax,8),%xmm1
movsd  0x8(%rdi,%rax,8),%xmm2
mulsd  (%rsi,%rax,8),%xmm1
mulsd  0x8(%rsi,%rax,8),%xmm2
addsd  %xmm0,%xmm1
movsd  0x10(%rdi,%rax,8),%xmm3
mulsd  0x10(%rsi,%rax,8),%xmm3
addsd  %xmm1,%xmm2
movsd  0x18(%rdi,%rax,8),%xmm0
mulsd  0x18(%rsi,%rax,8),%xmm0
addsd  %xmm2,%xmm3
addsd  %xmm3,%xmm0
add    $0x4,%rax
cmp    %edx,%eax
jl     12f0 <sse_filtering_misaligned+0x170>
addsd  0x28(%rsp),%xmm0
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x10(%rsp),%rsi
mov    0x8(%rsp),%rdi
cmp    $0x3,%ebp
jae    12f0 <sse_filtering_misaligned+0x170>
jmp    1336 <sse_filtering_misaligned+0x1b6>

LLVM IR (-O0):
define double @sse_filtering_misaligned(double* noalias %0, double* noalias %1, i32 %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca [2 x double]
store double* %0, double** %4
store double* %1, double** %5
store i32 %2, i32* %6
%13 = call i32 (...) @_mm_setzero_pd()
store i32 %13, i32* %7
%14 = load double*, double** %5
%15 = call i32 @_mm_load1_pd(double* %14)
store i32 %15, i32* %8
store i32 0, i32* %9
br label %16
16: ; preds = %63, %3
%17 = load i32, i32* %9
%18 = load i32, i32* %6
%19 = sub nsw i32 %18, 4
%20 = icmp slt i32 %17, %19
br i1 %20, label %21, label %66
21: ; preds = %16
%22 = load double*, double** %4
%23 = load i32, i32* %9
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds double, double* %22, i64 %24
%26 = call i32 @_mm_load_pd(double* %25)
store i32 %26, i32* %10
%27 = load double*, double** %5
%28 = load i32, i32* %9
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds double, double* %27, i64 %29
%31 = getelementptr inbounds double, double* %30, i64 1
%32 = call i32 @_mm_load_pd(double* %31)
store i32 %32, i32* %11
%33 = load i32, i32* %8
%34 = load i32, i32* %11
%35 = call i32 @_MM_SHUFFLE2(i32 0, i32 1)
%36 = call i32 @_mm_shuffle_pd(i32 %33, i32 %34, i32 %35)
store i32 %36, i32* %8
%37 = load i32, i32* %7
%38 = load i32, i32* %10
%39 = load i32, i32* %8
%40 = call i32 @_mm_mul_pd(i32 %38, i32 %39)
%41 = call i32 @_mm_add_pd(i32 %37, i32 %40)
store i32 %41, i32* %7
%42 = load double*, double** %4
%43 = load i32, i32* %9
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds double, double* %42, i64 %44
%46 = getelementptr inbounds double, double* %45, i64 2
%47 = call i32 @_mm_load_pd(double* %46)
store i32 %47, i32* %10
%48 = load double*, double** %5
%49 = load i32, i32* %9
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds double, double* %48, i64 %50
%52 = getelementptr inbounds double, double* %51, i64 3
%53 = call i32 @_mm_load_pd(double* %52)
store i32 %53, i32* %8
%54 = load i32, i32* %11
%55 = load i32, i32* %8
%56 = call i32 @_MM_SHUFFLE2(i32 0, i32 1)
%57 = call i32 @_mm_shuffle_pd(i32 %54, i32 %55, i32 %56)
store i32 %57, i32* %11
%58 = load i32, i32* %7
%59 = load i32, i32* %10
%60 = load i32, i32* %11
%61 = call i32 @_mm_mul_pd(i32 %59, i32 %60)
%62 = call i32 @_mm_add_pd(i32 %58, i32 %61)
store i32 %62, i32* %7
br label %63
63: ; preds = %21
%64 = load i32, i32* %9
%65 = add nsw i32 %64, 4
store i32 %65, i32* %9
br label %16
66: ; preds = %16
%67 = getelementptr inbounds [2 x double], [2 x double]* %12, i64 0, i64 0
%68 = load i32, i32* %7
%69 = call i32 @_mm_storeu_pd(double* %67, i32 %68)
br label %70
70: ; preds = %88, %66
%71 = load i32, i32* %9
%72 = load i32, i32* %6
%73 = icmp slt i32 %71, %72
br i1 %73, label %74, label %91
74: ; preds = %70
%75 = load double*, double** %4
%76 = load i32, i32* %9
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds double, double* %75, i64 %77
%79 = load double, double* %78
%80 = load double*, double** %5
%81 = load i32, i32* %9
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds double, double* %80, i64 %82
%84 = load double, double* %83
%85 = getelementptr inbounds [2 x double], [2 x double]* %12, i64 0, i64 0
%86 = load double, double* %85
%87 = call double @llvm.fmuladd.f64(double %79, double %84, double %86)
store double %87, double* %85
br label %88
88: ; preds = %74
%89 = load i32, i32* %9
%90 = add nsw i32 %89, 1
store i32 %90, i32* %9
br label %70
91: ; preds = %70
%92 = getelementptr inbounds [2 x double], [2 x double]* %12, i64 0, i64 0
%93 = load double, double* %92
%94 = getelementptr inbounds [2 x double], [2 x double]* %12, i64 0, i64 1
%95 = load double, double* %94
%96 = fadd double %93, %95
ret double %96
}

LLVM IR (-O2):
define double @sse_filtering_misaligned(double* noalias %0, double* noalias %1, i32 %2) {
%4 = alloca [2 x double]
%5 = tail call i32 (...) @_mm_setzero_pd()
%6 = tail call i32 @_mm_load1_pd(double* %1)
%7 = add nsw i32 %2, -4
%8 = icmp sgt i32 %2, 4
br i1 %8, label %9, label %35
9: ; preds = %3, %9
%10 = phi i64 [ %30, %9 ], [ 0, %3 ]
%11 = phi i32 [ %29, %9 ], [ %5, %3 ]
%12 = phi i32 [ %25, %9 ], [ %6, %3 ]
%13 = getelementptr inbounds double, double* %0, i64 %10
%14 = tail call i32 @_mm_load_pd(double* %13)
%15 = getelementptr inbounds double, double* %1, i64 %10
%16 = getelementptr inbounds double, double* %15, i64 1
%17 = tail call i32 @_mm_load_pd(double* %16)
%18 = tail call i32 @_MM_SHUFFLE2(i32 0, i32 1)
%19 = tail call i32 @_mm_shuffle_pd(i32 %12, i32 %17, i32 %18)
%20 = tail call i32 @_mm_mul_pd(i32 %14, i32 %19)
%21 = tail call i32 @_mm_add_pd(i32 %11, i32 %20)
%22 = getelementptr inbounds double, double* %13, i64 2
%23 = tail call i32 @_mm_load_pd(double* %22)
%24 = getelementptr inbounds double, double* %15, i64 3
%25 = tail call i32 @_mm_load_pd(double* %24)
%26 = tail call i32 @_MM_SHUFFLE2(i32 0, i32 1)
%27 = tail call i32 @_mm_shuffle_pd(i32 %17, i32 %25, i32 %26)
%28 = tail call i32 @_mm_mul_pd(i32 %23, i32 %27)
%29 = tail call i32 @_mm_add_pd(i32 %21, i32 %28)
%30 = add nuw i64 %10, 4
%31 = trunc i64 %30 to i32
%32 = icmp sgt i32 %7, %31
br i1 %32, label %9, label %33
33: ; preds = %9
%34 = trunc i64 %30 to i32
br label %35
35: ; preds = %33, %3
%36 = phi i32 [ 0, %3 ], [ %34, %33 ]
%37 = phi i32 [ %5, %3 ], [ %29, %33 ]
%38 = bitcast [2 x double]* %4 to i8*
%39 = getelementptr inbounds [2 x double], [2 x double]* %4, i64 0, i64 0
%40 = call i32 @_mm_storeu_pd(double* %39, i32 %37)
%41 = load double, double* %39
%42 = icmp slt i32 %36, %2
br i1 %42, label %43, label %96
43: ; preds = %35
%44 = zext i32 %36 to i64
%45 = sub i32 %2, %36
%46 = xor i32 %36, -1
%47 = add i32 %46, %2
%48 = and i32 %45, 3
%49 = icmp eq i32 %48, 0
br i1 %49, label %62, label %50
50: ; preds = %43, %50
%51 = phi i64 [ %59, %50 ], [ %44, %43 ]
%52 = phi double [ %58, %50 ], [ %41, %43 ]
%53 = phi i32 [ %60, %50 ], [ 0, %43 ]
%54 = getelementptr inbounds double, double* %0, i64 %51
%55 = load double, double* %54
%56 = getelementptr inbounds double, double* %1, i64 %51
%57 = load double, double* %56
%58 = call double @llvm.fmuladd.f64(double %55, double %57, double %52)
%59 = add nuw nsw i64 %51, 1
%60 = add i32 %53, 1
%61 = icmp eq i32 %60, %48
br i1 %61, label %62, label %50
62: ; preds = %50, %43
%63 = phi i64 [ %44, %43 ], [ %59, %50 ]
%64 = phi double [ %41, %43 ], [ %58, %50 ]
%65 = phi double [ undef, %43 ], [ %58, %50 ]
%66 = icmp ult i32 %47, 3
br i1 %66, label %96, label %67
67: ; preds = %62, %67
%68 = phi i64 [ %93, %67 ], [ %63, %62 ]
%69 = phi double [ %92, %67 ], [ %64, %62 ]
%70 = getelementptr inbounds double, double* %0, i64 %68
%71 = load double, double* %70
%72 = getelementptr inbounds double, double* %1, i64 %68
%73 = load double, double* %72
%74 = call double @llvm.fmuladd.f64(double %71, double %73, double %69)
%75 = add nuw nsw i64 %68, 1
%76 = getelementptr inbounds double, double* %0, i64 %75
%77 = load double, double* %76
%78 = getelementptr inbounds double, double* %1, i64 %75
%79 = load double, double* %78
%80 = call double @llvm.fmuladd.f64(double %77, double %79, double %74)
%81 = add nuw nsw i64 %68, 2
%82 = getelementptr inbounds double, double* %0, i64 %81
%83 = load double, double* %82
%84 = getelementptr inbounds double, double* %1, i64 %81
%85 = load double, double* %84
%86 = call double @llvm.fmuladd.f64(double %83, double %85, double %80)
%87 = add nuw nsw i64 %68, 3
%88 = getelementptr inbounds double, double* %0, i64 %87
%89 = load double, double* %88
%90 = getelementptr inbounds double, double* %1, i64 %87
%91 = load double, double* %90
%92 = call double @llvm.fmuladd.f64(double %89, double %91, double %86)
%93 = add nuw nsw i64 %68, 4
%94 = trunc i64 %93 to i32
%95 = icmp slt i32 %94, %2
br i1 %95, label %67, label %96
96: ; preds = %62, %67, %35
%97 = phi double [ %41, %35 ], [ %65, %62 ], [ %92, %67 ]
%98 = getelementptr inbounds [2 x double], [2 x double]* %4, i64 0, i64 1
%99 = load double, double* %98
%100 = fadd double %97, %99
ret double %100
}