// File: chhylp123[P]hifiasm/Correct.cpp
// Function: cigar_gen_by_chain(overlap_region*, Chain_Data*, k_mer_hit*, long, ul_ov_t*, long, unsigned long, ul_idx_t const*, hpc_t*, All_reads*, char*, UC_Read*, bit_extz_t*, double, long, unsigned long)
void cigar_gen_by_chain(overlap_region *z, Chain_Data *dp, k_mer_hit *ch_a, int64_t ch_n, ul_ov_t *ov, int64_t on, uint64_t wl,  
const ul_idx_t *uref, hpc_t *hpc_g, All_reads *rref, char* qstr, UC_Read *tu, bit_extz_t *exz, double e_rate, 
int64_t ql, uint64_t rid)
{
    if(on <= 0) return;
    int64_t i, ch_i, tl, id = z->y_id; uint64_t pe = (uint64_t)-1;
    if(hpc_g) tl = hpc_len(*hpc_g, id);
    else if(uref) tl = uref->ug->u.a[id].len;
    else tl = Get_READ_LENGTH((*rref), id);
    // for (i = 0; i < wn; i++) z->w_list.a[i].clen = 0;///clean cigar
    // if(on > 1) {
    //     fprintf(stderr, "[M::%s::] rid::%lu, on::%ld\n", __func__, rid, on);
    // }
    // if(z->y_id == 126) prt_k_mer_hit(ch_a, ch_n);
    for (i = ch_i = 0; i < on; i++) {
        assert((i<=0)||(ov[i].qs > ov[i-1].qe));
        ch_i = sub_base_aln(z, dp, ch_a, ch_n, pe, ov[i].qs, ov[i].qe, wl, uref, hpc_g, rref, qstr, tu, exz, e_rate, ql, tl, ch_i, rid);
        pe = ov[i].qe;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq 0x50(%rbp), %rax
movq 0x48(%rbp), %rax
movq 0x40(%rbp), %rax
movq 0x38(%rbp), %rax
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x30(%rbp)
movq %rsi, -0x38(%rbp)
movq %rdx, -0x40(%rbp)
movq %rcx, -0x48(%rbp)
movq %r8, -0x50(%rbp)
movq %r9, -0x58(%rbp)
movsd %xmm0, -0x60(%rbp)
cmpq $0x0, -0x58(%rbp)
jg 0x63621
jmp 0x63843
movq -0x30(%rbp), %rax
movl 0x10(%rax), %eax
movq %rax, -0x80(%rbp)
movq $-0x1, -0x88(%rbp)
cmpq $0x0, 0x20(%rbp)
je 0x63662
movq 0x20(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x80(%rbp), %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
sarl %eax
cltq
movq %rax, -0x78(%rbp)
jmp 0x636a1
cmpq $0x0, 0x18(%rbp)
je 0x6368b
movq 0x18(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x80(%rbp), %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movq %rax, -0x78(%rbp)
jmp 0x6369f
movq 0x28(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x80(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x78(%rbp)
jmp 0x636a1
movq $0x0, -0x70(%rbp)
movq $0x0, -0x68(%rbp)
movq -0x68(%rbp), %rax
cmpq -0x58(%rbp), %rax
jge 0x63843
movb $0x1, %al
cmpq $0x0, -0x68(%rbp)
movb %al, -0x89(%rbp)
jle 0x636fc
movq -0x50(%rbp), %rax
imulq $0x1c, -0x68(%rbp), %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movq -0x50(%rbp), %rcx
movq -0x68(%rbp), %rdx
subq $0x1, %rdx
imulq $0x1c, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x8(%rcx), %eax
seta %al
movb %al, -0x89(%rbp)
movb -0x89(%rbp), %al
testb $0x1, %al
jne 0x63708
jmp 0x6370a
jmp 0x63729
leaq 0x31fd3d(%rip), %rdi    # 0x38344e
leaq 0x31ec03(%rip), %rsi    # 0x38231b
movl $0x409c, %edx           # imm = 0x409C
leaq 0x320370(%rip), %rcx    # 0x383a94
callq 0x2130
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x48(%rbp), %rcx
movq -0x88(%rbp), %r8
movq -0x50(%rbp), %rax
imulq $0x1c, -0x68(%rbp), %r9
addq %r9, %rax
movl 0x4(%rax), %eax
movl %eax, %r9d
movq -0x50(%rbp), %rax
imulq $0x1c, -0x68(%rbp), %r10
addq %r10, %rax
movl 0x8(%rax), %eax
movq %rax, -0xb8(%rbp)
movq 0x10(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq 0x18(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq 0x20(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq 0x28(%rbp), %r13
movq 0x30(%rbp), %r12
movq 0x38(%rbp), %r15
movq 0x40(%rbp), %r14
movsd -0x60(%rbp), %xmm0
movq 0x48(%rbp), %rbx
movq -0x78(%rbp), %r11
movq -0x70(%rbp), %r10
movq 0x50(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0xb8(%rbp), %rax
movq %rax, (%rsp)
movq -0xb0(%rbp), %rax
movq %rax, 0x8(%rsp)
movq -0xa8(%rbp), %rax
movq %rax, 0x10(%rsp)
movq -0xa0(%rbp), %rax
movq %rax, 0x18(%rsp)
movq -0x98(%rbp), %rax
movq %r13, 0x20(%rsp)
movq %r12, 0x28(%rsp)
movq %r15, 0x30(%rsp)
movq %r14, 0x38(%rsp)
movq %rbx, 0x40(%rsp)
movq %r11, 0x48(%rsp)
movq %r10, 0x50(%rsp)
movq %rax, 0x58(%rsp)
callq 0x62f10
movq %rax, -0x70(%rbp)
movq -0x50(%rbp), %rax
imulq $0x1c, -0x68(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movq %rax, -0x88(%rbp)
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
jmp 0x636b1
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopw %cs:(%rax,%rax)