// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/hic.cpp
// Function: worker_pipeline(void*, int, void*)
static void *worker_pipeline(void *data, int step, void *in) // callback for kt_pipeline()
{
    sldat_t *p = (sldat_t*)data;
    ///uint64_t total_base = 0, total_pair = 0;
    if (step == 0) { // step 1: read a block of sequences
        int ret1, ret2;
        uint64_t l1, l2;
		stepdat_t *s;
		CALLOC(s, 1);
        s->idx = p->idx; s->id = p->total_pair; s->t_ch = p->t_ch;
        while (((ret1 = kseq_read(p->ks1)) >= 0)&&((ret2 = kseq_read(p->ks2)) >= 0)) 
        {
            if (p->ks1->seq.l < p->idx->k || p->ks2->seq.l < p->idx->k) continue;
            if (s->n == s->m) {
                s->m = s->m < 16? 16 : s->m + (s->n>>1);
                REALLOC(s->len, s->m);
                REALLOC(s->seq, s->m);
            }

            l1 = p->ks1->seq.l; l2 = p->ks2->seq.l;
            MALLOC(s->seq[s->n], l1+l2);
            s->sum_len += l1+l2;
            memcpy(s->seq[s->n], p->ks1->seq.s, l1);
            memcpy(s->seq[s->n]+l1, p->ks2->seq.s, l2);
            s->len[s->n++] = (uint64_t)(l1<<32)|(uint64_t)l2;

            if (s->sum_len >= p->chunk_size) break;            
        }
        p->total_pair += s->n;
        if (s->sum_len == 0) free(s);
		else return s;
    }
    else if (step == 1) { // step 2: alignment
        stepdat_t *s = (stepdat_t*)in;
        CALLOC(s->pos_buf, p->n_thread);
        CALLOC(s->pos, s->n);
        int i;
        kt_for(p->n_thread, worker_for_alignment, s, s->n);
        for (i = 0; i < s->n; ++i) {
            free(s->seq[i]);
            p->total_base += (s->len[i]>>32) + (uint32_t)s->len[i];
        }
        
        free(s->seq); free(s->len);
        for (i = 0; i < (int)p->n_thread; ++i) {
            free(s->pos_buf[i].a.a);
        }
        free(s->pos_buf);
		return s;
    }
    else if (step == 2) { // step 3: dump
        stepdat_t *s = (stepdat_t*)in;
        int i;
        for (i = 0; i < s->n; ++i) {
            // if(s->pos[i].a == NULL) continue;
            // kv_push(pe_hit_hap, p->hits, s->pos[i]);
            if(s->pos[i].s == (uint64_t)-1) continue;
            kv_push(pe_hit, p->hits.a, s->pos[i]);
        }
        free(s->pos);
        free(s);
    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
testl %esi, %esi
je 0x156f5e
movq %rdx, %r14
cmpl $0x1, %esi
je 0x156ea0
cmpl $0x2, %esi
jne 0x1570b3
cmpl $0x0, 0x8(%r14)
jle 0x156e8f
xorl %r15d, %r15d
movl $0x2, %r12d
xorl %r13d, %r13d
movq 0x40(%r14), %rax
cmpq $-0x1, (%rax,%r15)
je 0x156e7f
movq 0x40(%rbx), %rax
cmpq %rax, 0x38(%rbx)
jne 0x156e53
leaq (%rax,%rax), %rsi
testq %rax, %rax
cmoveq %r12, %rsi
movq %rsi, 0x40(%rbx)
movq 0x48(%rbx), %rdi
shlq $0x5, %rsi
callq 0x2370
movq %rax, 0x48(%rbx)
movq 0x40(%r14), %rax
movq 0x38(%rbx), %rcx
movq 0x48(%rbx), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x38(%rbx)
shlq $0x5, %rcx
movups (%rax,%r15), %xmm0
movups 0x10(%rax,%r15), %xmm1
movups %xmm1, 0x10(%rdx,%rcx)
movups %xmm0, (%rdx,%rcx)
incq %r13
movslq 0x8(%r14), %rax
addq $0x20, %r15
cmpq %rax, %r13
jl 0x156e1e
movq 0x40(%r14), %rdi
callq 0x2220
movq %r14, %r15
jmp 0x1570a3
movq 0x20(%rbx), %r15
movl $0x18, %esi
movq %r15, %rdi
callq 0x2120
movq %rax, 0x38(%r14)
movslq 0x8(%r14), %r12
movl $0x20, %esi
movq %r12, %rdi
callq 0x2120
movq %rax, 0x40(%r14)
leaq 0x8252(%rip), %rsi      # 0x15f123
movl %r15d, %edi
movq %r14, %rdx
movq %r12, %rcx
callq 0x1047b4
cmpl $0x0, 0x8(%r14)
jle 0x156f17
xorl %r15d, %r15d
movq 0x28(%r14), %rax
movq (%rax,%r15,8), %rdi
callq 0x2220
movq 0x18(%r14), %rax
movq (%rax,%r15,8), %rax
movl %eax, %ecx
shrq $0x20, %rax
addq %rax, %rcx
addq %rcx, 0x28(%rbx)
incq %r15
movslq 0x8(%r14), %rax
cmpq %rax, %r15
jl 0x156ee9
movq 0x28(%r14), %rdi
callq 0x2220
movq 0x18(%r14), %rdi
callq 0x2220
cmpl $0x0, 0x20(%rbx)
jle 0x156f55
movl $0x10, %r15d
xorl %r12d, %r12d
movq 0x38(%r14), %rax
movq (%rax,%r15), %rdi
callq 0x2220
incq %r12
movslq 0x20(%rbx), %rax
addq $0x18, %r15
cmpq %rax, %r12
jl 0x156f38
movq 0x38(%r14), %r15
jmp 0x1570a6
movl $0x1, %edi
movl $0x50, %esi
callq 0x2120
movq %rax, %r15
movq (%rbx), %rax
movq %rax, (%r15)
movq 0x30(%rbx), %rax
movq %rax, 0x20(%r15)
movq 0x90(%rbx), %rax
movq %rax, 0x48(%r15)
movq 0x8(%rbx), %rdi
callq 0x137aea
testl %eax, %eax
js 0x157094
movq 0x10(%rbx), %rdi
callq 0x137aea
testl %eax, %eax
js 0x157094
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
movq 0x40(%rax), %rax
cmpq %rax, 0x30(%rcx)
jb 0x156f89
movq 0x10(%rbx), %rcx
cmpq %rax, 0x30(%rcx)
jb 0x156f89
movslq 0x8(%r15), %r13
movl 0xc(%r15), %eax
cmpl %eax, %r13d
jne 0x157010
movl %r13d, %ecx
sarl %ecx
addl %eax, %ecx
cmpl $0x10, %eax
movl $0x10, %eax
cmovll %eax, %ecx
movl %ecx, 0xc(%r15)
movq 0x18(%r15), %rdi
movslq %ecx, %r14
shlq $0x3, %r14
movq %r14, %rsi
callq 0x2370
movq %rax, 0x18(%r15)
movq 0x28(%r15), %rdi
movq %r14, %rsi
callq 0x2370
movq %rax, 0x28(%r15)
movq 0x8(%rbx), %rax
movq 0x10(%rbx), %rcx
movq 0x30(%rax), %r14
movq 0x30(%rcx), %rax
movq %rax, (%rsp)
leaq (%rax,%r14), %r12
movq %r12, %rdi
callq 0x2280
movq 0x28(%r15), %rbp
movq %rax, (%rbp,%r13,8)
addl 0x10(%r15), %r12d
movl %r12d, 0x10(%r15)
movq 0x8(%rbx), %rcx
movq 0x40(%rcx), %rsi
movq %rax, %rdi
movq %r14, %rdx
callq 0x2160
movq (%rbp,%r13,8), %rdi
addq %r14, %rdi
movq 0x10(%rbx), %rax
movq 0x40(%rax), %rsi
movq (%rsp), %rbp
movq %rbp, %rdx
callq 0x2160
shlq $0x20, %r14
orq %rbp, %r14
movq 0x18(%r15), %rax
leal 0x1(%r13), %ecx
movl %ecx, 0x8(%r15)
movq %r14, (%rax,%r13,8)
movslq %r12d, %rax
cmpq %rax, 0x18(%rbx)
jg 0x156f89
movslq 0x8(%r15), %rax
addq %rax, 0x30(%rbx)
cmpl $0x0, 0x10(%r15)
jne 0x1570b6
xorl %r14d, %r14d
movq %r15, %rdi
callq 0x2220
movq %r14, %r15
jmp 0x1570b6
xorl %r15d, %r15d
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq