// File: 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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movl $0x9, -0x1c(%rbp)
movl -0xc(%rbp), %eax
addl $0x12, %eax
cltq
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x1030
movq %rax, -0x28(%rbp)
movl -0xc(%rbp), %eax
addl $0x12, %eax
cltq
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x1030
movq %rax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
cmpl $0x9, -0x34(%rbp)
jge 0x6c67
movq -0x8(%rbp), %rax
movsd (%rax), %xmm0
movq -0x8(%rbp), %rax
movl $0x9, %ecx
subl -0x34(%rbp), %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
addsd %xmm0, %xmm0
addsd %xmm1, %xmm0
movq -0x28(%rbp), %rax
movslq -0x34(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x6c0e
movl $0x9, -0x38(%rbp)
movl -0x38(%rbp), %eax
movl -0xc(%rbp), %ecx
addl $0x9, %ecx
cmpl %ecx, %eax
jge 0x6ca5
movq -0x8(%rbp), %rax
movl -0x38(%rbp), %ecx
subl $0x9, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x28(%rbp), %rax
movslq -0x38(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x6c6e
movl -0xc(%rbp), %eax
addl $0x9, %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movl -0xc(%rbp), %ecx
addl $0x12, %ecx
cmpl %ecx, %eax
jge 0x6d23
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %ecx
subl $0x2, %ecx
movl -0x3c(%rbp), %edx
movl -0xc(%rbp), %esi
addl $0x9, %esi
subl %esi, %edx
subl %edx, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
addsd %xmm0, %xmm0
addsd %xmm1, %xmm0
movq -0x28(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x6cae
movq -0x28(%rbp), %rdi
movl -0xc(%rbp), %esi
addl $0x12, %esi
movl -0x10(%rbp), %edx
movq -0x30(%rbp), %rcx
callq 0x6e80
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
movl -0xc(%rbp), %ecx
addl $0x12, %ecx
cmpl %ecx, %eax
jge 0x6d7d
movq -0x30(%rbp), %rax
movl -0xc(%rbp), %ecx
addl $0x12, %ecx
subl -0x40(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x28(%rbp), %rax
movslq -0x40(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x6d40
movq -0x28(%rbp), %rdi
movl -0xc(%rbp), %esi
addl $0x12, %esi
movl -0x10(%rbp), %edx
movq -0x30(%rbp), %rcx
callq 0x6e80
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
movl -0xc(%rbp), %ecx
addl $0x12, %ecx
cmpl %ecx, %eax
jge 0x6dd7
movq -0x30(%rbp), %rax
movl -0xc(%rbp), %ecx
addl $0x12, %ecx
subl -0x44(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x28(%rbp), %rax
movslq -0x44(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x6d9a
movl -0xc(%rbp), %eax
cltd
idivl -0x10(%rbp)
addl $0x1, %eax
movl %eax, -0x48(%rbp)
movl -0x10(%rbp), %eax
movl -0x10(%rbp), %ecx
imull -0x48(%rbp), %ecx
subl %ecx, %eax
addl -0xc(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl $0x0, -0x50(%rbp)
movl -0x4c(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
movl -0xc(%rbp), %ecx
addl $0x9, %ecx
cmpl %ecx, %eax
jge 0x6e47
movq -0x28(%rbp), %rax
movl -0x54(%rbp), %ecx
addl $0x9, %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x18(%rbp), %rax
movl -0x50(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x50(%rbp)
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x10(%rbp), %eax
addl -0x54(%rbp), %eax
movl %eax, -0x54(%rbp)
jmp 0x6e03
movq -0x28(%rbp), %rax
movq %rax, -0x60(%rbp)
cmpq $0x0, %rax
je 0x6e5e
movq -0x60(%rbp), %rdi
callq 0x1110
movq -0x30(%rbp), %rax
movq %rax, -0x68(%rbp)
cmpq $0x0, %rax
je 0x6e75
movq -0x68(%rbp), %rdi
callq 0x1110
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)