// File: /workspace/github_cpp_makefile_star2_O1/readmapping[P]alfalfa/src/performanceUtils.cpp
// Function: calculatedDPScore(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>&, std::vector<long, std::allocator<long>>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
int calculatedDPScore(const string& S, vector<string> & refdescr, vector<long> & startpos, const string& queryLine){
    //read boundaries and sequence from SAM line
    int tabPos = 0;
    char delimeter = '\t';
    //qname
    nextField(queryLine, delimeter, tabPos);
    //flag
    nextField(queryLine, delimeter, tabPos);
    //rname
    string rname = nextField(queryLine, delimeter, tabPos);
    long chromStart = 0;
    size_t index = 0;
    while(index < refdescr.size() && refdescr[index].compare(rname)!=0)
        index++;
    if(index < refdescr.size()){
        chromStart = startpos[index];
    }
    else{
        cerr << "query found in sequence " << rname << ". But this sequence is not found in reference string" << endl;
        cerr << queryLine << endl;
        cerr << "length of line: " << queryLine.length() << endl;
        exit(1);
    }
    //pos
    long refStart = atoi(nextField(queryLine, delimeter, tabPos).c_str()) -1;//-1 because SAM is 1-based
    refStart += chromStart;
    //mapq
    nextField(queryLine, delimeter, tabPos).c_str();
    //skip CIGAR
    string cigar = nextField(queryLine, delimeter, tabPos);
    //rnext
    nextField(queryLine, delimeter, tabPos);
    //pnext
    nextField(queryLine, delimeter, tabPos);
    //tlen
    nextField(queryLine, delimeter, tabPos);
    //seq
    string P = nextField(queryLine, delimeter, tabPos);
    for(size_t i = 0; i < P.length(); i++){
        P[i] = std::tolower(P[i]);
    }
    int cigarPos = 0;
    long refEnd = refStart;
    long qStart = 0;
    int editDist = 0;
    while(cigarPos < (int)cigar.length()){
        int beginPos = cigarPos;
        while(cigar[cigarPos] >= 48 && cigar[cigarPos] <= 57)//integer
                cigarPos++;
        //now cigar[cigarPos] is character
        long partsize = atoi(cigar.substr(beginPos,cigarPos-beginPos).c_str());
        if(cigar[cigarPos] == 'D' || cigar[cigarPos] == 'X' || cigar[cigarPos] == 'I'){
            editDist += partsize;
            qStart += partsize;
            refEnd += partsize;
        }
        else if(cigar[cigarPos] == 'S' || cigar[cigarPos] == 'H'){
            qStart += partsize;
        }
        else if(cigar[cigarPos] == 'M'){
            
            for(int i= 0; i < partsize; i++){
                if(P[qStart+i]!=S[refEnd+i])
                    editDist++;
            }
            qStart += partsize;
            refEnd += partsize;
        }
        cigarPos++;
    }
    return editDist;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movq %rcx, %r14
movq %rdx, 0x8(%rsp)
movq %rsi, %r12
movq %rdi, 0x50(%rsp)
movq %rcx, %rdi
movl $0x9, %esi
xorl %edx, %edx
callq 0x7410
movslq %eax, %r13
leaq 0x118(%rsp), %rbp
movq %rbp, %rdi
movq %r14, %rsi
xorl %edx, %edx
movq %r13, %rcx
callq 0x7310
incl %r13d
movq (%rbp), %rdi
leaq 0x128(%rsp), %rax
cmpq %rax, %rdi
je 0x35256
movq 0x128(%rsp), %rsi
incq %rsi
callq 0x72f0
movslq %r13d, %rbp
movq %r14, %rdi
movl $0x9, %esi
movq %rbp, %rdx
callq 0x7410
movq %rax, %r13
subl %ebp, %eax
movslq %eax, %rcx
leaq 0xf8(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x7310
incl %r13d
movq (%rbx), %rdi
leaq 0x108(%rsp), %rax
cmpq %rax, %rdi
je 0x352aa
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x72f0
movslq %r13d, %rbx
movq %r14, %rdi
movl $0x9, %esi
movq %rbx, %rdx
callq 0x7410
movq %rax, %r13
subl %ebx, %eax
movslq %eax, %rcx
leaq 0x58(%rsp), %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x7310
movq (%r12), %rdi
cmpq %rdi, 0x8(%r12)
je 0x35317
xorl %r15d, %r15d
leaq 0x58(%rsp), %rbp
xorl %ebx, %ebx
addq %r15, %rdi
movq %rbp, %rsi
callq 0x7050
testl %eax, %eax
je 0x35319
incq %rbx
movq (%r12), %rdi
movq 0x8(%r12), %rax
subq %rdi, %rax
sarq $0x5, %rax
addq $0x20, %r15
cmpq %rax, %rbx
jb 0x352ea
jmp 0x35319
xorl %ebx, %ebx
movq 0x8(%r12), %rax
subq (%r12), %rax
sarq $0x5, %rax
cmpq %rax, %rbx
jae 0x356c6
incl %r13d
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq (%rax,%rbx,8), %rax
movq %rax, 0x8(%rsp)
movslq %r13d, %rbx
movq %r14, %rdi
movl $0x9, %esi
movq %rbx, %rdx
callq 0x7410
movq %rax, %r15
subl %ebx, %eax
movslq %eax, %rcx
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x7310
incl %r15d
leaq 0x20(%rsp), %rbx
movq -0x10(%rbx), %r12
movq %r12, %rdi
callq 0x7520
movl %eax, %ebp
cmpq %rbx, %r12
je 0x35399
movq 0x20(%rsp), %rsi
incq %rsi
movq %r12, %rdi
callq 0x72f0
movslq %r15d, %rbx
movq %r14, %rdi
movl $0x9, %esi
movq %rbx, %rdx
callq 0x7410
movq %rax, %r15
subl %ebx, %eax
movslq %eax, %rcx
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x7310
incl %r15d
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x353e3
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x72f0
movslq %r15d, %rbx
movq %r14, %rdi
movl $0x9, %esi
movq %rbx, %rdx
callq 0x7410
movq %rax, %r15
subl %ebx, %eax
movslq %eax, %rcx
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x7310
incl %r15d
movslq %r15d, %rbx
movq %r14, %rdi
movl $0x9, %esi
movq %rbx, %rdx
callq 0x7410
movq %rax, %r15
subl %ebx, %eax
movslq %eax, %rcx
leaq 0xd8(%rsp), %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x7310
incl %r15d
leaq 0xe8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x35463
movq 0xe8(%rsp), %rsi
incq %rsi
callq 0x72f0
movslq %r15d, %rbx
movq %r14, %rdi
movl $0x9, %esi
movq %rbx, %rdx
callq 0x7410
movq %rax, %r15
subl %ebx, %eax
movslq %eax, %rcx
leaq 0xb8(%rsp), %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x7310
incl %r15d
leaq 0xc8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x354b5
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x72f0
movslq %r15d, %rbx
movq %r14, %rdi
movl $0x9, %esi
movq %rbx, %rdx
callq 0x7410
movq %rax, %r15
subl %ebx, %eax
movslq %eax, %rcx
leaq 0x98(%rsp), %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x7310
incl %r15d
leaq 0xa8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x35507
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x72f0
movslq %r15d, %rbx
movq %r14, %rdi
movl $0x9, %esi
movq %rbx, %rdx
callq 0x7410
subl %ebx, %eax
movslq %eax, %rcx
leaq 0x30(%rsp), %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x7310
cmpq $0x0, 0x38(%rsp)
je 0x35556
xorl %ebx, %ebx
movq 0x30(%rsp), %r14
movsbl (%r14,%rbx), %edi
callq 0x7480
movb %al, (%r14,%rbx)
incq %rbx
cmpq 0x38(%rsp), %rbx
jb 0x35539
cmpl $0x0, 0x18(%rsp)
jle 0x3565c
decl %ebp
movslq %ebp, %rax
addq %rax, 0x8(%rsp)
xorl %r14d, %r14d
leaq 0x10433(%rip), %rbx     # 0x459a8
xorl %r15d, %r15d
xorl %r12d, %r12d
movq 0x10(%rsp), %rax
movslq %r12d, %rdx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq %rdx, %r12
movb (%rax,%r12), %sil
addb $-0x30, %sil
incq %r12
incl %ecx
cmpb $0xa, %sil
jb 0x3558b
movslq %ecx, %rcx
leaq 0x78(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x7310
movq 0x78(%rsp), %r13
movq %r13, %rdi
callq 0x7520
movl %eax, %ebp
leaq 0x88(%rsp), %rax
cmpq %rax, %r13
je 0x355df
movq 0x88(%rsp), %rsi
incq %rsi
movq %r13, %rdi
callq 0x72f0
movslq %ebp, %rax
movq 0x10(%rsp), %rcx
movzbl -0x1(%rcx,%r12), %ecx
leal -0x44(%rcx), %edx
cmpl $0x9, %edx
ja 0x35635
movslq (%rbx,%rdx,4), %rcx
addq %rbx, %rcx
jmpq *%rcx
testl %ebp, %ebp
jle 0x35642
movq 0x30(%rsp), %rcx
addq %r15, %rcx
movq 0x50(%rsp), %rdx
movq (%rdx), %rdx
addq 0x8(%rsp), %rdx
xorl %esi, %esi
movb (%rcx,%rsi), %dil
xorl %r8d, %r8d
cmpb (%rdx,%rsi), %dil
setne %r8b
addl %r8d, %r14d
incq %rsi
cmpq %rsi, %rax
jne 0x35619
jmp 0x35642
cmpl $0x53, %ecx
je 0x3564c
cmpl $0x58, %ecx
jne 0x3564f
addl %ebp, %r14d
addq %rax, %r15
addq %rax, 0x8(%rsp)
jmp 0x3564f
addq %rax, %r15
cmpl 0x18(%rsp), %r12d
jl 0x3557b
jmp 0x3565f
xorl %r14d, %r14d
leaq 0x40(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3567a
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x72f0
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x35696
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x72f0
leaq 0x68(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x356b1
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x72f0
movl %r14d, %eax
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1e91b(%rip), %rdi     # 0x53fe8
leaq 0x10617(%rip), %rsi     # 0x45ceb
movl $0x18, %edx
callq 0x7340
movq 0x58(%rsp), %rsi
movq 0x60(%rsp), %rdx
movq 0x1e8f9(%rip), %rdi     # 0x53fe8
callq 0x7340
movq %rax, %rbx
leaq 0x10606(%rip), %rsi     # 0x45d04
movl $0x34, %edx
movq %rax, %rdi
callq 0x7340
movq %rbx, %rdi
callq 0x7150
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq 0x1e8c7(%rip), %rdi     # 0x53fe8
callq 0x7340
movq %rax, %rdi
callq 0x7150
movq 0x1e8b3(%rip), %rdi     # 0x53fe8
leaq 0x105fd(%rip), %rsi     # 0x45d39
movl $0x10, %edx
callq 0x7340
movq 0x8(%r14), %rsi
movq 0x1e897(%rip), %rdi     # 0x53fe8
callq 0x71c0
movq %rax, %rdi
callq 0x7150
movl $0x1, %edi
callq 0x73b0
jmp 0x35777
jmp 0x35772
jmp 0x35777
jmp 0x35777
jmp 0x35777
movq %rax, %rbx
jmp 0x3579a
movq %rax, %rbx
jmp 0x357b6
movq %rax, %rbx
leaq 0x40(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3579a
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x72f0
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x357b6
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x72f0
leaq 0x68(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x357d1
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x72f0
movq %rbx, %rdi
callq 0x7600