// File: /workspace/github_cpp_makefile_star2_O3/Sleepwalking[P]world-octave/matlabfunctions.cpp
// Function: decimate(double*, int, int, double*)
void decimate(double *x, int x_length, int r, double *y) {
  const int kNFact = 9;
  double *tmp1 = new double[x_length + kNFact * 2];
  double *tmp2 = new double[x_length + kNFact * 2];

  for (int i = 0; i < kNFact; ++i) tmp1[i] = 2 * x[0] - x[kNFact - i];
  for (int i = kNFact; i < kNFact + x_length; ++i) tmp1[i] = x[i - kNFact];
  for (int i = kNFact + x_length; i < 2 * kNFact + x_length; ++i)
    tmp1[i] = 2 * x[x_length - 1] - x[x_length - 2 - (i - (kNFact + x_length))];

  FilterForDecimate(tmp1, 2 * kNFact + x_length, r, tmp2);
  for (int i = 0; i < 2 * kNFact + x_length; ++i)
    tmp1[i] = tmp2[2 * kNFact + x_length - i - 1];
  FilterForDecimate(tmp1, 2 * kNFact + x_length, r, tmp2);
  for (int i = 0; i < 2 * kNFact + x_length; ++i)
    tmp1[i] = tmp2[2 * kNFact + x_length - i - 1];

  int nout = x_length / r + 1;
  int nbeg = r - r * nout + x_length;

  int count = 0;
  for (int i = nbeg; i < x_length + kNFact; i += r)
    y[count++] = tmp1[i + kNFact - 1];

  delete[] tmp1;
  delete[] tmp2;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %rbx
movl %edx, (%rsp)
movl %esi, %r12d
movq %rdi, %rbp
leal 0x12(%r12), %eax
movq %rax, 0x10(%rsp)
leaq (,%rax,8), %rax
cmpl $-0x12, %esi
movq $-0x1, %r15
cmovgeq %rax, %r15
movq %r15, %rdi
callq 0x1030
movq %rax, %r14
movq %r15, %rdi
callq 0x1030
movq %rax, %r15
movsd (%rbp), %xmm0
movl $0x48, %eax
addsd %xmm0, %xmm0
movq %r14, %rcx
movapd %xmm0, %xmm1
subsd (%rbp,%rax), %xmm1
movsd %xmm1, (%rcx)
addq $0x8, %rcx
addq $-0x8, %rax
jne 0x4928
leal 0x9(%r12), %r13d
testl %r12d, %r12d
jle 0x496d
movq %r14, %rdi
addq $0x48, %rdi
cmpl $0xb, %r13d
movl $0xa, %edx
cmovgel %r13d, %edx
addl $-0x9, %edx
shlq $0x3, %rdx
movq %rbp, %rsi
callq 0x10b0
movslq %r12d, %rax
movsd -0x8(%rbp,%rax,8), %xmm0
movq %r12, 0x8(%rsp)
leal -0x2(%r12), %eax
movl %r13d, 0x4(%rsp)
movslq %r13d, %r13
movq 0x10(%rsp), %rsi
movslq %esi, %rcx
addsd %xmm0, %xmm0
movq %r13, %rdx
cltq
movapd %xmm0, %xmm1
subsd (%rbp,%rax,8), %xmm1
movsd %xmm1, (%r14,%rdx,8)
incq %rdx
decl %eax
cmpq %rcx, %rdx
jl 0x4997
movq %r14, %rdi
movq %rsi, %rbp
movl (%rsp), %r12d
movl %r12d, %edx
movq %r15, %rcx
callq 0x4aa0
movq 0x8(%rsp), %rsi
cmpl $-0x12, %esi
jle 0x4a41
cmpl $0x2, %ebp
movl $0x1, %eax
cmovgel %ebp, %eax
leal 0x11(%rsi), %ecx
xorl %edx, %edx
movq %rsi, %r12
movslq %ecx, %rcx
movsd (%r15,%rcx,8), %xmm0
movsd %xmm0, (%r14,%rdx,8)
incq %rdx
decl %ecx
cmpq %rdx, %rax
jne 0x49e5
movq %r14, %rdi
movl %ebp, %esi
movl (%rsp), %edx
movq %r15, %rcx
callq 0x4aa0
cmpl $-0x11, %r12d
jl 0x4a56
cmpl $0x2, %ebp
movl $0x1, %eax
cmovgel %ebp, %eax
leal 0x11(%r12), %ecx
xorl %edx, %edx
movslq %ecx, %rcx
movsd (%r15,%rcx,8), %xmm0
movsd %xmm0, (%r14,%rdx,8)
incq %rdx
decl %ecx
cmpq %rdx, %rax
jne 0x4a26
jmp 0x4a56
movq %r14, %rdi
movl %ebp, %esi
movl %r12d, %edx
movq %r15, %rcx
callq 0x4aa0
movq 0x8(%rsp), %r12
movl %r12d, %eax
cltd
movl (%rsp), %ecx
idivl %ecx
cmpl 0x4(%rsp), %edx
jge 0x4a82
movslq %edx, %rax
movslq %ecx, %rcx
movsd 0x40(%r14,%rax,8), %xmm0
movsd %xmm0, (%rbx)
addq %rcx, %rax
addq $0x8, %rbx
cmpq %r13, %rax
jl 0x4a6b
movq %r14, %rdi
callq 0x1110
movq %r15, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1110