// File: /workspace/github_cpp_makefile_star2_O1/readmapping[P]alfalfa/src/mapper.cpp
// Function: alignment_t::setFieldsKsw(int, unsigned int*, unsigned char const*, unsigned char const*, int, int)
void alignment_t::setFieldsKsw(int n_cigar, uint32_t *BamCigar, const uint8_t * query, const uint8_t * rseq, int beginGap, int endGap){
    int i, k, x, y, n_mm = 0, n_gap = 0;
    stringstream sNM;
    stringstream sCig;
    if(beginGap){
        sCig << beginGap << "S";
        sNM << beginGap << "S";
    }    
    for (k = 0, x = y = 0; k < n_cigar; ++k) {
        int op  = BamCigar[k]&0xf;
        int len = BamCigar[k]>>4;
        sCig << len << "MIDSH"[op];
        if (op == 0) { // match
            int matchLen = 0;
            int mmLen = 0;
            for(i = 0; i < len; i++){
                if(query[x + i] != rseq[y + i]){
                    ++n_mm; ++mmLen;
                    if(matchLen){
                        sNM << matchLen << "=";
                        matchLen = 0;
                    }
                }
                else{
                    ++matchLen;
                    if(mmLen){
                        sNM << mmLen << "X";
                        mmLen = 0;
                    }
                }
            }
            if(matchLen)
                sNM << matchLen << "=";
            else
                sNM << mmLen << "X";
            x += len; y += len;
        } 
        else{
            sNM << len << "MIDSH"[op];
            if (op == 1) x += len, n_gap += len;
            else if (op == 2) y += len, n_gap += len;
        }
    }
    if(endGap){
        sCig << endGap << "S";
        sNM << endGap << "S";
    }  
    editDist = n_mm + n_gap;
    cigar = sCig.str();
    NMtag = sNM.str();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x378, %rsp            # imm = 0x378
movl %r9d, %ebp
movq %r8, 0x38(%rsp)
movq %rcx, 0x30(%rsp)
movq %rdx, 0x50(%rsp)
movl %esi, %ebx
movq %rdi, %r13
leaq 0x68(%rsp), %rdi
callq 0x71e0
leaq 0x1f0(%rsp), %rdi
callq 0x71e0
testl %ebp, %ebp
je 0x1f34a
leaq 0x200(%rsp), %rdi
movl %ebp, %esi
callq 0x75d0
leaq 0x26284(%rip), %rsi     # 0x455a1
movl $0x1, %edx
movq %rax, %rdi
callq 0x7340
leaq 0x78(%rsp), %rdi
movl %ebp, %esi
callq 0x75d0
leaq 0x26264(%rip), %rsi     # 0x455a1
movl $0x1, %edx
movq %rax, %rdi
callq 0x7340
testl %ebx, %ebx
jle 0x1f525
movl %ebx, %eax
movq %rax, 0x48(%rsp)
xorl %ecx, %ecx
movl $0x0, (%rsp)
movl $0x0, 0xc(%rsp)
movl $0x0, 0x8(%rsp)
movl $0x0, 0x4(%rsp)
movq %r13, 0x40(%rsp)
movq 0x50(%rsp), %rax
movq %rcx, 0x58(%rsp)
movl (%rax,%rcx,4), %r15d
movl %r15d, %ebx
shrl $0x4, %ebx
leaq 0x200(%rsp), %rdi
movl %ebx, %esi
callq 0x75d0
movl %r15d, %r14d
andl $0xf, %r14d
leaq 0x25980(%rip), %rcx     # 0x44d30
movb (%r14,%rcx), %bpl
movb %bpl, 0x10(%rsp)
movl $0x1, %edx
movq %rax, %rdi
leaq 0x10(%rsp), %rsi
callq 0x7340
testl %r14d, %r14d
je 0x1f409
leaq 0x78(%rsp), %rdi
movl %ebx, %esi
callq 0x75d0
movb %bpl, 0x10(%rsp)
movl $0x1, %edx
movq %rax, %rdi
leaq 0x10(%rsp), %rsi
callq 0x7340
cmpl $0x2, %r14d
je 0x1f41a
cmpl $0x1, %r14d
jne 0x1f510
addl %ebx, 0x4(%rsp)
jmp 0x1f41e
xorl %r12d, %r12d
cmpl $0x10, %r15d
jae 0x1f426
xorl %r15d, %r15d
jmp 0x1f4c7
addl %ebx, 0x8(%rsp)
addl %ebx, (%rsp)
jmp 0x1f510
movslq 0x4(%rsp), %rax
movslq 0x8(%rsp), %r14
addq 0x30(%rsp), %rax
movq %rax, 0x60(%rsp)
addq 0x38(%rsp), %r14
xorl %r13d, %r13d
xorl %r15d, %r15d
xorl %ebp, %ebp
movq 0x60(%rsp), %rax
movb (%rax,%r13), %al
cmpb (%r14,%r13), %al
jne 0x1f486
incl %ebp
testl %r15d, %r15d
je 0x1f4b6
leaq 0x78(%rsp), %rdi
movl %r15d, %esi
callq 0x75d0
movl $0x1, %edx
movq %rax, %rdi
leaq 0x2417f(%rip), %rsi     # 0x435f8
callq 0x7340
movl %ebp, %r12d
xorl %r15d, %r15d
jmp 0x1f4bc
incl 0xc(%rsp)
incl %r15d
xorl %r12d, %r12d
testl %ebp, %ebp
je 0x1f4bc
leaq 0x78(%rsp), %rdi
movl %ebp, %esi
callq 0x75d0
movl $0x1, %edx
movq %rax, %rdi
leaq 0x20fd5(%rip), %rsi     # 0x40484
callq 0x7340
jmp 0x1f4bc
movl %ebp, %r12d
xorl %r15d, %r15d
incq %r13
movl %r12d, %ebp
cmpq %r13, %rbx
jne 0x1f447
testl %r12d, %r12d
movq 0x40(%rsp), %r13
je 0x1f4e7
leaq 0x78(%rsp), %rdi
movl %r12d, %esi
callq 0x75d0
leaq 0x20f9f(%rip), %rsi     # 0x40484
jmp 0x1f4fb
leaq 0x78(%rsp), %rdi
movl %r15d, %esi
callq 0x75d0
leaq 0x240fd(%rip), %rsi     # 0x435f8
movl $0x1, %edx
movq %rax, %rdi
callq 0x7340
addl %ebx, 0x4(%rsp)
addl %ebx, 0x8(%rsp)
movq 0x58(%rsp), %rcx
incq %rcx
cmpq 0x48(%rsp), %rcx
jne 0x1f37f
jmp 0x1f534
movl $0x0, 0xc(%rsp)
movl $0x0, (%rsp)
movl 0x3b0(%rsp), %ebx
testl %ebx, %ebx
je 0x1f582
leaq 0x200(%rsp), %rdi
movl %ebx, %esi
callq 0x75d0
leaq 0x2604c(%rip), %rsi     # 0x455a1
movl $0x1, %edx
movq %rax, %rdi
callq 0x7340
leaq 0x78(%rsp), %rdi
movl %ebx, %esi
callq 0x75d0
leaq 0x2602c(%rip), %rsi     # 0x455a1
movl $0x1, %edx
movq %rax, %rdi
callq 0x7340
movl (%rsp), %eax
addl 0xc(%rsp), %eax
movl %eax, 0x6c(%r13)
leaq 0x208(%rsp), %rsi
leaq 0x10(%rsp), %rdi
callq 0x7540
leaq 0x20(%r13), %rdi
leaq 0x10(%rsp), %rbx
movq %rbx, %rsi
callq 0x73c0
movq (%rbx), %rdi
leaq 0x20(%rsp), %r14
cmpq %r14, %rdi
je 0x1f5ca
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x72f0
leaq 0x80(%rsp), %rsi
leaq 0x10(%rsp), %rdi
callq 0x7540
addq $0x78, %r13
leaq 0x10(%rsp), %rbx
movq %r13, %rdi
movq %rbx, %rsi
callq 0x73c0
movq (%rbx), %rdi
cmpq %r14, %rdi
je 0x1f605
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x72f0
movq 0x3498c(%rip), %rbx     # 0x53f98
leaq 0x1f0(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x7210
movl $0x80, %r14d
addq %r14, %r15
movq %r15, %rdi
callq 0x7100
leaq 0x68(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x7210
addq %r14, %r15
movq %r15, %rdi
callq 0x7100
addq $0x378, %rsp            # imm = 0x378
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1f66c
jmp 0x1f66c
movq %rax, %rbx
jmp 0x1f690
jmp 0x1f66c
jmp 0x1f66c
jmp 0x1f66c
movq %rax, %rbx
movq 0x34922(%rip), %rsi     # 0x53f98
leaq 0x1f0(%rsp), %rdi
callq 0x7210
leaq 0x270(%rsp), %rdi
callq 0x7100
movq 0x34901(%rip), %rsi     # 0x53f98
leaq 0x68(%rsp), %rdi
callq 0x7210
leaq 0xe8(%rsp), %rdi
callq 0x7100
movq %rbx, %rdi
callq 0x7600