// File: /workspace/github_cpp_makefile_star2_O1/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 $0x118, %rsp            # imm = 0x118
movq %rdx, %rbx
movq %rdi, %r14
movl $0x44494d4d, 0xc(%rsp)  # imm = 0x44494D4D
cmpl $0x2, %esi
je 0x18bdfe
cmpl $0x1, %esi
je 0x18bdba
testl %esi, %esi
jne 0x18bf89
movl $0x1, %edi
movl $0x18, %esi
callq 0x2120
movq %rax, %rbx
movl 0xc(%r14), %eax
movl %eax, 0x10(%rbx)
movl 0x8(%r14), %ecx
addl %eax, %ecx
movl 0x4(%r14), %edx
cmpl %edx, %ecx
cmovael %edx, %ecx
movl %ecx, 0xc(%r14)
movl %ecx, 0x14(%rbx)
cmpl %ecx, %eax
jae 0x18bf81
jmp 0x18bf8b
movl (%r14), %edi
callq 0x179027
movq %rax, (%rbx)
movl (%r14), %r14d
movl $0x30, %esi
movq %r14, %rdi
callq 0x2120
movq %rax, 0x8(%rbx)
movl 0x14(%rbx), %ecx
subl 0x10(%rbx), %ecx
leaq 0xeda(%rip), %rsi       # 0x18ccc0
movl %r14d, %edi
movq %rbx, %rdx
callq 0x1047b4
movq (%rbx), %rdi
callq 0x1793c1
jmp 0x18bf8b
leaq 0x40(%rsp), %rdi
movl $0xd8, %edx
xorl %esi, %esi
callq 0x20e0
cmpl $0x0, (%r14)
je 0x18bf78
xorl %ecx, %ecx
leaq 0xff40e(%rip), %r12     # 0x28b230
movq %r14, 0x20(%rsp)
movq %rbx, 0x18(%rsp)
movq 0x8(%rbx), %rax
movq %rcx, 0x10(%rsp)
leaq (%rcx,%rcx,2), %r13
shlq $0x4, %r13
leaq (%rax,%r13), %rcx
cmpq $0x0, 0x8(%rax,%r13)
je 0x18bf4e
movl $0x18, %r15d
xorl %ebp, %ebp
movq %r13, 0x28(%rsp)
movq (%rcx), %rax
movq (%rax,%r15), %rdx
movq %rdx, %rsi
shrq $0x20, %rsi
addl %esi, %esi
addq 0x28(%rcx), %rsi
movq %rsi, 0xf8(%rsp)
andl $0x3fffffff, %edx       # imm = 0x3FFFFFFF
movq %rdx, 0xf0(%rsp)
movq %rdx, 0xe8(%rsp)
movq 0x10(%r14), %rdi
movq 0x40(%r12), %r10
movq -0x18(%rax,%r15), %r8
movl %r8d, %ecx
movq %rcx, 0x38(%rsp)
shrq $0x20, %r8
movq (%r10,%r8,8), %rbx
movq 0x8(%r12), %r9
movq 0x18(%r12), %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), %r13d
movl (%r10,%r13,8), %r10d
subl %r14d, %r10d
movl -0x10(%rax,%r15), %esi
movq %rsi, 0x30(%rsp)
movl -0x8(%rax,%r15), %r13d
movq %r12, %rsi
movl -0x4(%rax,%r15), %r12d
movl (%rax,%r15), %eax
shrl $0x1f, %eax
leaq 0xc(%rsp), %r14
pushq %r14
leaq 0x48(%rsp), %r14
pushq %r14
pushq %rax
pushq (%r11,%rbx,8)
movq 0x38(%rsp), %rbx
pushq %r12
movq %rsi, %r12
pushq %r13
movq 0x58(%rsp), %r13
pushq (%r11,%r8,8)
pushq 0x68(%rsp)
movq 0x60(%rsp), %r14
pushq 0x78(%rsp)
pushq %r10
callq 0x18bb2c
addq $0x50, %rsp
incq %rbp
movq 0x8(%rbx), %rax
leaq (%rax,%r13), %rcx
addq $0x28, %r15
cmpq 0x8(%rax,%r13), %rbp
jb 0x18be5a
movq (%rcx), %rdi
callq 0x2220
movq 0x8(%rbx), %rax
movq 0x28(%rax,%r13), %rdi
callq 0x2220
movq 0x10(%rsp), %rcx
incq %rcx
movl (%r14), %eax
cmpq %rax, %rcx
jb 0x18be2c
movq 0x8(%rbx), %rdi
callq 0x2220
movq %rbx, %rdi
callq 0x2220
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq