void wkeep_1D_right(double *sigIn, int sigInLength, double *sigOut,
                    int sigOutLength) {
  int count = 0;
  for (count = 0; count < sigOutLength; count++)
    sigOut[count] = sigIn[sigInLength - sigOutLength + count];
  return;
}


x86 assembly (clang, -O0):
<wkeep_1D_right>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    115c <wkeep_1D_right+0x5c>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    -0x1c(%rbp),%ecx
add    -0x20(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1120 <wkeep_1D_right+0x20>
pop    %rbp
ret

x86 assembly (clang, -O2):
<wkeep_1D_right>:
test   %ecx,%ecx
jle    1296 <wkeep_1D_right+0x196>
sub    %ecx,%esi
movslq %esi,%r8
mov    %ecx,%r10d
cmp    $0x4,%ecx
jb     1137 <wkeep_1D_right+0x37>
lea    (%r8,%r10,1),%rax
lea    (%rdi,%rax,8),%rax
cmp    %rdx,%rax
jbe    11bc <wkeep_1D_right+0xbc>
lea    (%rdx,%r10,8),%rax
lea    (%rdi,%r8,8),%rcx
cmp    %rax,%rcx
jae    11bc <wkeep_1D_right+0xbc>
xor    %ecx,%ecx
mov    %rcx,%r9
not    %r9
add    %r10,%r9
mov    %r10,%rsi
and    $0x3,%rsi
je     1164 <wkeep_1D_right+0x64>
lea    (%rdi,%r8,8),%rax
nop
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rdx,%rcx,8)
add    $0x1,%rcx
add    $0xffffffffffffffff,%rsi
jne    1150 <wkeep_1D_right+0x50>
cmp    $0x3,%r9
jb     1296 <wkeep_1D_right+0x196>
lea    (%rdi,%r8,8),%rax
add    $0x18,%rax
cs nopw 0x0(%rax,%rax,1)
movsd  -0x18(%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rdx,%rcx,8)
movsd  -0x10(%rax,%rcx,8),%xmm0
movsd  %xmm0,0x8(%rdx,%rcx,8)
movsd  -0x8(%rax,%rcx,8),%xmm0
movsd  %xmm0,0x10(%rdx,%rcx,8)
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,0x18(%rdx,%rcx,8)
add    $0x4,%rcx
cmp    %rcx,%r10
jne    1180 <wkeep_1D_right+0x80>
jmp    1296 <wkeep_1D_right+0x196>
mov    %r10d,%ecx
and    $0xfffffffc,%ecx
lea    -0x4(%rcx),%rax
mov    %rax,%r11
shr    $0x2,%r11
add    $0x1,%r11
mov    %r11d,%r9d
and    $0x3,%r9d
cmp    $0xc,%rax
jae    11e2 <wkeep_1D_right+0xe2>
xor    %eax,%eax
jmp    1248 <wkeep_1D_right+0x148>
and    $0xfffffffffffffffc,%r11
lea    (%rdi,%r8,8),%rsi
add    $0x70,%rsi
xor    %eax,%eax
movups -0x70(%rsi,%rax,8),%xmm0
movups -0x60(%rsi,%rax,8),%xmm1
movups %xmm0,(%rdx,%rax,8)
movups %xmm1,0x10(%rdx,%rax,8)
movups -0x50(%rsi,%rax,8),%xmm0
movups -0x40(%rsi,%rax,8),%xmm1
movups %xmm0,0x20(%rdx,%rax,8)
movups %xmm1,0x30(%rdx,%rax,8)
movups -0x30(%rsi,%rax,8),%xmm0
movups -0x20(%rsi,%rax,8),%xmm1
movups %xmm0,0x40(%rdx,%rax,8)
movups %xmm1,0x50(%rdx,%rax,8)
movups -0x10(%rsi,%rax,8),%xmm0
movups (%rsi,%rax,8),%xmm1
movups %xmm0,0x60(%rdx,%rax,8)
movups %xmm1,0x70(%rdx,%rax,8)
add    $0x10,%rax
add    $0xfffffffffffffffc,%r11
jne    11f0 <wkeep_1D_right+0xf0>
test   %r9,%r9
je     128d <wkeep_1D_right+0x18d>
lea    (%rdx,%rax,8),%r11
add    $0x10,%r11
add    %r8,%rax
lea    (%rdi,%rax,8),%rax
add    $0x10,%rax
shl    $0x5,%r9
xor    %esi,%esi
cs nopw 0x0(%rax,%rax,1)
movups -0x10(%rax,%rsi,1),%xmm0
movups (%rax,%rsi,1),%xmm1
movups %xmm0,-0x10(%r11,%rsi,1)
movups %xmm1,(%r11,%rsi,1)
add    $0x20,%rsi
cmp    %rsi,%r9
jne    1270 <wkeep_1D_right+0x170>
cmp    %r10,%rcx
jne    1139 <wkeep_1D_right+0x39>
ret

