// File: /workspace/github_cpp_makefile_star2_O3/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, 0x48(%rsp)
movq %rcx, 0x40(%rsp)
movq %rdx, 0x58(%rsp)
movl %esi, %ebx
movq %rdi, %r13
leaq 0x68(%rsp), %rdi
callq 0x71e0
leaq 0x1f0(%rsp), %rdi
callq 0x71e0
testl %ebp, %ebp
je 0x1f01a
leaq 0x200(%rsp), %rdi
movl %ebp, %esi
callq 0x75d0
leaq 0x265b4(%rip), %rsi     # 0x455a1
movl $0x1, %edx
movq %rax, %rdi
callq 0x7340
leaq 0x78(%rsp), %rdi
movl %ebp, %esi
callq 0x75d0
leaq 0x26594(%rip), %rsi     # 0x455a1
movl $0x1, %edx
movq %rax, %rdi
callq 0x7340
testl %ebx, %ebx
jle 0x1f1f3
movl %ebx, %eax
movq %rax, 0x50(%rsp)
xorl %ecx, %ecx
movl $0x0, 0x8(%rsp)
movl $0x0, 0x14(%rsp)
movl $0x0, 0x10(%rsp)
movl $0x0, 0xc(%rsp)
movq %r13, 0x38(%rsp)
movq 0x58(%rsp), %rax
movq %rcx, 0x60(%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 0x25caf(%rip), %rcx     # 0x44d30
movb (%r14,%rcx), %bpl
movb %bpl, 0x18(%rsp)
movl $0x1, %edx
movq %rax, %rdi
leaq 0x18(%rsp), %rsi
callq 0x7340
testl %r14d, %r14d
je 0x1f0e1
leaq 0x78(%rsp), %rdi
movl %ebx, %esi
callq 0x75d0
movb %bpl, 0x18(%rsp)
movl $0x1, %edx
movq %rax, %rdi
leaq 0x18(%rsp), %rsi
callq 0x7340
cmpl $0x2, %r14d
je 0x1f1d6
cmpl $0x1, %r14d
jne 0x1f1de
addl %ebx, 0xc(%rsp)
jmp 0x1f1da
xorl %r12d, %r12d
cmpl $0x10, %r15d
jb 0x1f1ab
movslq 0xc(%rsp), %r14
movslq 0x10(%rsp), %r13
addq 0x40(%rsp), %r14
addq 0x48(%rsp), %r13
xorl %r15d, %r15d
xorl %r12d, %r12d
xorl %ebp, %ebp
movb (%r14,%r15), %al
cmpb (%r13,%r15), %al
jne 0x1f142
incl %ebp
testl %r12d, %r12d
je 0x1f171
leaq 0x78(%rsp), %rdi
movl %r12d, %esi
callq 0x75d0
movl $0x1, %edx
movq %rax, %rdi
leaq 0x244c0(%rip), %rsi     # 0x435f8
callq 0x7340
xorl %r12d, %r12d
jmp 0x1f178
incl 0x14(%rsp)
incl %r12d
testl %ebp, %ebp
je 0x1f176
leaq 0x78(%rsp), %rdi
movl %ebp, %esi
callq 0x75d0
movl $0x1, %edx
movq %rax, %rdi
leaq 0x21319(%rip), %rsi     # 0x40481
callq 0x7340
xorl %ebp, %ebp
jmp 0x1f178
xorl %r12d, %r12d
jmp 0x1f178
xorl %ebp, %ebp
incq %r15
cmpq %r15, %rbx
jne 0x1f10a
testl %ebp, %ebp
movq 0x38(%rsp), %r13
je 0x1f1ab
leaq 0x78(%rsp), %rdi
movl %ebp, %esi
callq 0x75d0
movl $0x1, %edx
movq %rax, %rdi
leaq 0x212dd(%rip), %rsi     # 0x40481
callq 0x7340
jmp 0x1f1cc
leaq 0x78(%rsp), %rdi
movl %r12d, %esi
callq 0x75d0
movl $0x1, %edx
movq %rax, %rdi
leaq 0x24431(%rip), %rsi     # 0x435f8
callq 0x7340
addl %ebx, 0xc(%rsp)
addl %ebx, 0x10(%rsp)
jmp 0x1f1de
addl %ebx, 0x10(%rsp)
addl %ebx, 0x8(%rsp)
movq 0x60(%rsp), %rcx
incq %rcx
cmpq 0x50(%rsp), %rcx
jne 0x1f050
jmp 0x1f203
movl $0x0, 0x14(%rsp)
movl $0x0, 0x8(%rsp)
movl 0x3b0(%rsp), %ebx
testl %ebx, %ebx
je 0x1f251
leaq 0x200(%rsp), %rdi
movl %ebx, %esi
callq 0x75d0
leaq 0x2637d(%rip), %rsi     # 0x455a1
movl $0x1, %edx
movq %rax, %rdi
callq 0x7340
leaq 0x78(%rsp), %rdi
movl %ebx, %esi
callq 0x75d0
leaq 0x2635d(%rip), %rsi     # 0x455a1
movl $0x1, %edx
movq %rax, %rdi
callq 0x7340
movl 0x8(%rsp), %eax
addl 0x14(%rsp), %eax
movl %eax, 0x6c(%r13)
leaq 0x208(%rsp), %rsi
leaq 0x18(%rsp), %rdi
callq 0x7540
leaq 0x20(%r13), %rdi
leaq 0x18(%rsp), %rbx
movq %rbx, %rsi
callq 0x73c0
movq (%rbx), %rdi
leaq 0x28(%rsp), %r14
cmpq %r14, %rdi
je 0x1f29a
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x72f0
leaq 0x80(%rsp), %rsi
leaq 0x18(%rsp), %rdi
callq 0x7540
addq $0x78, %r13
leaq 0x18(%rsp), %rbx
movq %r13, %rdi
movq %rbx, %rsi
callq 0x73c0
movq (%rbx), %rdi
cmpq %r14, %rdi
je 0x1f2d5
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x72f0
movq 0x34cbc(%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 0x1f33c
jmp 0x1f33c
movq %rax, %rbx
jmp 0x1f360
jmp 0x1f33c
jmp 0x1f33c
jmp 0x1f33c
movq %rax, %rbx
movq 0x34c52(%rip), %rsi     # 0x53f98
leaq 0x1f0(%rsp), %rdi
callq 0x7210
leaq 0x270(%rsp), %rdi
callq 0x7100
movq 0x34c31(%rip), %rsi     # 0x53f98
leaq 0x68(%rsp), %rdi
callq 0x7210
leaq 0xe8(%rsp), %rdi
callq 0x7100
movq %rbx, %rdi
callq 0x7600