// File: /workspace/github_cpp_makefile_star2_O2/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 $0x148, %rsp            # imm = 0x148
movq %rcx, %r14
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, 0x40(%rsp)
leaq 0xc(%rsp), %rbp
andl $0x0, (%rbp)
leaq 0x128(%rsp), %r13
pushq $0x9
popq %rbx
movq %r13, %rdi
movq %rcx, %rsi
movl %ebx, %edx
movq %rbp, %rcx
callq 0x2a2b8
movq %r13, %rdi
callq 0x76a8
leaq 0x108(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
movl %ebx, %edx
movq %rbp, %rcx
callq 0x2a2b8
movq %r13, %rdi
callq 0x76a8
leaq 0x68(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
movl %ebx, %edx
movq %rbp, %rcx
callq 0x2a2b8
xorl %ebp, %ebp
xorl %ebx, %ebx
movq (%r12), %rdi
movq 0x8(%r12), %rax
subq %rdi, %rax
sarq $0x5, %rax
cmpq %rax, %rbx
jae 0x2a88b
addq %rbp, %rdi
movq %r13, %rsi
callq 0x7040
testl %eax, %eax
je 0x2a87e
incq %rbx
addq $0x20, %rbp
jmp 0x2a851
movq 0x8(%r12), %rax
subq (%r12), %rax
sarq $0x5, %rax
cmpq %rax, %rbx
jae 0x2aae5
movq (%r15), %rax
movq (%rax,%rbx,8), %r15
leaq 0x20(%rsp), %rdi
pushq $0x9
popq %rdx
leaq 0xc(%rsp), %rcx
movq %r14, %rsi
callq 0x2a2b8
leaq 0x20(%rsp), %rbx
movq (%rbx), %rdi
callq 0x7520
movl %eax, %ebp
movq %rbx, %rdi
callq 0x76a8
leaq 0x20(%rsp), %rdi
pushq $0x9
popq %rdx
leaq 0xc(%rsp), %rcx
movq %r14, %rsi
callq 0x2a2b8
leaq 0x20(%rsp), %rdi
callq 0x76a8
leaq 0x20(%rsp), %rdi
pushq $0x9
popq %rdx
leaq 0xc(%rsp), %rcx
movq %r14, %rsi
callq 0x2a2b8
leaq 0xe8(%rsp), %rdi
pushq $0x9
popq %rdx
leaq 0xc(%rsp), %rcx
movq %r14, %rsi
callq 0x2a2b8
leaq 0xe8(%rsp), %rdi
callq 0x76a8
leaq 0xc8(%rsp), %rdi
pushq $0x9
popq %rdx
leaq 0xc(%rsp), %rcx
movq %r14, %rsi
callq 0x2a2b8
leaq 0xc8(%rsp), %rdi
callq 0x76a8
leaq 0xa8(%rsp), %rdi
pushq $0x9
popq %rdx
leaq 0xc(%rsp), %rcx
movq %r14, %rsi
callq 0x2a2b8
leaq 0xa8(%rsp), %rdi
callq 0x76a8
leaq 0x48(%rsp), %rdi
pushq $0x9
popq %rdx
leaq 0xc(%rsp), %rcx
movq %r14, %rsi
callq 0x2a2b8
movslq %ebp, %rax
addq %r15, %rax
decq %rax
movq %rax, 0x18(%rsp)
xorl %r14d, %r14d
cmpq 0x50(%rsp), %r14
jae 0x2a9af
movq 0x48(%rsp), %r15
movsbl (%r15,%r14), %edi
callq 0x7490
movb %al, (%r15,%r14)
incq %r14
jmp 0x2a990
leaq 0x88(%rsp), %rbx
xorl %r13d, %r13d
movq $0x0, 0x10(%rsp)
xorl %ebp, %ebp
cmpl 0x28(%rsp), %r13d
jge 0x2aab3
movq 0x20(%rsp), %rax
movslq %r13d, %rdx
pushq $-0x1
popq %rcx
movq %rdx, %r13
movb (%rax,%r13), %sil
addb $-0x30, %sil
incq %r13
incl %ecx
cmpb $0xa, %sil
jb 0x2a9de
movslq %ecx, %rcx
movq %rbx, %rdi
leaq 0x20(%rsp), %rsi
callq 0x72f0
movq 0x88(%rsp), %rdi
callq 0x7520
movl %eax, %r12d
movslq %eax, %r14
movq %rbx, %r15
movq %rbx, %rdi
callq 0x76a8
movq 0x20(%rsp), %rax
movzbl -0x1(%rax,%r13), %eax
leal -0x44(%rax), %ecx
cmpl $0x9, %ecx
ja 0x2aa86
leaq 0xcf2f(%rip), %rdx      # 0x37968
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
movq %r15, %rbx
jmpq *%rax
movq 0x48(%rsp), %rax
addq 0x10(%rsp), %rax
movq 0x40(%rsp), %rcx
movq (%rcx), %rcx
addq 0x18(%rsp), %rcx
testl %r12d, %r12d
movl $0x0, %edx
cmovlel %edx, %r12d
xorl %edx, %edx
cmpq %rdx, %r12
je 0x2aa9a
movb (%rax,%rdx), %sil
xorl %r8d, %r8d
cmpb (%rcx,%rdx), %sil
setne %r8b
addl %r8d, %ebp
incq %rdx
jmp 0x2aa6a
cmpl $0x53, %eax
movq %r15, %rbx
je 0x2aaa9
cmpl $0x58, %eax
jne 0x2a9c5
addl %r12d, %ebp
addq %r14, 0x10(%rsp)
addq %r14, 0x18(%rsp)
jmp 0x2a9c5
addq %r14, 0x10(%rsp)
jmp 0x2a9c5
leaq 0x48(%rsp), %rdi
callq 0x76a8
leaq 0x20(%rsp), %rdi
callq 0x76a8
leaq 0x68(%rsp), %rdi
callq 0x76a8
movl %ebp, %eax
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1f4fc(%rip), %rdi     # 0x49fe8
leaq 0xd1b8(%rip), %rsi      # 0x37cab
callq 0x72b0
leaq 0x68(%rsp), %rsi
movq %rax, %rdi
callq 0x7280
leaq 0xd1b8(%rip), %rsi      # 0x37cc4
movq %rax, %rdi
callq 0x72b0
movq %rax, %rdi
callq 0x7160
movq 0x1f4c5(%rip), %rdi     # 0x49fe8
movq %r14, %rsi
callq 0x7280
movq %rax, %rdi
callq 0x7160
movq 0x1f4ae(%rip), %rdi     # 0x49fe8
leaq 0xd1b8(%rip), %rsi      # 0x37cf9
callq 0x72b0
movq 0x8(%r14), %rsi
movq %rax, %rdi
callq 0x71d0
movq %rax, %rdi
callq 0x7160
pushq $0x1
popq %rdi
callq 0x7390
jmp 0x2ab71
jmp 0x2ab6c
jmp 0x2ab71
jmp 0x2ab71
jmp 0x2ab71
movq %rax, %rbx
jmp 0x2ab83
movq %rax, %rbx
jmp 0x2ab8d
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x76a8
leaq 0x20(%rsp), %rdi
callq 0x76a8
leaq 0x68(%rsp), %rdi
callq 0x76a8
movq %rbx, %rdi
callq 0x75e0