// File: /workspace/github_cpp_makefile_star2_O3/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, %r14
movl $0x44494d4d, 0x4(%rsp)  # imm = 0x44494D4D
cmpl $0x2, %esi
je 0x19466e
cmpl $0x1, %esi
je 0x19462a
testl %esi, %esi
jne 0x1947f1
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 0x1947e9
jmp 0x1947f3
movl (%r14), %edi
callq 0x17fcf7
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 0x1490(%rip), %rsi      # 0x195ae6
movl %r14d, %edi
movq %rbx, %rdx
callq 0x108f2c
movq (%rbx), %rdi
callq 0x18002d
jmp 0x1947f3
leaq 0x30(%rsp), %rdi
movl $0xd8, %edx
xorl %esi, %esi
callq 0x20e0
cmpl $0x0, (%r14)
je 0x1947e0
xorl %ecx, %ecx
leaq 0x101b9e(%rip), %r12    # 0x296230
movq %rbx, 0x18(%rsp)
movq %r14, 0x10(%rsp)
movq 0x8(%rbx), %rax
movq %rcx, 0x8(%rsp)
leaq (%rcx,%rcx,2), %r13
shlq $0x4, %r13
leaq (%rax,%r13), %rcx
cmpq $0x0, 0x8(%rax,%r13)
je 0x1947b6
movl $0x18, %r15d
xorl %ebp, %ebp
movq %r13, 0x20(%rsp)
movq (%rcx), %rsi
movq (%rsi,%r15), %rax
movq %rax, %rdx
shrq $0x20, %rdx
addl %edx, %edx
addq 0x28(%rcx), %rdx
movq %rdx, 0xe8(%rsp)
movl %eax, %ecx
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
movq %rcx, 0xe0(%rsp)
movq %rcx, 0xd8(%rsp)
movq 0x10(%r14), %rdi
movq 0x40(%r12), %r11
movq -0x18(%rsi,%r15), %r10
movl %r10d, %ecx
movq %rcx, 0x28(%rsp)
shrq $0x20, %r10
movq (%r11,%r10,8), %r14
movq 0x8(%r12), %r9
movq 0x18(%r12), %rbx
leaq (%r9,%r14), %rdx
movl 0x8(%r11,%r10,8), %ecx
subl %r14d, %ecx
movl -0xc(%rsi,%r15), %r14d
movq (%r11,%r14,8), %r13
addq %r13, %r9
leal 0x1(%r14), %r12d
movl (%r11,%r12,8), %r11d
subl %r13d, %r11d
movl -0x10(%rsi,%r15), %r12d
movl -0x8(%rsi,%r15), %r13d
movl -0x4(%rsi,%r15), %esi
shrl $0x1f, %eax
leaq 0x4(%rsp), %r8
pushq %r8
leaq 0x38(%rsp), %r8
pushq %r8
pushq %rax
pushq (%rbx,%r14,8)
movq 0x30(%rsp), %r14
pushq %rsi
pushq %r13
movq 0x50(%rsp), %r13
pushq (%rbx,%r10,8)
movq 0x50(%rsp), %rbx
pushq %r12
leaq 0x101aa3(%rip), %r12    # 0x296230
pushq 0x68(%rsp)
pushq %r11
callq 0x1943af
addq $0x50, %rsp
incq %rbp
movq 0x8(%rbx), %rax
leaq (%rax,%r13), %rcx
addq $0x28, %r15
cmpq 0x8(%rax,%r13), %rbp
jb 0x1946ca
movq (%rcx), %rdi
callq 0x2220
movq 0x8(%rbx), %rax
movq 0x28(%rax,%r13), %rdi
callq 0x2220
movq 0x8(%rsp), %rcx
incq %rcx
movl (%r14), %eax
cmpq %rax, %rcx
jb 0x19469c
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