// File: matteotiziano[P]simple-wavelet/wavelet.cpp
// Function: Wavelet<double>::Wextend(std::vector<double, std::allocator<double>> const&, unsigned long) const
std::vector<T> Wavelet<T>::Wextend(const std::vector<T>& x, size_t lenEXT) const {
  std::vector<T> temp = x;
  // Add extra sample if signal is odd
  if (x.size() % 2 == 1) {
    temp.push_back(temp.back());
  }
  // Handle cases when x is shorter than lenEXT
  const size_t rep = lenEXT / temp.size(); // (size_t)std::floor(lenEXT/temp.size());
  const size_t len = lenEXT % temp.size();
  std::vector<T> y;
  y.reserve(2 * (len + rep * temp.size()) + temp.size());
  // Copy last len elements at the beginning
  y.insert(y.begin(), temp.end() - len, temp.end());
  for (size_t k = 0; k < 2 * rep + 1; k++) {
    y.insert(y.end(), temp.begin(), temp.end());
  }
  // Copy first len elements at the end
  y.insert(y.end(), temp.begin(), temp.begin() + len);
  return y;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x170, %rsp            # imm = 0x170
movq %rdi, -0x100(%rbp)
movq %rdi, %rax
movq %rax, -0xf8(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x18(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x3340
movq -0x18(%rbp), %rdi
callq 0x31e0
andq $0x1, %rax
cmpq $0x1, %rax
jne 0x7b10
leaq -0x38(%rbp), %rdi
movq %rdi, -0x108(%rbp)
callq 0x8790
movq -0x108(%rbp), %rdi
movq %rax, %rsi
callq 0x86d0
jmp 0x7afd
jmp 0x7b10
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x7e21
movq -0x20(%rbp), %rax
movq %rax, -0x140(%rbp)
leaq -0x38(%rbp), %rdi
movq %rdi, -0x120(%rbp)
callq 0x31e0
movq -0x120(%rbp), %rdi
movq %rax, %rcx
movq -0x140(%rbp), %rax
xorl %edx, %edx
movq %rdx, -0x138(%rbp)
divq %rcx
movq %rax, -0x50(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x130(%rbp)
callq 0x31e0
movq -0x138(%rbp), %rdx
movq -0x100(%rbp), %rdi
movq %rax, %rcx
movq -0x130(%rbp), %rax
divq %rcx
movq %rdx, -0x58(%rbp)
movb $0x0, -0x59(%rbp)
callq 0x5970
movq -0x120(%rbp), %rdi
movq -0x58(%rbp), %rax
movq %rax, -0x118(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x128(%rbp)
callq 0x31e0
movq -0x128(%rbp), %rcx
movq -0x120(%rbp), %rdi
movq %rax, %rdx
movq -0x118(%rbp), %rax
imulq %rdx, %rcx
addq %rcx, %rax
movq %rax, -0x110(%rbp)
callq 0x31e0
movq -0x110(%rbp), %rcx
movq -0x100(%rbp), %rdi
leaq (%rax,%rcx,2), %rsi
callq 0x85d0
jmp 0x7bea
movq -0x100(%rbp), %rdi
callq 0x45b0
movq %rax, -0x70(%rbp)
leaq -0x68(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x82e0
leaq -0x38(%rbp), %rdi
movq %rdi, -0x150(%rbp)
callq 0x45e0
movq %rax, -0x80(%rbp)
movq -0x58(%rbp), %rsi
leaq -0x80(%rbp), %rdi
callq 0x8360
movq -0x150(%rbp), %rdi
movq %rax, -0x78(%rbp)
callq 0x45e0
movq -0x100(%rbp), %rdi
movq %rax, -0x88(%rbp)
movq -0x68(%rbp), %rsi
movq -0x78(%rbp), %rdx
movq -0x88(%rbp), %rcx
callq 0x87d0
movq %rax, -0x148(%rbp)
jmp 0x7c63
movq -0x148(%rbp), %rax
movq %rax, -0x90(%rbp)
movq $0x0, -0x98(%rbp)
movq -0x98(%rbp), %rax
movq -0x50(%rbp), %rcx
shlq %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jae 0x7d53
movq -0x100(%rbp), %rdi
callq 0x45e0
movq %rax, -0xa8(%rbp)
leaq -0xa0(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x82e0
leaq -0x38(%rbp), %rdi
movq %rdi, -0x160(%rbp)
callq 0x45b0
movq -0x160(%rbp), %rdi
movq %rax, -0xb0(%rbp)
callq 0x45e0
movq -0x100(%rbp), %rdi
movq %rax, -0xb8(%rbp)
movq -0xa0(%rbp), %rsi
movq -0xb0(%rbp), %rdx
movq -0xb8(%rbp), %rcx
callq 0x87d0
movq %rax, -0x158(%rbp)
jmp 0x7d11
movq -0x158(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0x98(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x98(%rbp)
jmp 0x7c7c
movq -0x100(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
callq 0x3430
jmp 0x7e21
movq -0x100(%rbp), %rdi
callq 0x45e0
movq %rax, -0xd0(%rbp)
leaq -0xc8(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x82e0
leaq -0x38(%rbp), %rdi
movq %rdi, -0x170(%rbp)
callq 0x45b0
movq -0x170(%rbp), %rdi
movq %rax, -0xd8(%rbp)
callq 0x45b0
movq %rax, -0xe8(%rbp)
movq -0x58(%rbp), %rsi
leaq -0xe8(%rbp), %rdi
callq 0x8320
movq -0x100(%rbp), %rdi
movq %rax, -0xe0(%rbp)
movq -0xc8(%rbp), %rsi
movq -0xd8(%rbp), %rdx
movq -0xe0(%rbp), %rcx
callq 0x87d0
movq %rax, -0x168(%rbp)
jmp 0x7de4
movq -0x168(%rbp), %rax
movq %rax, -0xf0(%rbp)
movb $0x1, -0x59(%rbp)
testb $0x1, -0x59(%rbp)
jne 0x7e08
movq -0x100(%rbp), %rdi
callq 0x3430
leaq -0x38(%rbp), %rdi
callq 0x3430
movq -0xf8(%rbp), %rax
addq $0x170, %rsp            # imm = 0x170
popq %rbp
retq
leaq -0x38(%rbp), %rdi
callq 0x3430
movq -0x40(%rbp), %rdi
callq 0x2350
nopw %cs:(%rax,%rax)
nopl (%rax)