int test_extract(int argc, char *argv[]) {
  int i = 0;
  short test_input[160];
  short test_result[160 / 2];
  printf("\n * Test: %s\n", __PRETTY_FUNCTION__);
  for (i = 0; i < 160; i++) {
    test_input[i] = 1;
    i++;
    test_input[i] = 2;
  }
  for (i = 0; i < 160 / 2; i++) {
    test_result[i] = 0;
  }
  extract_mono_from_interleaved_stereo(test_input, &test_result[0], 160, 0);
  for (i = 0; i < 160 / 2; i++) {
    printf("test result in index %d is %d\n", i, test_result[i]);
  }
  extract_mono_from_interleaved_stereo(test_input, &test_result[0], 160, 1);
  for (i = 0; i < 160 / 2; i++) {
    printf("test result in index %d is %d\n", i, test_result[i]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<test_extract>:
push   %rbp
mov    %rsp,%rbp
sub    $0x200,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xec0(%rip),%rdi
lea    0xec7(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0xa0,-0x14(%rbp)
jge    1195 <test_extract+0x75>
movslq -0x14(%rbp),%rax
movw   $0x1,-0x160(%rbp,%rax,2)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
movslq -0x14(%rbp),%rax
movw   $0x2,-0x160(%rbp,%rax,2)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1155 <test_extract+0x35>
movl   $0x0,-0x14(%rbp)
cmpl   $0x50,-0x14(%rbp)
jge    11c2 <test_extract+0xa2>
movslq -0x14(%rbp),%rax
movw   $0x0,-0x200(%rbp,%rax,2)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    119c <test_extract+0x7c>
lea    -0x160(%rbp),%rdi
lea    -0x200(%rbp),%rsi
mov    $0xa0,%edx
xor    %ecx,%ecx
mov    $0x0,%al
call   1040 <extract_mono_from_interleaved_stereo@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x50,-0x14(%rbp)
jge    121a <test_extract+0xfa>
mov    -0x14(%rbp),%esi
movslq -0x14(%rbp),%rax
movswl -0x200(%rbp,%rax,2),%edx
ff
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11e5 <test_extract+0xc5>
lea    -0x160(%rbp),%rdi
lea    -0x200(%rbp),%rsi
mov    $0xa0,%edx
mov    $0x1,%ecx
mov    $0x0,%al
call   1040 <extract_mono_from_interleaved_stereo@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x50,-0x14(%rbp)
jge    1275 <test_extract+0x155>
mov    -0x14(%rbp),%esi
movslq -0x14(%rbp),%rax
movswl -0x200(%rbp,%rax,2),%edx
ff
lea    0xdcd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1240 <test_extract+0x120>
xor    %eax,%eax
add    $0x200,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_extract>:
push   %r14
push   %rbx
sub    $0x1e8,%rsp
lea    0xedf(%rip),%rdi
lea    0xee6(%rip),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
movaps 0xeba(%rip),%xmm0
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0x110(%rsp)
movaps %xmm0,0x120(%rsp)
movaps %xmm0,0x130(%rsp)
movaps %xmm0,0x140(%rsp)
movaps %xmm0,0x150(%rsp)
movaps %xmm0,0x160(%rsp)
movaps %xmm0,0x170(%rsp)
movaps %xmm0,0x180(%rsp)
movaps %xmm0,0x190(%rsp)
movaps %xmm0,0x1a0(%rsp)
movaps %xmm0,0x1b0(%rsp)
movaps %xmm0,0x1c0(%rsp)
movaps %xmm0,0x1d0(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
lea    0xa0(%rsp),%rdi
mov    %rsp,%rsi
mov    $0xa0,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   1040 <extract_mono_from_interleaved_stereo@plt>
lea    0xdfd(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movswl (%rsp,%rbx,2),%edx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%rbx
cmp    $0x50,%rbx
jne    1250 <test_extract+0x130>
lea    0xa0(%rsp),%rdi
mov    %rsp,%rsi
mov    $0xa0,%edx
mov    $0x1,%ecx
xor    %eax,%eax
call   1040 <extract_mono_from_interleaved_stereo@plt>
lea    0xdb0(%rip),%r14
xor    %ebx,%ebx
nop
movswl (%rsp,%rbx,2),%edx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%rbx
cmp    $0x50,%rbx
jne    1290 <test_extract+0x170>
xor    %eax,%eax
add    $0x1e8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [14 x i8] c"\0A * Test: %s\0A\00"
@__PRETTY_FUNCTION__.test_extract = [31 x i8] c"int test_extract(int, char **)\00"
@.str.1 = [31 x i8] c"test result in index %d is %d\0A\00"
define i32 @test_extract(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca [160 x i16]
%7 = alloca [80 x i16]
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i32 0, i32* %5
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @__PRETTY_FUNCTION__.test_extract, i64 0, i64 0))
store i32 0, i32* %5
br label %9
9: ; preds = %21, %2
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 160
br i1 %11, label %12, label %24
12: ; preds = %9
%13 = load i32, i32* %5
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [160 x i16], [160 x i16]* %6, i64 0, i64 %14
store i16 1, i16* %15
%16 = load i32, i32* %5
%17 = add nsw i32 %16, 1
store i32 %17, i32* %5
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [160 x i16], [160 x i16]* %6, i64 0, i64 %19
store i16 2, i16* %20
br label %21
21: ; preds = %12
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
br label %9
24: ; preds = %9
store i32 0, i32* %5
br label %25
25: ; preds = %32, %24
%26 = load i32, i32* %5
%27 = icmp slt i32 %26, 80
br i1 %27, label %28, label %35
28: ; preds = %25
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [80 x i16], [80 x i16]* %7, i64 0, i64 %30
store i16 0, i16* %31
br label %32
32: ; preds = %28
%33 = load i32, i32* %5
%34 = add nsw i32 %33, 1
store i32 %34, i32* %5
br label %25
35: ; preds = %25
%36 = getelementptr inbounds [160 x i16], [160 x i16]* %6, i64 0, i64 0
%37 = getelementptr inbounds [80 x i16], [80 x i16]* %7, i64 0, i64 0
%38 = call i32 (i16*, i16*, i32, i32, ...) bitcast (i32 (...)* @extract_mono_from_interleaved_stereo to i32 (i16*, i16*, i32, i32, ...)*)(i16* %36, i16* %37, i32 160, i32 0)
store i32 0, i32* %5
br label %39
39: ; preds = %50, %35
%40 = load i32, i32* %5
%41 = icmp slt i32 %40, 80
br i1 %41, label %42, label %53
42: ; preds = %39
%43 = load i32, i32* %5
%44 = load i32, i32* %5
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [80 x i16], [80 x i16]* %7, i64 0, i64 %45
%47 = load i16, i16* %46
%48 = sext i16 %47 to i32
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %43, i32 %48)
br label %50
50: ; preds = %42
%51 = load i32, i32* %5
%52 = add nsw i32 %51, 1
store i32 %52, i32* %5
br label %39
53: ; preds = %39
%54 = getelementptr inbounds [160 x i16], [160 x i16]* %6, i64 0, i64 0
%55 = getelementptr inbounds [80 x i16], [80 x i16]* %7, i64 0, i64 0
%56 = call i32 (i16*, i16*, i32, i32, ...) bitcast (i32 (...)* @extract_mono_from_interleaved_stereo to i32 (i16*, i16*, i32, i32, ...)*)(i16* %54, i16* %55, i32 160, i32 1)
store i32 0, i32* %5
br label %57
57: ; preds = %68, %53
%58 = load i32, i32* %5
%59 = icmp slt i32 %58, 80
br i1 %59, label %60, label %71
60: ; preds = %57
%61 = load i32, i32* %5
%62 = load i32, i32* %5
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [80 x i16], [80 x i16]* %7, i64 0, i64 %63
%65 = load i16, i16* %64
%66 = sext i16 %65 to i32
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %61, i32 %66)
br label %68
68: ; preds = %60
%69 = load i32, i32* %5
%70 = add nsw i32 %69, 1
store i32 %70, i32* %5
br label %57
71: ; preds = %57
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"\0A * Test: %s\0A\00"
@__PRETTY_FUNCTION__.test_extract = [31 x i8] c"int test_extract(int, char **)\00"
@.str.1 = [31 x i8] c"test result in index %d is %d\0A\00"
define i32 @test_extract(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [160 x i16]
%4 = alloca [80 x i16]
%5 = bitcast [80 x i16]* %4 to i8*
%6 = bitcast [160 x i16]* %3 to i8*
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @__PRETTY_FUNCTION__.test_extract, i64 0, i64 0))
%8 = bitcast [160 x i16]* %3 to <8 x i16>*
store <8 x i16> <i16 1, i16 2, i16 1, i16 2, i16 1, i16 2, i16 1, i16 2>, <8 x i16>* %8
%9 = getelementptr inbounds [160 x i16], [160 x i16]* %3, i64 0, i64 8
%10 = bitcast i16* %9 to <8 x i16>*
store <8 x i16> <i16 1, i16 2, i16 1, i16 2, i16 1, i16 2, i16 1, i16 2>, <8 x i16>* %10
%11 = getelementptr inbounds [160 x i16], [160 x i16]* %3, i64 0, i64 16
%12 = bitcast i16* %11 to <8 x i16>*
store <8 x i16> <i16 1, i16 2, i16 1, i16 2, i16 1, i16 2, i16 1, i16 2>, <8 x i16>* %12
%13 = getelementptr inbounds [160 x i16], [160 x i16]* %3, i64 0, i64 24
%14 = bitcast i16* %13 to <8 x i16>*
store <8 x i16> <i16 1, i16 2, i16 1, i16 2, i16 1, i16 2, i16 1, i16 2>, <8 x i16>* %14
%15 = getelementptr inbounds [160 x i16], [160 x i16]* %3, i64 0, i64 32
%16 = bitcast i16* %15 to <8 x i16>*
store <8 x i16> <i16 1, i16 2, i16 1, i16 2, i16 1, i16 2, i16 1, i16 2>, <8 x i16>* %16
%17 = getelementptr inbounds [160 x i16], [160 x i16]* %3, i64 0, i64 40
%18 = bitcast i16* %17 to <8 x i16>*
store <8 x i16> <i16 1, i16 2, i16 1, i16 2, i16 1, i16 2, i16 1, i16 2>, <8 x i16>* %18
%19 = getelementptr inbounds [160 x i16], [160 x i16]* %3, i64 0, i64 48
%20 = bitcast i16* %19 to <8 x i16>*
store <8 x i16> <i16 1, i16 2, i16 1, i16 2, i16 1, i16 2, i16 1, i16 2>, <8 x i16>* %20
%21 = getelementptr inbounds [160 x i16], [160 x i16]* %3, i64 0, i64 56
%22 = bitcast i16* %21 to <8 x i16>*
store <8 x i16> <i16 1, i16 2, i16 1, i16 2, i16 1, i16 2, i16 1, i16 2>, <8 x i16>* %22
%23 = getelementptr inbounds [160 x i16], [160 x i16]* %3, i64 0, i64 64
%24 = bitcast i16* %23 to <8 x i16>*
store <8 x i16> <i16 1, i16 2, i16 1, i16 2, i16 1, i16 2, i16 1, i16 2>, <8 x i16>* %24
%25 = getelementptr inbounds [160 x i16], [160 x i16]* %3, i64 0, i64 72
%26 = bitcast i16* %25 to <8 x i16>*
store <8 x i16> <i16 1, i16 2, i16 1, i16 2, i16 1, i16 2, i16 1, i16 2>, <8 x i16>* %26
%27 = getelementptr inbounds [160 x i16], [160 x i16]* %3, i64 0, i64 80
%28 = bitcast i16* %27 to <8 x i16>*
store <8 x i16> <i16 1, i16 2, i16 1, i16 2, i16 1, i16 2, i16 1, i16 2>, <8 x i16>* %28
%29 = getelementptr inbounds [160 x i16], [160 x i16]* %3, i64 0, i64 88
%30 = bitcast i16* %29 to <8 x i16>*
store <8 x i16> <i16 1, i16 2, i16 1, i16 2, i16 1, i16 2, i16 1, i16 2>, <8 x i16>* %30
%31 = getelementptr inbounds [160 x i16], [160 x i16]* %3, i64 0, i64 96
%32 = bitcast i16* %31 to <8 x i16>*
store <8 x i16> <i16 1, i16 2, i16 1, i16 2, i16 1, i16 2, i16 1, i16 2>, <8 x i16>* %32
%33 = getelementptr inbounds [160 x i16], [160 x i16]* %3, i64 0, i64 104
%34 = bitcast i16* %33 to <8 x i16>*
store <8 x i16> <i16 1, i16 2, i16 1, i16 2, i16 1, i16 2, i16 1, i16 2>, <8 x i16>* %34
%35 = getelementptr inbounds [160 x i16], [160 x i16]* %3, i64 0, i64 112
%36 = bitcast i16* %35 to <8 x i16>*
store <8 x i16> <i16 1, i16 2, i16 1, i16 2, i16 1, i16 2, i16 1, i16 2>, <8 x i16>* %36
%37 = getelementptr inbounds [160 x i16], [160 x i16]* %3, i64 0, i64 120
%38 = bitcast i16* %37 to <8 x i16>*
store <8 x i16> <i16 1, i16 2, i16 1, i16 2, i16 1, i16 2, i16 1, i16 2>, <8 x i16>* %38
%39 = getelementptr inbounds [160 x i16], [160 x i16]* %3, i64 0, i64 128
%40 = bitcast i16* %39 to <8 x i16>*
store <8 x i16> <i16 1, i16 2, i16 1, i16 2, i16 1, i16 2, i16 1, i16 2>, <8 x i16>* %40
%41 = getelementptr inbounds [160 x i16], [160 x i16]* %3, i64 0, i64 136
%42 = bitcast i16* %41 to <8 x i16>*
store <8 x i16> <i16 1, i16 2, i16 1, i16 2, i16 1, i16 2, i16 1, i16 2>, <8 x i16>* %42
%43 = getelementptr inbounds [160 x i16], [160 x i16]* %3, i64 0, i64 144
%44 = bitcast i16* %43 to <8 x i16>*
store <8 x i16> <i16 1, i16 2, i16 1, i16 2, i16 1, i16 2, i16 1, i16 2>, <8 x i16>* %44
%45 = getelementptr inbounds [160 x i16], [160 x i16]* %3, i64 0, i64 152
%46 = bitcast i16* %45 to <8 x i16>*
store <8 x i16> <i16 1, i16 2, i16 1, i16 2, i16 1, i16 2, i16 1, i16 2>, <8 x i16>* %46
%47 = getelementptr inbounds [160 x i16], [160 x i16]* %3, i64 0, i64 0
%48 = getelementptr inbounds [80 x i16], [80 x i16]* %4, i64 0, i64 0
%49 = call i32 (i16*, i16*, i32, i32, ...) bitcast (i32 (...)* @extract_mono_from_interleaved_stereo to i32 (i16*, i16*, i32, i32, ...)*)(i16* %47, i16* %48, i32 160, i32 0)
br label %50
50: ; preds = %2, %50
%51 = phi i64 [ 0, %2 ], [ %57, %50 ]
%52 = getelementptr inbounds [80 x i16], [80 x i16]* %4, i64 0, i64 %51
%53 = load i16, i16* %52
%54 = sext i16 %53 to i32
%55 = trunc i64 %51 to i32
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %55, i32 %54)
%57 = add nuw nsw i64 %51, 1
%58 = icmp eq i64 %57, 80
br i1 %58, label %59, label %50
59: ; preds = %50
%60 = call i32 (i16*, i16*, i32, i32, ...) bitcast (i32 (...)* @extract_mono_from_interleaved_stereo to i32 (i16*, i16*, i32, i32, ...)*)(i16* %47, i16* %48, i32 160, i32 1)
br label %61
61: ; preds = %59, %61
%62 = phi i64 [ 0, %59 ], [ %68, %61 ]
%63 = getelementptr inbounds [80 x i16], [80 x i16]* %4, i64 0, i64 %62
%64 = load i16, i16* %63
%65 = sext i16 %64 to i32
%66 = trunc i64 %62 to i32
%67 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %66, i32 %65)
%68 = add nuw nsw i64 %62, 1
%69 = icmp eq i64 %68, 80
br i1 %69, label %70, label %61
70: ; preds = %61
ret i32 0
}