// File: /workspace/github_cpp_makefile_star2_O2/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 $0x578, %rsp            # imm = 0x578
movq %rsi, %rbx
movq 0x10(%rsi), %rsi
leaq 0x4d86(%rip), %rdi      # 0x7138
callq 0x21e0
andl $0x0, -0x2c(%rbp)
andl $0x0, -0x34(%rbp)
movq 0x8(%rbx), %rsi
leaq -0x598(%rbp), %rbx
pushq $0x8
popq %rdx
movq %rbx, %rdi
callq 0x21c0
leaq -0x70(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
movb %cl, (%rax)
leaq -0x48(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq -0x80(%rbp), %rsi
movq %rbx, %rdi
callq 0x2040
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
je 0x2416
xorl %eax, %eax
jmp 0x24d8
leaq -0x390(%rbp), %rdi
leaq -0x80(%rbp), %rsi
pushq $0x18
popq %rdx
callq 0x2160
leaq -0x390(%rbp), %rdi
leaq -0x58(%rbp), %rsi
pushq $0x2c
popq %rdx
callq 0x21d0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2479
leaq -0x208(%rbp), %rdi
leaq -0x58(%rbp), %rsi
pushq $0x18
popq %rdx
callq 0x2160
leaq -0x208(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x20b0
leaq -0x208(%rbp), %rdi
callq 0x20c0
leaq -0x390(%rbp), %rdi
leaq -0x58(%rbp), %rsi
pushq $0x2c
popq %rdx
callq 0x21d0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x24c9
leaq -0x208(%rbp), %rdi
leaq -0x58(%rbp), %rsi
pushq $0x18
popq %rdx
callq 0x2160
leaq -0x208(%rbp), %rdi
leaq -0x34(%rbp), %rsi
callq 0x20b0
leaq -0x208(%rbp), %rdi
callq 0x20c0
leaq -0x390(%rbp), %rdi
callq 0x20c0
movl -0x2c(%rbp), %eax
movq %rsp, -0x60(%rbp)
movq %rsp, %r14
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
subq %rax, %r14
movq %r14, %rsp
movl -0x2c(%rbp), %eax
movq %rsp, %r12
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
subq %rax, %r12
movq %r12, %rsp
xorl %ebx, %ebx
leaq -0x390(%rbp), %r15
leaq -0x598(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x2040
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x25f0
movq %r15, %rdi
leaq -0x80(%rbp), %rsi
pushq $0x18
popq %rdx
callq 0x2160
movq %r15, %rdi
leaq -0x58(%rbp), %rsi
pushq $0x2c
popq %rdx
callq 0x21d0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2591
leaq -0x208(%rbp), %r13
movq %r13, %rdi
leaq -0x58(%rbp), %rsi
pushq $0x18
popq %rdx
callq 0x2160
movq %r13, %rdi
leaq -0x30(%rbp), %rsi
callq 0x20b0
movl -0x30(%rbp), %eax
movl %eax, (%r12,%rbx)
movq %r13, %rdi
callq 0x20c0
movq %r15, %rdi
leaq -0x58(%rbp), %rsi
pushq $0x2c
popq %rdx
callq 0x21d0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x25df
leaq -0x208(%rbp), %r13
movq %r13, %rdi
leaq -0x58(%rbp), %rsi
pushq $0x18
popq %rdx
callq 0x2160
movq %r13, %rdi
leaq -0x30(%rbp), %rsi
callq 0x20b0
movl -0x30(%rbp), %eax
movl %eax, (%r14,%rbx)
movq %r13, %rdi
callq 0x20c0
movq %r15, %rdi
callq 0x20c0
addq $0x4, %rbx
jmp 0x2512
movl -0x2c(%rbp), %ecx
movslq %ecx, %rax
movq %rsp, %rbx
leaq 0xf(,%rcx,8), %rcx
andq $-0x10, %rcx
subq %rcx, %rbx
movq %rbx, %rsp
xorl %ecx, %ecx
testl %eax, %eax
movl $0x0, %edx
cmovgl %eax, %edx
cmpq %rcx, %rdx
je 0x263a
cvtsi2ssl (%r14,%rcx,4), %xmm0
cvtsi2ssl (%r12,%rcx,4), %xmm1
divss %xmm1, %xmm0
movss %xmm0, (%rbx,%rcx,8)
movl %ecx, 0x4(%rbx,%rcx,8)
incq %rcx
jmp 0x2617
leaq (%rbx,%rax,8), %rsi
leaq -0x2c9(%rip), %rdx      # 0x237c
movq %rbx, %rdi
callq 0x2f87
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
xorl %eax, %eax
testl %edi, %edi
movl $0x0, %ecx
cmovgl %edi, %ecx
cmpq %rax, %rcx
je 0x2699
movslq 0x4(%rbx,%rax,8), %r8
movl (%r14,%r8,4), %r9d
movl %r9d, (%rsi,%rax,4)
movl (%r12,%r8,4), %r8d
movl %r8d, (%rdx,%rax,4)
incq %rax
jmp 0x267a
movl -0x34(%rbp), %ecx
callq 0x2737
movq -0x60(%rbp), %rsp
leaq -0x58(%rbp), %rdi
callq 0x21f8
leaq -0x80(%rbp), %rdi
callq 0x21f8
leaq -0x598(%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 0x26e8
jmp 0x2702
jmp 0x26e8
jmp 0x2702
jmp 0x26fd
jmp 0x2702
jmp 0x26fd
jmp 0x26fd
jmp 0x26e8
jmp 0x2702
movq %rax, %rbx
leaq -0x208(%rbp), %rdi
callq 0x20c0
jmp 0x2705
jmp 0x2702
jmp 0x26fd
movq %rax, %rbx
jmp 0x2711
movq %rax, %rbx
leaq -0x390(%rbp), %rdi
callq 0x20c0
leaq -0x58(%rbp), %rdi
callq 0x21f8
leaq -0x80(%rbp), %rdi
callq 0x21f8
leaq -0x598(%rbp), %rdi
callq 0x2050
movq %rbx, %rdi
callq 0x21b0