void spcut(double *arrayIn, double *arrayOut, int trunc, int *waves) {
  int n, m;
  for (n = 0; n <= trunc; n++) {
    for (m = n; m <= trunc; m++) {
      if (waves[m]) {
        *arrayOut++ = *arrayIn++;
        *arrayOut++ = *arrayIn++;
      } else {
        *arrayOut++ = 0.0;
        *arrayOut++ = 0.0;
        arrayIn++;
        arrayIn++;
      }
    }
  }
}


x86 assembly (clang, -O0):
<spcut>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     1205 <spcut+0x105>
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     11f2 <spcut+0xf2>
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
je     119b <spcut+0x9b>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x8(%rbp)
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
movsd  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x8(%rbp)
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
movsd  %xmm0,(%rax)
jmp    11df <spcut+0xdf>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x8(%rbp)
jmp    11e4 <spcut+0xe4>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    112c <spcut+0x2c>
jmp    11f7 <spcut+0xf7>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    111a <spcut+0x1a>
pop    %rbp
ret

x86 assembly (clang, -O2):
<spcut>:
test   %edx,%edx
js     1165 <spcut+0x65>
add    $0x1,%edx
xor    %r8d,%r8d
mov    %rdx,%r9
jmp    1121 <spcut+0x21>
nop
add    $0x1,%r8
add    $0x4,%rcx
add    $0xffffffffffffffff,%r9
cmp    %rdx,%r8
je     1165 <spcut+0x65>
xor    %eax,%eax
jmp    1150 <spcut+0x50>
cs nopw 0x0(%rax,%rax,1)
nop
movq   $0x0,(%rsi)
xorps  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsi)
add    $0x10,%rsi
add    $0x10,%rdi
add    $0x1,%rax
cmp    %rax,%r9
je     1110 <spcut+0x10>
cmpl   $0x0,(%rcx,%rax,4)
je     1130 <spcut+0x30>
movsd  (%rdi),%xmm0
movsd  %xmm0,(%rsi)
movsd  0x8(%rdi),%xmm0
jmp    113a <spcut+0x3a>
ret

LLVM IR (-O0):
define void @spcut(double* %0, double* %1, i32 %2, i32* %3) {
%5 = alloca double*
%6 = alloca double*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
store double* %0, double** %5
store double* %1, double** %6
store i32 %2, i32* %7
store i32* %3, i32** %8
store i32 0, i32* %9
br label %11
11: ; preds = %53, %4
%12 = load i32, i32* %9
%13 = load i32, i32* %7
%14 = icmp sle i32 %12, %13
br i1 %14, label %15, label %56
15: ; preds = %11
%16 = load i32, i32* %9
store i32 %16, i32* %10
br label %17
17: ; preds = %49, %15
%18 = load i32, i32* %10
%19 = load i32, i32* %7
%20 = icmp sle i32 %18, %19
br i1 %20, label %21, label %52
21: ; preds = %17
%22 = load i32*, i32** %8
%23 = load i32, i32* %10
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
%26 = load i32, i32* %25
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %39
28: ; preds = %21
%29 = load double*, double** %5
%30 = getelementptr inbounds double, double* %29, i32 1
store double* %30, double** %5
%31 = load double, double* %29
%32 = load double*, double** %6
%33 = getelementptr inbounds double, double* %32, i32 1
store double* %33, double** %6
store double %31, double* %32
%34 = load double*, double** %5
%35 = getelementptr inbounds double, double* %34, i32 1
store double* %35, double** %5
%36 = load double, double* %34
%37 = load double*, double** %6
%38 = getelementptr inbounds double, double* %37, i32 1
store double* %38, double** %6
store double %36, double* %37
br label %48
39: ; preds = %21
%40 = load double*, double** %6
%41 = getelementptr inbounds double, double* %40, i32 1
store double* %41, double** %6
store double 0.000000e+00, double* %40
%42 = load double*, double** %6
%43 = getelementptr inbounds double, double* %42, i32 1
store double* %43, double** %6
store double 0.000000e+00, double* %42
%44 = load double*, double** %5
%45 = getelementptr inbounds double, double* %44, i32 1
store double* %45, double** %5
%46 = load double*, double** %5
%47 = getelementptr inbounds double, double* %46, i32 1
store double* %47, double** %5
br label %48
48: ; preds = %39, %28
br label %49
49: ; preds = %48
%50 = load i32, i32* %10
%51 = add nsw i32 %50, 1
store i32 %51, i32* %10
br label %17
52: ; preds = %17
br label %53
53: ; preds = %52
%54 = load i32, i32* %9
%55 = add nsw i32 %54, 1
store i32 %55, i32* %9
br label %11
56: ; preds = %11
ret void
}

LLVM IR (-O2):
define void @spcut(double* nocapture %0, double* nocapture writeonly %1, i32 %2, i32* nocapture %3) {
%5 = icmp slt i32 %2, 0
br i1 %5, label %35, label %6
6: ; preds = %4
%7 = add nuw i32 %2, 1
%8 = zext i32 %7 to i64
br label %9
9: ; preds = %32, %6
%10 = phi i64 [ 0, %6 ], [ %33, %32 ]
%11 = phi double* [ %0, %6 ], [ %29, %32 ]
%12 = phi double* [ %1, %6 ], [ %28, %32 ]
br label %13
13: ; preds = %9, %25
%14 = phi i64 [ %10, %9 ], [ %30, %25 ]
%15 = phi double* [ %11, %9 ], [ %29, %25 ]
%16 = phi double* [ %12, %9 ], [ %28, %25 ]
%17 = getelementptr inbounds i32, i32* %3, i64 %14
%18 = load i32, i32* %17
%19 = icmp eq i32 %18, 0
br i1 %19, label %24, label %20
20: ; preds = %13
%21 = getelementptr inbounds double, double* %15, i64 1
%22 = load double, double* %15
store double %22, double* %16
%23 = load double, double* %21
br label %25
24: ; preds = %13
store double 0.000000e+00, double* %16
br label %25
25: ; preds = %20, %24
%26 = phi double [ 0.000000e+00, %24 ], [ %23, %20 ]
%27 = getelementptr inbounds double, double* %16, i64 1
store double %26, double* %27
%28 = getelementptr inbounds double, double* %16, i64 2
%29 = getelementptr inbounds double, double* %15, i64 2
%30 = add nuw nsw i64 %14, 1
%31 = icmp eq i64 %30, %8
br i1 %31, label %32, label %13
32: ; preds = %25
%33 = add nuw nsw i64 %10, 1
%34 = icmp eq i64 %33, %8
br i1 %34, label %35, label %9
35: ; preds = %32, %4
ret void
}