// File: matteotiziano[P]simple-wavelet/wavelet.cpp
// Function: Wavelet<double>::Appcoef(Decomposition2D<double> const&, unsigned long, MatrixSize const&) const
Matrix<T> Wavelet<T>::Appcoef(const Decomposition2D<T>& decomposition, size_t level,
                              const MatrixSize& size_rec) const {
  Matrix<T> a = decomposition.GetAppcoef();
  for (size_t k = decomposition.NumLevels(); k != level; k--) {
    // Select size of reconstruction from any subband at the next highest level
    // We arbitrarily use the horizontal subband. If there is no next highest
    // level, then we use the size_rec argument.
    const MatrixSize s = (k != 1) ? decomposition.GetDetcoef(kHorizontalSubband, k - 2).Size() : size_rec;
    const Matrix<T>& hk = decomposition.GetDetcoef(kHorizontalSubband, k - 1);
    const Matrix<T>& vk = decomposition.GetDetcoef(kVerticalSubband, k - 1);
    const Matrix<T>& dk = decomposition.GetDetcoef(kDiagonalSubband, k - 1);
    a = Idwt(a, hk, vk, dk, s);
  }
  return a;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0xa0(%rbp)
movq %rdi, %rax
movq %rax, -0xb0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xa8(%rbp)
movb $0x0, -0x29(%rbp)
movq -0x18(%rbp), %rdi
callq 0x5460
movq -0xa0(%rbp), %rdi
movq %rax, %rsi
callq 0x3490
movq -0x18(%rbp), %rdi
callq 0x5400
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x20(%rbp), %rax
je 0x6a13
cmpq $0x1, -0x38(%rbp)
je 0x68fc
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rdx
addq $-0x2, %rdx
movl $0x2, %esi
callq 0x54c0
movq %rax, -0xb8(%rbp)
jmp 0x68c8
movq -0xb8(%rbp), %rdi
callq 0xca80
movq %rdx, -0xc8(%rbp)
movq %rax, -0xc0(%rbp)
jmp 0x68e4
movq -0xc8(%rbp), %rax
movq -0xc0(%rbp), %rcx
movq %rcx, -0x48(%rbp)
movq %rax, -0x40(%rbp)
jmp 0x690f
movq -0x28(%rbp), %rax
movq (%rax), %rcx
movq %rcx, -0x48(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rdx
decq %rdx
movl $0x2, %esi
callq 0x54c0
movq %rax, -0xd0(%rbp)
jmp 0x692d
movq -0xd0(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rdx
decq %rdx
movl $0x1, %esi
callq 0x54c0
movq %rax, -0xd8(%rbp)
jmp 0x6956
movq -0xd8(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rdx
decq %rdx
xorl %esi, %esi
callq 0x54c0
movq %rax, -0xe0(%rbp)
jmp 0x697c
movq -0xa0(%rbp), %rdx
movq -0xa8(%rbp), %rsi
movq -0xe0(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x60(%rbp), %rcx
movq -0x68(%rbp), %r8
movq -0x70(%rbp), %r9
movq %rsp, %rax
leaq -0x48(%rbp), %rdi
movq %rdi, (%rax)
leaq -0x98(%rbp), %rdi
callq 0x6f50
jmp 0x69b9
movq -0xa0(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x5790
jmp 0x69ce
leaq -0x98(%rbp), %rdi
callq 0xca20
movq -0x38(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x6894
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x6a39
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x98(%rbp), %rdi
callq 0xca20
jmp 0x6a39
movb $0x1, -0x29(%rbp)
testb $0x1, -0x29(%rbp)
jne 0x6a29
movq -0xa0(%rbp), %rdi
callq 0xca20
movq -0xb0(%rbp), %rax
addq $0xf0, %rsp
popq %rbp
retq
movq -0xa0(%rbp), %rdi
callq 0xca20
movq -0x50(%rbp), %rdi
callq 0x2350
nop