LLVM IR (-O0):
define void @wkeep_1D_right(double* %0, i32 %1, double* %2, i32 %3) {
%5 = alloca double*
%6 = alloca i32
%7 = alloca double*
%8 = alloca i32
%9 = alloca i32
store double* %0, double** %5
store i32 %1, i32* %6
store double* %2, double** %7
store i32 %3, i32* %8
store i32 0, i32* %9
store i32 0, i32* %9
br label %10
10: ; preds = %28, %4
%11 = load i32, i32* %9
%12 = load i32, i32* %8
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %31
14: ; preds = %10
%15 = load double*, double** %5
%16 = load i32, i32* %6
%17 = load i32, i32* %8
%18 = sub nsw i32 %16, %17
%19 = load i32, i32* %9
%20 = add nsw i32 %18, %19
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds double, double* %15, i64 %21
%23 = load double, double* %22
%24 = load double*, double** %7
%25 = load i32, i32* %9
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds double, double* %24, i64 %26
store double %23, double* %27
br label %28
28: ; preds = %14
%29 = load i32, i32* %9
%30 = add nsw i32 %29, 1
store i32 %30, i32* %9
br label %10
31: ; preds = %10
ret void
}

LLVM IR (-O2):
define void @wkeep_1D_right(double* nocapture %0, i32 %1, double* nocapture writeonly %2, i32 %3) {
%5 = icmp sgt i32 %3, 0
br i1 %5, label %6, label %145
6: ; preds = %4
%7 = sub i32 %1, %3
%8 = sext i32 %7 to i64
%9 = zext i32 %3 to i64
%10 = icmp ult i32 %3, 4
br i1 %10, label %103, label %11
11: ; preds = %6
%12 = getelementptr double, double* %2, i64 %9
%13 = getelementptr double, double* %0, i64 %8
%14 = add nsw i64 %8, %9
%15 = getelementptr double, double* %0, i64 %14
%16 = icmp ugt double* %15, %2
%17 = icmp ult double* %13, %12
%18 = and i1 %16, %17
br i1 %18, label %103, label %19
19: ; preds = %11
%20 = and i64 %9, 4294967292
%21 = add nsw i64 %20, -4
%22 = lshr exact i64 %21, 2
%23 = add nuw nsw i64 %22, 1
%24 = and i64 %23, 3
%25 = icmp ult i64 %21, 12
br i1 %25, label %81, label %26
26: ; preds = %19
%27 = and i64 %23, 9223372036854775804
br label %28
28: ; preds = %28, %26
%29 = phi i64 [ 0, %26 ], [ %78, %28 ]
%30 = phi i64 [ 0, %26 ], [ %79, %28 ]
%31 = add nsw i64 %29, %8
%32 = getelementptr inbounds double, double* %0, i64 %31
%33 = bitcast double* %32 to <2 x double>*
%34 = load <2 x double>, <2 x double>* %33
%35 = getelementptr inbounds double, double* %32, i64 2
%36 = bitcast double* %35 to <2 x double>*
%37 = load <2 x double>, <2 x double>* %36
%38 = getelementptr inbounds double, double* %2, i64 %29
%39 = bitcast double* %38 to <2 x double>*
store <2 x double> %34, <2 x double>* %39
%40 = getelementptr inbounds double, double* %38, i64 2
%41 = bitcast double* %40 to <2 x double>*
store <2 x double> %37, <2 x double>* %41
%42 = or i64 %29, 4
%43 = add nsw i64 %42, %8
%44 = getelementptr inbounds double, double* %0, i64 %43
%45 = bitcast double* %44 to <2 x double>*
%46 = load <2 x double>, <2 x double>* %45
%47 = getelementptr inbounds double, double* %44, i64 2
%48 = bitcast double* %47 to <2 x double>*
%49 = load <2 x double>, <2 x double>* %48
%50 = getelementptr inbounds double, double* %2, i64 %42
%51 = bitcast double* %50 to <2 x double>*
store <2 x double> %46, <2 x double>* %51
%52 = getelementptr inbounds double, double* %50, i64 2
%53 = bitcast double* %52 to <2 x double>*
store <2 x double> %49, <2 x double>* %53
%54 = or i64 %29, 8
%55 = add nsw i64 %54, %8
%56 = getelementptr inbounds double, double* %0, i64 %55
%57 = bitcast double* %56 to <2 x double>*
%58 = load <2 x double>, <2 x double>* %57
%59 = getelementptr inbounds double, double* %56, i64 2
%60 = bitcast double* %59 to <2 x double>*
%61 = load <2 x double>, <2 x double>* %60
%62 = getelementptr inbounds double, double* %2, i64 %54
%63 = bitcast double* %62 to <2 x double>*
store <2 x double> %58, <2 x double>* %63
%64 = getelementptr inbounds double, double* %62, i64 2
%65 = bitcast double* %64 to <2 x double>*
store <2 x double> %61, <2 x double>* %65
%66 = or i64 %29, 12
%67 = add nsw i64 %66, %8
%68 = getelementptr inbounds double, double* %0, i64 %67
%69 = bitcast double* %68 to <2 x double>*
%70 = load <2 x double>, <2 x double>* %69
%71 = getelementptr inbounds double, double* %68, i64 2
%72 = bitcast double* %71 to <2 x double>*
%73 = load <2 x double>, <2 x double>* %72
%74 = getelementptr inbounds double, double* %2, i64 %66
%75 = bitcast double* %74 to <2 x double>*
store <2 x double> %70, <2 x double>* %75
%76 = getelementptr inbounds double, double* %74, i64 2
%77 = bitcast double* %76 to <2 x double>*
store <2 x double> %73, <2 x double>* %77
%78 = add nuw i64 %29, 16
%79 = add nuw i64 %30, 4
%80 = icmp eq i64 %79, %27
br i1 %80, label %81, label %28
81: ; preds = %28, %19
%82 = phi i64 [ 0, %19 ], [ %78, %28 ]
%83 = icmp eq i64 %24, 0
br i1 %83, label %101, label %84
84: ; preds = %81, %84
%85 = phi i64 [ %98, %84 ], [ %82, %81 ]
%86 = phi i64 [ %99, %84 ], [ 0, %81 ]
%87 = add nsw i64 %85, %8
%88 = getelementptr inbounds double, double* %0, i64 %87
%89 = bitcast double* %88 to <2 x double>*
%90 = load <2 x double>, <2 x double>* %89
%91 = getelementptr inbounds double, double* %88, i64 2
%92 = bitcast double* %91 to <2 x double>*
%93 = load <2 x double>, <2 x double>* %92
%94 = getelementptr inbounds double, double* %2, i64 %85
%95 = bitcast double* %94 to <2 x double>*
store <2 x double> %90, <2 x double>* %95
%96 = getelementptr inbounds double, double* %94, i64 2
%97 = bitcast double* %96 to <2 x double>*
store <2 x double> %93, <2 x double>* %97
%98 = add nuw i64 %85, 4
%99 = add i64 %86, 1
%100 = icmp eq i64 %99, %24
br i1 %100, label %101, label %84
101: ; preds = %84, %81
%102 = icmp eq i64 %20, %9
br i1 %102, label %145, label %103
103: ; preds = %11, %6, %101
%104 = phi i64 [ 0, %11 ], [ 0, %6 ], [ %20, %101 ]
%105 = xor i64 %104, -1
%106 = add nsw i64 %105, %9
%107 = and i64 %9, 3
%108 = icmp eq i64 %107, 0
br i1 %108, label %119, label %109
109: ; preds = %103, %109
%110 = phi i64 [ %116, %109 ], [ %104, %103 ]
%111 = phi i64 [ %117, %109 ], [ 0, %103 ]
%112 = add nsw i64 %110, %8
%113 = getelementptr inbounds double, double* %0, i64 %112
%114 = load double, double* %113
%115 = getelementptr inbounds double, double* %2, i64 %110
store double %114, double* %115
%116 = add nuw nsw i64 %110, 1
%117 = add i64 %111, 1
%118 = icmp eq i64 %117, %107
br i1 %118, label %119, label %109
119: ; preds = %109, %103
%120 = phi i64 [ %104, %103 ], [ %116, %109 ]
%121 = icmp ult i64 %106, 3
br i1 %121, label %145, label %122
122: ; preds = %119, %122
%123 = phi i64 [ %143, %122 ], [ %120, %119 ]
%124 = add nsw i64 %123, %8
%125 = getelementptr inbounds double, double* %0, i64 %124
%126 = load double, double* %125
%127 = getelementptr inbounds double, double* %2, i64 %123
store double %126, double* %127
%128 = add nuw nsw i64 %123, 1
%129 = add nsw i64 %128, %8
%130 = getelementptr inbounds double, double* %0, i64 %129
%131 = load double, double* %130
%132 = getelementptr inbounds double, double* %2, i64 %128
store double %131, double* %132
%133 = add nuw nsw i64 %123, 2
%134 = add nsw i64 %133, %8
%135 = getelementptr inbounds double, double* %0, i64 %134
%136 = load double, double* %135
%137 = getelementptr inbounds double, double* %2, i64 %133
store double %136, double* %137
%138 = add nuw nsw i64 %123, 3
%139 = add nsw i64 %138, %8
%140 = getelementptr inbounds double, double* %0, i64 %139
%141 = load double, double* %140
%142 = getelementptr inbounds double, double* %2, i64 %138
store double %141, double* %142
%143 = add nuw nsw i64 %123, 4
%144 = icmp eq i64 %143, %9
br i1 %144, label %145, label %122
145: ; preds = %119, %122, %101, %4
ret void
}