// File: chhylp123[P]hifiasm/Correct.cpp
// Function: prt_sub_cigar(overlap_region*, unsigned long, unsigned long, unsigned long)
void prt_sub_cigar(overlap_region* z, uint64_t str_l, uint64_t site, uint64_t win)
{
    uint64_t k, s, e, ci, xi, yi, ws, we, os, oe, ovlp; uint32_t cl; uint16_t c; bit_extz_t ez; char cm[4]; 
    cm[0] = 'M'; cm[1] = 'S'; cm[2] = 'I'; cm[3] = 'D';  
    s = ((site >= win)?(site-win):(0)); 
    e = (((site+win+1) <= str_l)?(site+win+1):(str_l));

    fprintf(stderr, "[M::%s-site::%lu] [%lu, %lu)\n", __func__, site, s, e);

    for (k = 0; k < z->w_list.n; k++) {
        set_bit_extz_t(ez, (*z), k); ci = 0; xi = ez.ts; yi = ez.ps;
        while (ci < ez.cigar.n) {
            ws = xi;
            ci = pop_trace(&(ez.cigar), ci, &c, &cl);
            if(c!=2) xi += cl;
            if(c!=3) yi += cl; 
            we = xi; 

            os = MAX(s, ws); oe = MIN(e, we);
            ovlp = ((oe>os)? (oe-os):0);

            if(c != 2) {
                if(!ovlp) continue;
            } else {///ws == we
                if(ws < s || ws >= e) continue;
                ovlp = cl;
            }

            fprintf(stderr, "%lu%c[%lu,%lu)", ovlp, cm[c], os, oe);
        }
        fprintf(stderr, "\n");
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x190, %rsp            # imm = 0x190
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movb $0x4d, -0x15c(%rbp)
movb $0x53, -0x15b(%rbp)
movb $0x49, -0x15a(%rbp)
movb $0x44, -0x159(%rbp)
movq -0x18(%rbp), %rax
cmpq -0x20(%rbp), %rax
jb 0x41ba2
movq -0x18(%rbp), %rax
subq -0x20(%rbp), %rax
movq %rax, -0x168(%rbp)
jmp 0x41bad
xorl %eax, %eax
movq %rax, -0x168(%rbp)
jmp 0x41bad
movq -0x168(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
addq -0x20(%rbp), %rax
addq $0x1, %rax
cmpq -0x10(%rbp), %rax
ja 0x41bdf
movq -0x18(%rbp), %rax
addq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x170(%rbp)
jmp 0x41bea
movq -0x10(%rbp), %rax
movq %rax, -0x170(%rbp)
movq -0x170(%rbp), %rax
movq %rax, -0x38(%rbp)
movq 0x3823e4(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movq -0x18(%rbp), %rcx
movq -0x30(%rbp), %r8
movq -0x38(%rbp), %r9
leaq 0x340c71(%rip), %rsi    # 0x382883
leaq 0x340c9a(%rip), %rdx    # 0x3828b3
movb $0x0, %al
callq 0x22a0
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x48(%rcx), %rax
jae 0x41ee2
jmp 0x41c3c
movq -0x8(%rbp), %rax
movq 0x70(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x58(%rcx), %rcx
movq -0x28(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rcx
movl 0x18(%rcx), %ecx
shlq %rcx
addq %rcx, %rax
movq %rax, -0xa0(%rbp)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x28(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x1c(%rax), %eax
movq %rax, -0xa8(%rbp)
movq %rax, -0xb0(%rbp)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x28(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl (%rax), %eax
movl %eax, -0x13c(%rbp)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x28(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, -0x138(%rbp)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x28(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x148(%rbp)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x28(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
movl %eax, -0x144(%rbp)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x28(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movswl 0x14(%rax), %eax
movl %eax, -0x12c(%rbp)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x28(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movswl 0x14(%rax), %eax
movl %eax, -0x130(%rbp)
movq $0x0, -0x40(%rbp)
movslq -0x13c(%rbp), %rax
movq %rax, -0x48(%rbp)
movslq -0x148(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x40(%rbp), %rax
cmpq -0xb0(%rbp), %rax
jae 0x41eb9
movq -0x48(%rbp), %rax
movq %rax, -0x58(%rbp)
leaq -0x158(%rbp), %rdi
addq $0xa8, %rdi
movq -0x40(%rbp), %rax
movl %eax, %esi
leaq -0x7e(%rbp), %rdx
leaq -0x7c(%rbp), %rcx
callq 0xa1ee0
movl %eax, %eax
movq %rax, -0x40(%rbp)
movzwl -0x7e(%rbp), %eax
cmpl $0x2, %eax
je 0x41da6
movl -0x7c(%rbp), %eax
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movzwl -0x7e(%rbp), %eax
cmpl $0x3, %eax
je 0x41dba
movl -0x7c(%rbp), %eax
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x58(%rbp), %rax
jb 0x41dd9
movq -0x30(%rbp), %rax
movq %rax, -0x178(%rbp)
jmp 0x41de4
movq -0x58(%rbp), %rax
movq %rax, -0x178(%rbp)
movq -0x178(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x60(%rbp), %rax
ja 0x41e06
movq -0x38(%rbp), %rax
movq %rax, -0x180(%rbp)
jmp 0x41e11
movq -0x60(%rbp), %rax
movq %rax, -0x180(%rbp)
movq -0x180(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
cmpq -0x68(%rbp), %rax
jbe 0x41e37
movq -0x70(%rbp), %rax
subq -0x68(%rbp), %rax
movq %rax, -0x188(%rbp)
jmp 0x41e42
xorl %eax, %eax
movq %rax, -0x188(%rbp)
jmp 0x41e42
movq -0x188(%rbp), %rax
movq %rax, -0x78(%rbp)
movzwl -0x7e(%rbp), %eax
cmpl $0x2, %eax
je 0x41e64
cmpq $0x0, -0x78(%rbp)
jne 0x41e62
jmp 0x41d52
jmp 0x41e84
movq -0x58(%rbp), %rax
cmpq -0x30(%rbp), %rax
jb 0x41e78
movq -0x58(%rbp), %rax
cmpq -0x38(%rbp), %rax
jb 0x41e7d
jmp 0x41d52
movl -0x7c(%rbp), %eax
movq %rax, -0x78(%rbp)
movq 0x382155(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movq -0x78(%rbp), %rdx
movzwl -0x7e(%rbp), %eax
movsbl -0x15c(%rbp,%rax), %ecx
movq -0x68(%rbp), %r8
movq -0x70(%rbp), %r9
leaq 0x340a14(%rip), %rsi    # 0x3828c1
movb $0x0, %al
callq 0x22a0
jmp 0x41d52
movq 0x382120(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x344b5e(%rip), %rsi    # 0x386a28
movb $0x0, %al
callq 0x22a0
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x41c28
addq $0x190, %rsp            # imm = 0x190
popq %rbp
retq
nopl (%rax,%rax)