// File: /workspace/github_cpp_makefile_star2_O1/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, 0x14(%rsp)
movl %esi, %r12d
movq %rdi, %rbp
leal 0x12(%r12), %eax
movl %eax, 0x10(%rsp)
movslq %eax, %r13
leaq (,%r13,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 0x4380
leal 0x9(%r12), %ecx
testl %r12d, %r12d
movl %ecx, 0xc(%rsp)
jle 0x43cb
movq %r14, %rdi
addq $0x48, %rdi
cmpl $0xb, %ecx
movl $0xa, %edx
cmovgel %ecx, %edx
addl $-0x9, %edx
shlq $0x3, %rdx
movq %rbp, %rsi
callq 0x10b0
movl 0xc(%rsp), %ecx
movslq %r12d, %rax
movsd -0x8(%rbp,%rax,8), %xmm0
leal -0x2(%r12), %eax
movslq %ecx, %rcx
addsd %xmm0, %xmm0
cltq
movapd %xmm0, %xmm1
subsd (%rbp,%rax,8), %xmm1
movsd %xmm1, (%r14,%rcx,8)
incq %rcx
decl %eax
cmpq %r13, %rcx
jl 0x43e0
movq %r14, %rdi
movl 0x10(%rsp), %r13d
movl %r13d, %esi
movl 0x14(%rsp), %ebp
movl %ebp, %edx
movq %r15, %rcx
callq 0x44d7
cmpl $-0x11, %r12d
jl 0x4448
cmpl $0x2, %r13d
movl $0x1, %eax
cmovgel %r13d, %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 0x442f
movq %r14, %rdi
movl %r13d, %esi
movl %ebp, %edx
movq %r15, %rcx
callq 0x44d7
cmpl $-0x11, %r12d
jl 0x448b
cmpl $0x2, %r13d
movl $0x1, %eax
cmovgel %r13d, %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 0x4472
movl %r12d, %eax
cltd
idivl %ebp
movl 0xc(%rsp), %esi
cmpl %esi, %edx
jge 0x44b9
movslq %edx, %rax
movslq %ebp, %rcx
movslq %esi, %rdx
movsd 0x40(%r14,%rax,8), %xmm0
movsd %xmm0, (%rbx)
addq %rcx, %rax
addq $0x8, %rbx
cmpq %rdx, %rax
jl 0x44a2
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