// File: /workspace/github_cpp_makefile_star2_O1/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, -0x34(%rbp)
movq 0x8(%rbx), %rsi
leaq -0x5b8(%rbp), %rbx
movq %rbx, %rdi
movl $0x8, %edx
callq 0x2210
leaq -0x80(%rbp), %rax
movq %rax, -0x10(%rax)
movq %r13, -0x8(%rax)
movb %r13b, (%rax)
leaq -0x60(%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 -0x90(%rbp), %rsi
callq 0x2220
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x25c6
leaq -0x3b0(%rbp), %rdi
leaq -0x90(%rbp), %rsi
movl $0x18, %edx
callq 0x21b0
leaq -0x3b0(%rbp), %rdi
leaq -0x70(%rbp), %rsi
movl $0x2c, %edx
callq 0x2220
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2540
leaq -0x228(%rbp), %rdi
leaq -0x70(%rbp), %rsi
movl $0x18, %edx
callq 0x21b0
leaq -0x228(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x20c0
movq 0x3a90(%rip), %rsi      # 0x5fb8
leaq -0x228(%rbp), %rdi
callq 0x20e0
leaq -0x1a8(%rbp), %rdi
callq 0x2070
leaq -0x3b0(%rbp), %rdi
leaq -0x70(%rbp), %rsi
movl $0x2c, %edx
callq 0x2220
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x25a7
leaq -0x228(%rbp), %rdi
leaq -0x70(%rbp), %rsi
movl $0x18, %edx
callq 0x21b0
leaq -0x228(%rbp), %rdi
leaq -0x34(%rbp), %rsi
callq 0x20c0
movq 0x3a29(%rip), %rsi      # 0x5fb8
leaq -0x228(%rbp), %rdi
callq 0x20e0
leaq -0x1a8(%rbp), %rdi
callq 0x2070
movq 0x3a0a(%rip), %rsi      # 0x5fb8
leaq -0x3b0(%rbp), %rdi
callq 0x20e0
leaq -0x330(%rbp), %rdi
callq 0x2070
movq %rsp, -0x98(%rbp)
movl -0x2c(%rbp), %eax
movq %rsp, %rcx
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
subq %rax, %rcx
movq %rcx, -0x40(%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), %r15
leaq (%r15,%rax), %rcx
movq %rcx, -0x50(%rbp)
leaq -0x3b0(%rbp), %r13
addq %r13, %rax
movq %rax, -0xa0(%rbp)
xorl %ebx, %ebx
leaq -0x70(%rbp), %r12
movq -0x5b8(%rbp), %rax
movq -0x18(%rax), %rdi
leaq -0x5b8(%rbp), %r14
addq %r14, %rdi
movl $0xa, %esi
callq 0x2120
movsbl %al, %edx
movq %r14, %rdi
leaq -0x90(%rbp), %rsi
callq 0x2220
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2763
movq %r13, %rdi
leaq -0x90(%rbp), %rsi
movl $0x18, %edx
callq 0x21b0
movq %r13, %rdi
movq %r12, %rsi
movl $0x2c, %edx
callq 0x2220
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x26e3
movq %r15, %rdi
movq %r12, %rsi
movl $0x18, %edx
callq 0x21b0
movq %r15, %rdi
leaq -0x30(%rbp), %rsi
callq 0x20c0
movl -0x30(%rbp), %eax
movq -0x48(%rbp), %rcx
movl %eax, (%rcx,%rbx)
movq %r15, %rdi
movq 0x38e3(%rip), %rsi      # 0x5fb8
callq 0x20e0
movq -0x50(%rbp), %rdi
callq 0x2070
movq %r13, %rdi
movq %r12, %rsi
movl $0x2c, %edx
callq 0x2220
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x273f
movq %r15, %rdi
movq %r12, %rsi
movl $0x18, %edx
callq 0x21b0
movq %r15, %rdi
leaq -0x30(%rbp), %rsi
callq 0x20c0
movl -0x30(%rbp), %eax
movq -0x40(%rbp), %rcx
movl %eax, (%rcx,%rbx)
movq %r15, %rdi
movq 0x3887(%rip), %rsi      # 0x5fb8
callq 0x20e0
movq -0x50(%rbp), %rdi
callq 0x2070
movq %r13, %rdi
movq 0x386f(%rip), %rsi      # 0x5fb8
callq 0x20e0
movq -0xa0(%rbp), %rdi
callq 0x2070
addq $0x4, %rbx
jmp 0x2630
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 -0x40(%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 0x27ec
leaq (%rbx,%rax,8), %r14
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
leaq -0x3e3(%rip), %rcx      # 0x23ec
movq %rbx, %rdi
movq %r14, %rsi
callq 0x33e1
leaq -0x3f5(%rip), %rdx      # 0x23ec
movq %rbx, %rdi
movq %r14, %rsi
callq 0x350a
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
movq -0x40(%rbp), %r9
movq -0x48(%rbp), %r10
jle 0x2837
xorl %eax, %eax
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 0x281b
movl -0x34(%rbp), %ecx
callq 0x2944
movq -0x98(%rbp), %rsp
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x285f
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x2140
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x287b
movq -0x80(%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 0x28ac
jmp 0x28d4
jmp 0x28ac
jmp 0x28d4
jmp 0x28f8
jmp 0x28d4
jmp 0x28f8
jmp 0x28f8
jmp 0x28ac
jmp 0x28d4
movq %rax, %rbx
movq 0x3702(%rip), %rsi      # 0x5fb8
leaq -0x228(%rbp), %rdi
callq 0x20e0
leaq -0x1a8(%rbp), %rdi
callq 0x2070
jmp 0x28d7
jmp 0x28d4
jmp 0x28f8
movq %rax, %rbx
movq 0x36da(%rip), %rsi      # 0x5fb8
leaq -0x3b0(%rbp), %rdi
callq 0x20e0
leaq -0x330(%rbp), %rdi
callq 0x2070
jmp 0x28fb
movq %rax, %rbx
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x2914
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x2140
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x2930
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x2140
leaq -0x5b8(%rbp), %rdi
callq 0x2050
movq %rbx, %rdi
callq 0x2200