// File: /workspace/github_cpp_makefile_star2_O3/ahnafraihan[P]BestFirstSearch/main.cpp
// Function: main
int main(int argc, const char * argv[]) {
    output = argv[2]; //save name of desired output file
    int n = 0; //initialize number of items n
    int W = 0; //initialize max weight W
    int maxprofit = 0; //initialize maximum profit to 0
    ifstream infile (argv[1]); //create an ifstream to parse our input file
    string line; //string to hold each line
    string buf; //string to hold each number
    
    if (getline(infile, line)) { //parse input file by commas
        stringstream s (line);
        if (getline(s, buf, ',')) { //identify number of items n
            stringstream ss (buf);
            ss >> n;
        }
        if (getline(s, buf, ',')) { //identify maximum weight W
            stringstream ss (buf);
            ss >> W;
        }
    }
    
    int p[n]; //initialize array of profits of size n
    int w[n]; //initialize array of weights of size n
    
    int count = 0; // count variable used to identify current line of input
    
    while (getline (infile, line)) { //parse input again, this time to identify individual items
        stringstream s (line);
        if (getline(s,buf, ',')) { //identify weights of items
            int in;
            stringstream ss (buf);
            ss >> in;
            w[count] = in;
        }
        if (getline(s, buf, ',')) { //identify profits of items
            int in;
            stringstream ss (buf);
            ss >> in;
            p[count] = in;
        }
        count ++;
    }
    
    sorts s[n]; //create array of sorts of size n items
    
    for (int i = 0; i < n; i++) { //populate array of sorts with respective price/weight's and index's
        s[i].pw = (float)p[i]/(float)w[i];
        s[i].index = i;
    }
    
    sort (s, s + n, comparePW); //sort array of sorts by pw
    
    int pSorted[n]; //create array to hold sorted profits
    int wSorted[n]; //create array to hold sorted weights
    
    for (int i = 0; i < n; i++) { //populate sorted profit and weight arrays with knowedge of p/w order from sorts
        pSorted[i] = p[s[i].index];
        wSorted[i] = w[s[i].index];
    }
    
    //call our knapsack 3 function
    knapsack3(n, pSorted, wSorted, W, maxprofit);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x598, %rsp            # imm = 0x598
movq %rsi, %rbx
movq 0x10(%rsi), %r14
movq 0x3d3e(%rip), %r15      # 0x6160
leaq 0x3d2f(%rip), %r12      # 0x6158
movq %r14, %rdi
callq 0x20a0
xorl %r13d, %r13d
movq %r12, %rdi
xorl %esi, %esi
movq %r15, %rdx
movq %r14, %rcx
movq %rax, %r8
callq 0x21a0
movl %r13d, -0x2c(%rbp)
movl %r13d, -0x38(%rbp)
movq 0x8(%rbx), %rsi
leaq -0x5b8(%rbp), %rbx
movq %rbx, %rdi
movl $0x8, %edx
callq 0x2210
leaq -0x88(%rbp), %rax
movq %rax, -0x10(%rax)
movq %r13, -0x8(%rax)
movb %r13b, (%rax)
leaq -0x68(%rbp), %rax
movq %rax, -0x10(%rax)
movq %r13, -0x8(%rax)
movb %r13b, (%rax)
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2120
movsbl %al, %edx
leaq -0x5b8(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x2220
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x25c9
leaq -0x3b0(%rbp), %rdi
leaq -0x98(%rbp), %rsi
movl $0x18, %edx
callq 0x21b0
leaq -0x3b0(%rbp), %rdi
leaq -0x78(%rbp), %rsi
movl $0x2c, %edx
callq 0x2220
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2543
leaq -0x228(%rbp), %rdi
leaq -0x78(%rbp), %rsi
movl $0x18, %edx
callq 0x21b0
leaq -0x228(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x20c0
movq 0x3a8d(%rip), %rsi      # 0x5fb8
leaq -0x228(%rbp), %rdi
callq 0x20e0
leaq -0x1a8(%rbp), %rdi
callq 0x2070
leaq -0x3b0(%rbp), %rdi
leaq -0x78(%rbp), %rsi
movl $0x2c, %edx
callq 0x2220
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x25aa
leaq -0x228(%rbp), %rdi
leaq -0x78(%rbp), %rsi
movl $0x18, %edx
callq 0x21b0
leaq -0x228(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x20c0
movq 0x3a26(%rip), %rsi      # 0x5fb8
leaq -0x228(%rbp), %rdi
callq 0x20e0
leaq -0x1a8(%rbp), %rdi
callq 0x2070
movq 0x3a07(%rip), %rsi      # 0x5fb8
leaq -0x3b0(%rbp), %rdi
callq 0x20e0
leaq -0x330(%rbp), %rdi
callq 0x2070
movq %rsp, -0xa0(%rbp)
movl -0x2c(%rbp), %eax
movq %rsp, %rcx
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
subq %rax, %rcx
movq %rcx, -0x50(%rbp)
movq %rcx, %rsp
movl -0x2c(%rbp), %eax
movq %rsp, %rcx
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
subq %rax, %rcx
movq %rcx, -0x48(%rbp)
movq %rcx, %rsp
movl $0x80, %eax
leaq -0x228(%rbp), %r12
leaq (%r12,%rax), %rcx
movq %rcx, -0x40(%rbp)
leaq -0x3b0(%rbp), %r13
addq %r13, %rax
movq %rax, -0x58(%rbp)
xorl %r14d, %r14d
leaq -0x78(%rbp), %r15
movq -0x5b8(%rbp), %rax
movq -0x18(%rax), %rdi
leaq -0x5b8(%rbp), %rbx
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2120
movsbl %al, %edx
movq %rbx, %rdi
leaq -0x98(%rbp), %rsi
callq 0x2220
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2763
movq %r13, %rdi
leaq -0x98(%rbp), %rsi
movl $0x18, %edx
callq 0x21b0
movq %r13, %rdi
movq %r15, %rsi
movl $0x2c, %edx
callq 0x2220
movq -0x50(%rbp), %rbx
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x26e9
movq %r12, %rdi
movq %r15, %rsi
movl $0x18, %edx
callq 0x21b0
movq %r12, %rdi
leaq -0x34(%rbp), %rsi
callq 0x20c0
movl -0x34(%rbp), %eax
movq -0x48(%rbp), %rcx
movl %eax, (%rcx,%r14)
movq %r12, %rdi
movq 0x38dd(%rip), %rsi      # 0x5fb8
callq 0x20e0
movq -0x40(%rbp), %rdi
callq 0x2070
movq %r13, %rdi
movq %r15, %rsi
movl $0x2c, %edx
callq 0x2220
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2742
movq %r12, %rdi
movq %r15, %rsi
movl $0x18, %edx
callq 0x21b0
movq %r12, %rdi
leaq -0x34(%rbp), %rsi
callq 0x20c0
movl -0x34(%rbp), %eax
movl %eax, (%rbx,%r14)
movq %r12, %rdi
movq 0x3884(%rip), %rsi      # 0x5fb8
callq 0x20e0
movq -0x40(%rbp), %rdi
callq 0x2070
movq %r13, %rdi
movq 0x386c(%rip), %rsi      # 0x5fb8
callq 0x20e0
movq -0x58(%rbp), %rdi
callq 0x2070
addq $0x4, %r14
jmp 0x2631
movslq -0x2c(%rbp), %rax
movl %eax, %ecx
movq %rsp, %rbx
leaq 0xf(,%rcx,8), %rdx
andq $-0x10, %rdx
subq %rdx, %rbx
movq %rbx, %rsp
testq %rax, %rax
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdi
jle 0x27b2
xorl %edx, %edx
xorps %xmm0, %xmm0
cvtsi2ssl (%rsi,%rdx,4), %xmm0
xorps %xmm1, %xmm1
cvtsi2ssl (%rdi,%rdx,4), %xmm1
divss %xmm1, %xmm0
movss %xmm0, (%rbx,%rdx,8)
movl %edx, 0x4(%rbx,%rdx,8)
incq %rdx
cmpq %rdx, %rcx
jne 0x278d
testq %rcx, %rcx
je 0x283d
leaq (%rbx,%rax,8), %r15
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
leaq -0x3e7(%rip), %rcx      # 0x23ec
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3451
leaq -0x3f9(%rip), %rdx      # 0x23ec
movq %rbx, %rdi
movq %r15, %rsi
callq 0x357a
movl -0x2c(%rbp), %edi
movq %rsp, %rsi
leaq 0xf(,%rdi,4), %rax
andq $-0x10, %rax
subq %rax, %rsi
movq %rsi, %rsp
movq %rsp, %rdx
subq %rax, %rdx
movq %rdx, %rsp
testl %edi, %edi
jle 0x2846
xorl %eax, %eax
movq -0x50(%rbp), %r9
movq -0x48(%rbp), %r10
movslq 0x4(%rbx,%rax,8), %rcx
movl (%r9,%rcx,4), %r8d
movl %r8d, (%rsi,%rax,4)
movl (%r10,%rcx,4), %ecx
movl %ecx, (%rdx,%rax,4)
incq %rax
cmpq %rax, %rdi
jne 0x281f
jmp 0x2846
xorl %edi, %edi
leaq -0x30(%rbp), %rdx
movq %rdx, %rsi
movl -0x38(%rbp), %ecx
callq 0x2998
movq -0xa0(%rbp), %rsp
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
je 0x286e
movq -0x68(%rbp), %rsi
incq %rsi
callq 0x2140
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
cmpq %rax, %rdi
je 0x2890
movq -0x88(%rbp), %rsi
incq %rsi
callq 0x2140
leaq -0x5b8(%rbp), %rdi
callq 0x2050
xorl %eax, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x28b1
jmp 0x28d9
movq %rax, %rbx
movq 0x36fd(%rip), %rsi      # 0x5fb8
leaq -0x228(%rbp), %rdi
callq 0x20e0
leaq -0x1a8(%rbp), %rdi
callq 0x2070
jmp 0x28dc
jmp 0x28d9
jmp 0x2946
movq %rax, %rbx
movq 0x36d5(%rip), %rsi      # 0x5fb8
leaq -0x3b0(%rbp), %rdi
callq 0x20e0
leaq -0x330(%rbp), %rdi
jmp 0x293f
jmp 0x2946
jmp 0x2946
jmp 0x2900
jmp 0x2925
movq %rax, %rbx
movq 0x36ae(%rip), %rsi      # 0x5fb8
leaq -0x228(%rbp), %rdi
callq 0x20e0
movq -0x40(%rbp), %rdi
callq 0x2070
jmp 0x2928
jmp 0x2925
jmp 0x2946
movq %rax, %rbx
movq 0x3689(%rip), %rsi      # 0x5fb8
leaq -0x3b0(%rbp), %rdi
callq 0x20e0
movq -0x58(%rbp), %rdi
callq 0x2070
jmp 0x2949
movq %rax, %rbx
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
je 0x2962
movq -0x68(%rbp), %rsi
incq %rsi
callq 0x2140
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
cmpq %rax, %rdi
je 0x2984
movq -0x88(%rbp), %rsi
incq %rsi
callq 0x2140
leaq -0x5b8(%rbp), %rdi
callq 0x2050
movq %rbx, %rdi
callq 0x2200