// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/ecovlp.cpp
// Function: worker_ov_dbg_pipeline(void*, int, void*)
static void *worker_ov_dbg_pipeline(void *data, int step, void *in) // callback for kt_pipeline()
{
    cal_ec_r_dbg_t *p = (cal_ec_r_dbg_t*)data; char cm[4]; cm[0] = 'M'; cm[1] = 'M'; cm[2] = 'I'; cm[3] = 'D'; 
    // cal_ec_r_dbg_step_t
    if (step == 0) { // step 1: read a block of sequences
        cal_ec_r_dbg_step_t *s; CALLOC(s, 1);
        s->si = p->cn; p->cn += p->chunk_size; 
        if(p->cn > p->n_a) p->cn = p->n_a; s->ei = p->cn;
        if(s->si >= s->ei) free(s);
        else return s;
    } else if (step == 1) { // step 2: alignment
        cal_ec_r_dbg_step_t *s = (cal_ec_r_dbg_step_t*)in;
        s->buf = gen_ec_ovec_buf_t(p->n_thread); CALLOC(s->res, p->n_thread);  
        kt_for(p->n_thread, worker_hap_ec_dbg_paf, s, (s->ei - s->si));
        destroy_ec_ovec_buf_t(s->buf);
        return s;
    } else if (step == 2) { // step 3: dump
        cal_ec_r_dbg_step_t *s = (cal_ec_r_dbg_step_t*)in; uint64_t k, z; bit_extz_t ez; memset(&ez, 0, sizeof(ez));
        // UC_Read qu; UC_Read tu; init_UC_Read(&qu); init_UC_Read(&tu); 
        for (k = 0; k < p->n_thread; k++) {
            for (z = 0; z < s->res[k].n; z++) {
                ez.cigar.a = s->res[k].ec.a + s->res[k].a[z].bl; ez.cigar.n = ez.cigar.m = s->res[k].a[z].cc;

                // UC_Read_resize(qu, (s->res[k].a[z].qe - ((uint32_t)s->res[k].a[z].qns))); 
                // recover_UC_Read_sub_region(qu.seq, ((uint32_t)s->res[k].a[z].qns), (s->res[k].a[z].qe - ((uint32_t)s->res[k].a[z].qns)), 0, &R_INF, (s->res[k].a[z].qns>>32));

                // UC_Read_resize(tu, (s->res[k].a[z].te - s->res[k].a[z].ts));
                // recover_UC_Read_sub_region(tu.seq, s->res[k].a[z].ts, s->res[k].a[z].te - s->res[k].a[z].ts, 0, &R_INF, s->res[k].a[z].tn); 

                print_ov_dbg_paf(p->fp, NULL/**qu.seq**/, Get_NAME(R_INF, (s->res[k].a[z].qns>>32)), Get_NAME_LENGTH(R_INF, (s->res[k].a[z].qns>>32)), 
                            NULL/**tu.seq**/, Get_NAME(R_INF, (s->res[k].a[z].tn)), Get_NAME_LENGTH(R_INF, (s->res[k].a[z].tn)), (uint32_t)s->res[k].a[z].qns, s->res[k].a[z].qe, Get_READ_LENGTH(R_INF, (s->res[k].a[z].qns>>32)), s->res[k].a[z].ts, s->res[k].a[z].te, Get_READ_LENGTH(R_INF, (s->res[k].a[z].tn)), s->res[k].a[z].rev, &ez, cm);
            }
            free(s->res[k].a); free(s->res[k].ec.a);
        }
        free(s->res); free(s); ///destory_UC_Read(&qu); destory_UC_Read(&tu);
    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %rdx, %rbx
movq %rdi, (%rsp)
movl $0x44494d4d, 0xc(%rsp)  # imm = 0x44494D4D
cmpl $0x2, %esi
je 0x14dcb4
cmpl $0x1, %esi
je 0x14dc6e
testl %esi, %esi
jne 0x14de18
pushq $0x1
popq %rdi
pushq $0x18
popq %rsi
callq 0x2120
movq %rax, %rbx
movq (%rsp), %rsi
movl 0xc(%rsi), %eax
movl %eax, 0x10(%rbx)
movl 0x8(%rsi), %ecx
addl %eax, %ecx
movl 0x4(%rsi), %edx
cmpl %edx, %ecx
cmovael %edx, %ecx
movl %ecx, 0xc(%rsi)
movl %ecx, 0x14(%rbx)
cmpl %ecx, %eax
jae 0x14de10
jmp 0x14de1a
movq (%rsp), %r14
movl (%r14), %edi
callq 0x13d062
movq %rax, (%rbx)
movl (%r14), %r14d
pushq $0x30
popq %rsi
movq %r14, %rdi
callq 0x2120
movq %rax, 0x8(%rbx)
movl 0x14(%rbx), %ecx
subl 0x10(%rbx), %ecx
leaq 0xe5f(%rip), %rsi       # 0x14eafb
movl %r14d, %edi
movq %rbx, %rdx
callq 0xc67c0
movq (%rbx), %rdi
callq 0x13d1f3
jmp 0x14de1a
leaq 0x30(%rsp), %rdi
xorl %r14d, %r14d
movl $0xd8, %edx
xorl %esi, %esi
callq 0x20e0
movq %rbx, 0x20(%rsp)
movq (%rsp), %rax
movl (%rax), %eax
cmpq %rax, %r14
jae 0x14de07
movq %r14, 0x18(%rsp)
imulq $0x30, %r14, %rax
movq %rax, 0x10(%rsp)
pushq $0x18
popq %r15
xorl %esi, %esi
movq 0x8(%rbx), %rax
movq 0x10(%rsp), %rdx
leaq (%rax,%rdx), %rcx
cmpq 0x8(%rax,%rdx), %rsi
jae 0x14dddf
movq (%rcx), %rax
movl 0x4(%rax,%r15), %edx
addl %edx, %edx
addq 0x28(%rcx), %rdx
movq %rdx, 0xe8(%rsp)
movq (%rax,%r15), %rcx
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
movq %rcx, 0xe0(%rsp)
movq %rcx, 0xd8(%rsp)
movq (%rsp), %rcx
movq 0x10(%rcx), %rdi
leaq 0x1064e9(%rip), %rcx    # 0x254230
movq 0x40(%rcx), %r10
movq -0x18(%rax,%r15), %r8
movl %r8d, %edx
movq %rdx, 0x28(%rsp)
shrq $0x20, %r8
movq (%r10,%r8,8), %rbx
movq 0x8(%rcx), %r9
movq 0x18(%rcx), %r11
leaq (%r9,%rbx), %rdx
movl 0x8(%r10,%r8,8), %ecx
subl %ebx, %ecx
movl -0xc(%rax,%r15), %ebx
movq (%r10,%rbx,8), %r14
addq %r14, %r9
leal 0x1(%rbx), %ebp
movl (%r10,%rbp,8), %r10d
subl %r14d, %r10d
movl -0x10(%rax,%r15), %r13d
movl -0x8(%rax,%r15), %ebp
movl -0x4(%rax,%r15), %r12d
movl (%rax,%r15), %eax
shrl $0x1f, %eax
movq %rsi, %r14
leaq 0xc(%rsp), %rsi
pushq %rsi
leaq 0x38(%rsp), %rsi
pushq %rsi
pushq %rax
pushq (%r11,%rbx,8)
movq 0x40(%rsp), %rbx
pushq %r12
pushq %rbp
pushq (%r11,%r8,8)
pushq %r13
pushq 0x68(%rsp)
pushq %r10
callq 0x14da45
movq %r14, %rsi
addq $0x50, %rsp
incq %rsi
addq $0x28, %r15
jmp 0x14dcf0
movq (%rcx), %rdi
callq 0x2220
movq 0x8(%rbx), %rax
movq 0x10(%rsp), %rcx
movq 0x28(%rax,%rcx), %rdi
callq 0x2220
movq 0x18(%rsp), %r14
incq %r14
jmp 0x14dccd
movq 0x8(%rbx), %rdi
callq 0x2220
movq %rbx, %rdi
callq 0x2220
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq