// File: Manca[P]algorithms2/./assignment3.hpp
// Function: assignment3::knapsack_big::knapsack_rec_memoization(int, std::vector<int, std::allocator<int>>&, std::vector<int, std::allocator<int>>&, int)
int knapsack_rec_memoization(int n, std::vector<int>& values, std::vector<int>& weights, const int W)
        {
            if (saved.count(W) > 0)
            {
                for (auto el : saved[W])
                {
                    if (std::get<0>(el) == n)   // if we have item's value for the given W and item number, let's return it
                        return std::get<1>(el);
                }
            }
            int withLastItem = -1;
            int withoutLastItem = -1;
            if (n <= 0)
                return 0;
           
            if (W < weights[n-1]) // last item
                withLastItem = -1;
            else
            {
                withLastItem = values[n - 1] + knapsack_rec_memoization(n - 1, values, weights, W - weights[n - 1]);
            }
            withoutLastItem = knapsack_rec_memoization(n - 1, values, weights, W);
            saved[W].push_back(std::make_tuple(n, std::max(withLastItem, withoutLastItem)));
            return std::max(withLastItem, withoutLastItem);
        }

// Assembly:
subq $0x78, %rsp
movl %edi, 0x70(%rsp)
movq %rsi, 0x68(%rsp)
movq %rdx, 0x60(%rsp)
movl %ecx, 0x5c(%rsp)
leaq 0x3c6e3(%rip), %rdi     # 0x44290
leaq 0x5c(%rsp), %rsi
callq 0x11800
cmpq $0x0, %rax
jbe 0x7c53
leaq 0x3c6c8(%rip), %rdi     # 0x44290
leaq 0x5c(%rsp), %rsi
callq 0x11830
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rdi
callq 0x11860
movq %rax, 0x48(%rsp)
movq 0x50(%rsp), %rdi
callq 0x11890
movq %rax, 0x40(%rsp)
leaq 0x48(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x118c0
testb $0x1, %al
jne 0x7c0a
jmp 0x7c51
leaq 0x48(%rsp), %rdi
callq 0x11900
movq (%rax), %rax
movq %rax, 0x38(%rsp)
leaq 0x38(%rsp), %rdi
callq 0xfd10
movl (%rax), %eax
cmpl 0x70(%rsp), %eax
jne 0x7c43
leaq 0x38(%rsp), %rdi
callq 0xfd20
movl (%rax), %eax
movl %eax, 0x74(%rsp)
jmp 0x7d99
jmp 0x7c45
leaq 0x48(%rsp), %rdi
callq 0x11910
jmp 0x7bf5
jmp 0x7c53
movl $0xffffffff, 0x34(%rsp) # imm = 0xFFFFFFFF
movl $0xffffffff, 0x30(%rsp) # imm = 0xFFFFFFFF
cmpl $0x0, 0x70(%rsp)
jg 0x7c77
movl $0x0, 0x74(%rsp)
jmp 0x7d99
movl 0x5c(%rsp), %eax
movl %eax, 0x24(%rsp)
movq 0x60(%rsp), %rdi
movl 0x70(%rsp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x11720
movq %rax, %rcx
movl 0x24(%rsp), %eax
cmpl (%rcx), %eax
jge 0x7ca8
movl $0xffffffff, 0x34(%rsp) # imm = 0xFFFFFFFF
jmp 0x7d22
movq 0x68(%rsp), %rdi
movl 0x70(%rsp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x11720
movl (%rax), %eax
movl %eax, 0x20(%rsp)
movl 0x70(%rsp), %eax
subl $0x1, %eax
movl %eax, 0xc(%rsp)
movq 0x68(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x60(%rsp), %rax
movq %rax, 0x18(%rsp)
movl 0x5c(%rsp), %eax
movl %eax, 0x8(%rsp)
movq 0x60(%rsp), %rdi
movl 0x70(%rsp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x11720
movl 0x8(%rsp), %ecx
movl 0xc(%rsp), %edi
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
subl (%rax), %ecx
callq 0x7b90
movl %eax, %ecx
movl 0x20(%rsp), %eax
addl %ecx, %eax
movl %eax, 0x34(%rsp)
movl 0x70(%rsp), %edi
subl $0x1, %edi
movq 0x68(%rsp), %rsi
movq 0x60(%rsp), %rdx
movl 0x5c(%rsp), %ecx
callq 0x7b90
movl %eax, 0x30(%rsp)
leaq 0x3c549(%rip), %rdi     # 0x44290
leaq 0x5c(%rsp), %rsi
callq 0x11830
movq %rax, (%rsp)
leaq 0x34(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x11740
movq %rax, %rdx
leaq 0x28(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x11960
movq (%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x11930
leaq 0x34(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x11740
movl (%rax), %eax
movl %eax, 0x74(%rsp)
movl 0x74(%rsp), %eax
addq $0x78, %rsp
retq
nopw %cs:(%rax,%rax)