// File: 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:
subq $0x2d8, %rsp            # imm = 0x2D8
movq %rdi, 0x2d0(%rsp)
movq %rsi, 0x2c8(%rsp)
movq %rdx, 0x2c0(%rsp)
movq %rcx, 0x2b8(%rsp)
movl $0x0, 0x2b4(%rsp)
movb $0x9, 0x2b3(%rsp)
movq 0x2b8(%rsp), %rsi
leaq 0x290(%rsp), %rdi
leaq 0x2b4(%rsp), %rcx
movsbl 0x2b3(%rsp), %edx
callq 0x66e60
leaq 0x290(%rsp), %rdi
callq 0x8858
movq 0x2b8(%rsp), %rsi
leaq 0x270(%rsp), %rdi
leaq 0x2b4(%rsp), %rcx
movsbl 0x2b3(%rsp), %edx
callq 0x66e60
leaq 0x270(%rsp), %rdi
callq 0x8858
movq 0x2b8(%rsp), %rsi
leaq 0x250(%rsp), %rdi
leaq 0x2b4(%rsp), %rcx
movsbl 0x2b3(%rsp), %edx
callq 0x66e60
movq $0x0, 0x248(%rsp)
movq $0x0, 0x240(%rsp)
movq 0x240(%rsp), %rax
movq %rax, 0xe8(%rsp)
movq 0x2c8(%rsp), %rdi
callq 0xccb0
movq 0xe8(%rsp), %rcx
movq %rax, %rdx
xorl %eax, %eax
cmpq %rdx, %rcx
movb %al, 0xf3(%rsp)
jae 0x67a73
movq 0x2c8(%rsp), %rdi
movq 0x240(%rsp), %rsi
callq 0xccf0
movq %rax, %rdi
leaq 0x250(%rsp), %rsi
callq 0x8050
movl %eax, 0xe4(%rsp)
jmp 0x67a5f
movl 0xe4(%rsp), %eax
cmpl $0x0, %eax
setne %al
movb %al, 0xf3(%rsp)
movb 0xf3(%rsp), %al
testb $0x1, %al
jne 0x67a80
jmp 0x67ab2
movq 0x240(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x240(%rsp)
jmp 0x679fb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x238(%rsp)
movl %eax, 0x234(%rsp)
jmp 0x682a2
movq 0x240(%rsp), %rax
movq %rax, 0xd8(%rsp)
movq 0x2c8(%rsp), %rdi
callq 0xccb0
movq %rax, %rcx
movq 0xd8(%rsp), %rax
cmpq %rcx, %rax
jae 0x67b04
movq 0x2c0(%rsp), %rdi
movq 0x240(%rsp), %rsi
callq 0xccd0
movq (%rax), %rax
movq %rax, 0x248(%rsp)
jmp 0x67c0c
movq 0x2f4e5(%rip), %rdi     # 0x96ff0
leaq 0x17125(%rip), %rsi     # 0x7ec37
callq 0x8360
movq %rax, 0xd0(%rsp)
jmp 0x67b21
movq 0xd0(%rsp), %rdi
leaq 0x250(%rsp), %rsi
callq 0x8330
movq %rax, 0xc8(%rsp)
jmp 0x67b40
movq 0xc8(%rsp), %rdi
leaq 0x17101(%rip), %rsi     # 0x7ec50
callq 0x8360
movq %rax, 0xc0(%rsp)
jmp 0x67b5e
movq 0xc0(%rsp), %rdi
movq 0x2f443(%rip), %rsi     # 0x96fb0
callq 0x83b0
jmp 0x67b74
movq 0x2b8(%rsp), %rsi
movq 0x2f46d(%rip), %rdi     # 0x96ff0
callq 0x8330
movq %rax, 0xb8(%rsp)
jmp 0x67b92
movq 0xb8(%rsp), %rdi
movq 0x2f40f(%rip), %rsi     # 0x96fb0
callq 0x83b0
jmp 0x67ba8
movq 0x2f441(%rip), %rdi     # 0x96ff0
leaq 0x170cf(%rip), %rsi     # 0x7ec85
callq 0x8360
movq %rax, 0xb0(%rsp)
jmp 0x67bc5
movq 0x2b8(%rsp), %rdi
callq 0x8630
movq 0xb0(%rsp), %rdi
movq %rax, %rsi
callq 0x8100
movq %rax, 0xa8(%rsp)
jmp 0x67bec
movq 0xa8(%rsp), %rdi
movq 0x2f3b5(%rip), %rsi     # 0x96fb0
callq 0x83b0
jmp 0x67c02
movl $0x1, %edi
callq 0x84a0
movq 0x2b8(%rsp), %rsi
movsbl 0x2b3(%rsp), %edx
leaq 0x208(%rsp), %rdi
leaq 0x2b4(%rsp), %rcx
callq 0x66e60
jmp 0x67c33
leaq 0x208(%rsp), %rdi
movq %rdi, 0x98(%rsp)
callq 0x8170
movq %rax, %rdi
callq 0x8670
movq 0x98(%rsp), %rdi
decl %eax
cltq
movq %rax, 0xa0(%rsp)
callq 0x8858
movq 0xa0(%rsp), %rax
movq %rax, 0x228(%rsp)
movq 0x248(%rsp), %rcx
movq 0x228(%rsp), %rax
addq %rcx, %rax
movq %rax, 0x228(%rsp)
movq 0x2b8(%rsp), %rsi
movsbl 0x2b3(%rsp), %edx
leaq 0x1e8(%rsp), %rdi
leaq 0x2b4(%rsp), %rcx
callq 0x66e60
jmp 0x67cbb
leaq 0x1e8(%rsp), %rdi
movq %rdi, 0x90(%rsp)
callq 0x8170
movq 0x90(%rsp), %rdi
callq 0x8858
movq 0x2b8(%rsp), %rsi
movsbl 0x2b3(%rsp), %edx
leaq 0x1c8(%rsp), %rdi
leaq 0x2b4(%rsp), %rcx
callq 0x66e60
jmp 0x67d04
movq 0x2b8(%rsp), %rsi
movsbl 0x2b3(%rsp), %edx
leaq 0x1a8(%rsp), %rdi
leaq 0x2b4(%rsp), %rcx
callq 0x66e60
jmp 0x67d2b
leaq 0x1a8(%rsp), %rdi
callq 0x8858
movq 0x2b8(%rsp), %rsi
movsbl 0x2b3(%rsp), %edx
leaq 0x188(%rsp), %rdi
leaq 0x2b4(%rsp), %rcx
callq 0x66e60
jmp 0x67d5f
leaq 0x188(%rsp), %rdi
callq 0x8858
movq 0x2b8(%rsp), %rsi
movsbl 0x2b3(%rsp), %edx
leaq 0x168(%rsp), %rdi
leaq 0x2b4(%rsp), %rcx
callq 0x66e60
jmp 0x67d93
leaq 0x168(%rsp), %rdi
callq 0x8858
movq 0x2b8(%rsp), %rsi
movsbl 0x2b3(%rsp), %edx
leaq 0x148(%rsp), %rdi
leaq 0x2b4(%rsp), %rcx
callq 0x66e60
jmp 0x67dc7
movq $0x0, 0x140(%rsp)
movq 0x140(%rsp), %rax
movq %rax, 0x88(%rsp)
leaq 0x148(%rsp), %rdi
callq 0x8630
movq %rax, %rcx
movq 0x88(%rsp), %rax
cmpq %rcx, %rax
jae 0x67eb6
movq 0x140(%rsp), %rsi
leaq 0x148(%rsp), %rdi
callq 0x8830
movq %rax, 0x80(%rsp)
jmp 0x67e23
movq 0x80(%rsp), %rax
movsbl (%rax), %edi
callq 0x85d0
movb %al, 0x77(%rsp)
movq 0x140(%rsp), %rsi
leaq 0x148(%rsp), %rdi
callq 0x8830
movq %rax, 0x78(%rsp)
jmp 0x67e53
movq 0x78(%rsp), %rax
movb 0x77(%rsp), %cl
movb %cl, (%rax)
movq 0x140(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x140(%rsp)
jmp 0x67dd3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x238(%rsp)
movl %eax, 0x234(%rsp)
jmp 0x68295
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x238(%rsp)
movl %eax, 0x234(%rsp)
leaq 0x148(%rsp), %rdi
callq 0x8858
jmp 0x68295
movl $0x0, 0x13c(%rsp)
movq 0x228(%rsp), %rax
movq %rax, 0x130(%rsp)
movq $0x0, 0x128(%rsp)
movl $0x0, 0x124(%rsp)
movl 0x13c(%rsp), %eax
movl %eax, 0x70(%rsp)
leaq 0x1c8(%rsp), %rdi
callq 0x8630
movq %rax, %rcx
movl 0x70(%rsp), %eax
cmpl %ecx, %eax
jge 0x68257
movl 0x13c(%rsp), %eax
movl %eax, 0x120(%rsp)
movslq 0x13c(%rsp), %rsi
leaq 0x1c8(%rsp), %rdi
callq 0x8830
movq %rax, 0x68(%rsp)
jmp 0x67f39
movq 0x68(%rsp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x30, %ecx
movb %al, 0x67(%rsp)
jl 0x67f7a
movslq 0x13c(%rsp), %rsi
leaq 0x1c8(%rsp), %rdi
callq 0x8830
movq %rax, 0x58(%rsp)
jmp 0x67f68
movq 0x58(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x39, %eax
setle %al
movb %al, 0x67(%rsp)
movb 0x67(%rsp), %al
testb $0x1, %al
jne 0x67f84
jmp 0x67f97
movl 0x13c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x13c(%rsp)
jmp 0x67f1d
movslq 0x120(%rsp), %rdx
movl %edx, %ecx
movl 0x13c(%rsp), %eax
subl %ecx, %eax
movslq %eax, %rcx
leaq 0xf8(%rsp), %rdi
leaq 0x1c8(%rsp), %rsi
callq 0x83a0
jmp 0x67fc4
leaq 0xf8(%rsp), %rdi
movq %rdi, 0x40(%rsp)
callq 0x8170
movq %rax, %rdi
callq 0x8670
movq 0x40(%rsp), %rdi
cltq
movq %rax, 0x48(%rsp)
callq 0x8858
movq 0x48(%rsp), %rax
movq %rax, 0x118(%rsp)
movslq 0x13c(%rsp), %rsi
leaq 0x1c8(%rsp), %rdi
callq 0x8830
movq %rax, 0x50(%rsp)
jmp 0x68018
movq 0x50(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x44, %eax
je 0x68077
movslq 0x13c(%rsp), %rsi
leaq 0x1c8(%rsp), %rdi
callq 0x8830
movq %rax, 0x38(%rsp)
jmp 0x68041
movq 0x38(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x58, %eax
je 0x68077
movslq 0x13c(%rsp), %rsi
leaq 0x1c8(%rsp), %rdi
callq 0x8830
movq %rax, 0x30(%rsp)
jmp 0x6806a
movq 0x30(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x49, %eax
jne 0x680c6
movq 0x118(%rsp), %rcx
movslq 0x124(%rsp), %rax
addq %rcx, %rax
movl %eax, 0x124(%rsp)
movq 0x118(%rsp), %rax
addq 0x128(%rsp), %rax
movq %rax, 0x128(%rsp)
movq 0x118(%rsp), %rax
addq 0x130(%rsp), %rax
movq %rax, 0x130(%rsp)
jmp 0x68241
movslq 0x13c(%rsp), %rsi
leaq 0x1c8(%rsp), %rdi
callq 0x8830
movq %rax, 0x28(%rsp)
jmp 0x680e2
movq 0x28(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x53, %eax
je 0x68118
movslq 0x13c(%rsp), %rsi
leaq 0x1c8(%rsp), %rdi
callq 0x8830
movq %rax, 0x20(%rsp)
jmp 0x6810b
movq 0x20(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x48, %eax
jne 0x68135
movq 0x118(%rsp), %rax
addq 0x128(%rsp), %rax
movq %rax, 0x128(%rsp)
jmp 0x6823f
movslq 0x13c(%rsp), %rsi
leaq 0x1c8(%rsp), %rdi
callq 0x8830
movq %rax, 0x18(%rsp)
jmp 0x68151
movq 0x18(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x4d, %eax
jne 0x6823d
movl $0x0, 0xf4(%rsp)
movslq 0xf4(%rsp), %rax
cmpq 0x118(%rsp), %rax
jge 0x6820d
movq 0x128(%rsp), %rsi
movslq 0xf4(%rsp), %rax
addq %rax, %rsi
leaq 0x148(%rsp), %rdi
callq 0x8830
movq %rax, 0x10(%rsp)
jmp 0x681aa
movq 0x10(%rsp), %rax
movsbl (%rax), %eax
movl %eax, 0xc(%rsp)
movq 0x2d0(%rsp), %rdi
movq 0x130(%rsp), %rsi
movslq 0xf4(%rsp), %rax
addq %rax, %rsi
callq 0x8410
movq %rax, %rcx
movl 0xc(%rsp), %eax
movsbl (%rcx), %ecx
cmpl %ecx, %eax
je 0x681f5
movl 0x124(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x124(%rsp)
jmp 0x681f7
movl 0xf4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xf4(%rsp)
jmp 0x6816d
movq 0x118(%rsp), %rax
addq 0x128(%rsp), %rax
movq %rax, 0x128(%rsp)
movq 0x118(%rsp), %rax
addq 0x130(%rsp), %rax
movq %rax, 0x130(%rsp)
jmp 0x6823f
jmp 0x68241
movl 0x13c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x13c(%rsp)
jmp 0x67ee8
movl 0x124(%rsp), %eax
movl %eax, 0x8(%rsp)
leaq 0x148(%rsp), %rdi
callq 0x8858
leaq 0x1c8(%rsp), %rdi
callq 0x8858
leaq 0x250(%rsp), %rdi
callq 0x8858
movl 0x8(%rsp), %eax
addq $0x2d8, %rsp            # imm = 0x2D8
retq
leaq 0x1c8(%rsp), %rdi
callq 0x8858
leaq 0x250(%rsp), %rdi
callq 0x8858
movq 0x238(%rsp), %rdi
callq 0x8730
nopl (%rax)