// File: Manca[P]algorithms2/./assignment3.hpp
// Function: assignment3::knapsack_1::knapsack(std::vector<int, std::allocator<int>> const&, std::vector<int, std::allocator<int>> const&, int)
int knapsack(const std::vector<int>& values, const std::vector<int>& weights, int W)
        {
            assert(values.size() == weights.size());    // values have to have coresponding weights
            size_t n = values.size();

            // define and initialize resulting matrix (rows are integral weights up to W (inclusive), so 0,1,2,3...,W, columns are items up to n (inclusive))
            std::vector<std::vector<int>> A(W+1, std::vector<int>(n+1));

            for (size_t i = 1; i <= values.size(); i++)
            {
                for (int x = 0; x <= W; x++)
                {
                    if (weights[i-1] > x)
                        A[x][i] = A[x][i - 1];
                    else
                        A[x][i] = std::max(A[x][i - 1], A[x - weights[i-1]][i - 1] + values[i-1]);
                }
            }

            return A[W][n]; // bottom right cell contains optimal value
        }

// Assembly:
subq $0xe8, %rsp
movq %rdi, 0xe0(%rsp)
movq %rsi, 0xd8(%rsp)
movl %edx, 0xd4(%rsp)
movq 0xe0(%rsp), %rdi
callq 0x102a0
movq %rax, 0x68(%rsp)
movq 0xd8(%rsp), %rdi
callq 0x102a0
movq %rax, %rcx
movq 0x68(%rsp), %rax
cmpq %rcx, %rax
jne 0x749c
jmp 0x74bb
leaq 0x29056(%rip), %rdi     # 0x304f9
leaq 0x2906f(%rip), %rsi     # 0x30519
movl $0x52, %edx
leaq 0x29075(%rip), %rcx     # 0x3052b
callq 0x3200
movq 0xe0(%rsp), %rdi
callq 0x102a0
movq %rax, 0xc8(%rsp)
movl 0xd4(%rsp), %eax
incl %eax
cltq
movq %rax, 0x50(%rsp)
movq 0xc8(%rsp), %rax
incq %rax
movq %rax, 0x58(%rsp)
leaq 0x97(%rsp), %rdi
movq %rdi, 0x60(%rsp)
callq 0x101e0
movq 0x58(%rsp), %rsi
movq 0x60(%rsp), %rdx
leaq 0x98(%rsp), %rdi
callq 0x115c0
jmp 0x751b
leaq 0x83(%rsp), %rdi
movq %rdi, 0x48(%rsp)
callq 0x11640
movq 0x50(%rsp), %rsi
movq 0x48(%rsp), %rcx
leaq 0xb0(%rsp), %rdi
leaq 0x98(%rsp), %rdx
callq 0x11650
jmp 0x754e
leaq 0x83(%rsp), %rdi
callq 0x116d0
leaq 0x98(%rsp), %rdi
callq 0x107c0
leaq 0x97(%rsp), %rdi
callq 0x10280
movq $0x1, 0x78(%rsp)
movq 0x78(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0xe0(%rsp), %rdi
callq 0x102a0
movq %rax, %rcx
movq 0x40(%rsp), %rax
cmpq %rcx, %rax
ja 0x77b7
movl $0x0, 0x74(%rsp)
movl 0x74(%rsp), %eax
cmpl 0xd4(%rsp), %eax
jg 0x77a2
movq 0xd8(%rsp), %rdi
movq 0x78(%rsp), %rsi
subq $0x1, %rsi
callq 0x116e0
movl (%rax), %eax
cmpl 0x74(%rsp), %eax
jle 0x768a
movslq 0x74(%rsp), %rsi
leaq 0xb0(%rsp), %rdi
callq 0x11700
movq %rax, %rdi
movq 0x78(%rsp), %rsi
subq $0x1, %rsi
callq 0x11720
movl (%rax), %eax
movl %eax, 0x3c(%rsp)
movslq 0x74(%rsp), %rsi
leaq 0xb0(%rsp), %rdi
callq 0x11700
movq %rax, %rdi
movq 0x78(%rsp), %rsi
callq 0x11720
movl 0x3c(%rsp), %ecx
movl %ecx, (%rax)
jmp 0x7790
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x88(%rsp)
movl %eax, 0x84(%rsp)
jmp 0x7678
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x88(%rsp)
movl %eax, 0x84(%rsp)
leaq 0x83(%rsp), %rdi
callq 0x116d0
leaq 0x98(%rsp), %rdi
callq 0x107c0
leaq 0x97(%rsp), %rdi
callq 0x10280
jmp 0x77fb
movslq 0x74(%rsp), %rsi
leaq 0xb0(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x11700
movq %rax, %rdi
movq 0x78(%rsp), %rsi
decq %rsi
callq 0x11720
movq %rax, 0x20(%rsp)
movl 0x74(%rsp), %eax
movl %eax, 0x1c(%rsp)
movq 0xd8(%rsp), %rdi
movq 0x78(%rsp), %rsi
decq %rsi
callq 0x116e0
movq 0x10(%rsp), %rdi
movq %rax, %rcx
movl 0x1c(%rsp), %eax
movl (%rcx), %ecx
subl %ecx, %eax
movslq %eax, %rsi
callq 0x11700
movq %rax, %rdi
movq 0x78(%rsp), %rsi
decq %rsi
callq 0x11720
movl (%rax), %eax
movl %eax, 0x2c(%rsp)
movq 0xe0(%rsp), %rdi
movq 0x78(%rsp), %rsi
decq %rsi
callq 0x116e0
movq 0x20(%rsp), %rdi
movq %rax, %rcx
movl 0x2c(%rsp), %eax
movl (%rcx), %ecx
addl %ecx, %eax
movl %eax, 0x70(%rsp)
leaq 0x70(%rsp), %rsi
callq 0x11740
movq %rax, 0x30(%rsp)
jmp 0x773b
movq 0x30(%rsp), %rax
movl (%rax), %eax
movl %eax, 0xc(%rsp)
movslq 0x74(%rsp), %rsi
leaq 0xb0(%rsp), %rdi
callq 0x11700
movq %rax, %rdi
movq 0x78(%rsp), %rsi
callq 0x11720
movl 0xc(%rsp), %ecx
movl %ecx, (%rax)
jmp 0x7790
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x88(%rsp)
movl %eax, 0x84(%rsp)
leaq 0xb0(%rsp), %rdi
callq 0x11780
jmp 0x77fb
jmp 0x7792
movl 0x74(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x74(%rsp)
jmp 0x75ae
jmp 0x77a4
movq 0x78(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x78(%rsp)
jmp 0x757e
movslq 0xd4(%rsp), %rsi
leaq 0xb0(%rsp), %rdi
callq 0x11700
movq %rax, %rdi
movq 0xc8(%rsp), %rsi
callq 0x11720
movl (%rax), %eax
movl %eax, 0x8(%rsp)
leaq 0xb0(%rsp), %rdi
callq 0x11780
movl 0x8(%rsp), %eax
addq $0xe8, %rsp
retq
movq 0x88(%rsp), %rdi
callq 0x3460
nopl (%rax,%rax)