// File: /workspace/github_cpp_makefile_star2_O2/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
subq $0x18, %rsp
movq %rdi, %r14
xorl %r13d, %r13d
testl %esi, %esi
je 0x11742b
movq %rdx, %rbx
cmpl $0x1, %esi
je 0x11737f
cmpl $0x2, %esi
jne 0x1175b5
xorl %r15d, %r15d
pushq $0x2
popq %r12
xorl %r13d, %r13d
movslq 0x8(%rbx), %rax
movq 0x40(%rbx), %rdi
cmpq %rax, %r13
jge 0x117597
cmpq $-0x1, (%rdi,%r15)
je 0x117376
movq 0x38(%r14), %rcx
movq 0x48(%r14), %rax
cmpq 0x40(%r14), %rcx
jne 0x117356
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
cmoveq %r12, %rsi
movq %rsi, 0x40(%r14)
shlq $0x5, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x48(%r14)
movq 0x40(%rbx), %rdi
movq 0x38(%r14), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x38(%r14)
shlq $0x5, %rcx
movups (%rdi,%r15), %xmm0
movups 0x10(%rdi,%r15), %xmm1
movups %xmm1, 0x10(%rax,%rcx)
movups %xmm0, (%rax,%rcx)
incq %r13
addq $0x20, %r15
jmp 0x117309
movq 0x20(%r14), %r15
pushq $0x18
popq %rsi
movq %r15, %rdi
callq 0x2120
movq %rax, 0x38(%rbx)
movslq 0x8(%rbx), %r12
pushq $0x20
popq %rsi
movq %r12, %rdi
callq 0x2120
movq %rax, 0x40(%rbx)
leaq 0x95d6(%rip), %rsi      # 0x120982
movl %r15d, %edi
movq %rbx, %rdx
movq %r12, %rcx
callq 0xc67c0
xorl %r15d, %r15d
movslq 0x8(%rbx), %rax
movq 0x28(%rbx), %rdi
cmpq %rax, %r15
jge 0x1173ed
movq (%rdi,%r15,8), %rdi
callq 0x2220
movq 0x18(%rbx), %rax
movq (%rax,%r15,8), %rax
movl %eax, %ecx
shrq $0x20, %rax
addq %rax, %rcx
addq %rcx, 0x28(%r14)
incq %r15
jmp 0x1173bd
callq 0x2220
movq 0x18(%rbx), %rdi
callq 0x2220
pushq $0x10
popq %r15
xorl %r12d, %r12d
movslq 0x20(%r14), %rax
movq 0x38(%rbx), %rdi
cmpq %rax, %r12
jge 0x117421
movq (%rdi,%r15), %rdi
callq 0x2220
incq %r12
addq $0x18, %r15
jmp 0x117402
callq 0x2220
jmp 0x1175b7
pushq $0x1
popq %rdi
pushq $0x50
popq %rsi
callq 0x2120
movq %rax, %rbx
movq (%r14), %rax
movq %rax, (%rbx)
movq 0x30(%r14), %rax
movq %rax, 0x20(%rbx)
movq 0x90(%r14), %rax
movq %rax, 0x48(%rbx)
movq $0x0, 0x10(%rsp)
xorl %ecx, %ecx
movl $0x0, 0x4(%rsp)
movl $0x0, (%rsp)
movq %rcx, 0x8(%rsp)
movq 0x8(%r14), %rdi
callq 0xf635b
testl %eax, %eax
js 0x11759e
movq 0x10(%r14), %rdi
callq 0xf635b
testl %eax, %eax
js 0x11759e
movq (%r14), %rax
movq 0x8(%r14), %rcx
movq 0x30(%rcx), %r12
movq 0x40(%rax), %rax
cmpq %rax, %r12
jb 0x117471
movq 0x10(%r14), %rcx
movq 0x30(%rcx), %r15
cmpq %rax, %r15
jb 0x117471
movl 0x4(%rsp), %eax
cmpl %eax, (%rsp)
jne 0x117514
movl %eax, %ebp
sarl %ebp
addl %eax, %ebp
cmpl $0x10, %eax
pushq $0x10
popq %rax
cmovll %eax, %ebp
movl %ebp, 0xc(%rbx)
movslq %ebp, %r15
shlq $0x3, %r15
movq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x2370
movq %rax, 0x18(%rbx)
movq 0x28(%rbx), %rdi
movq %r15, %rsi
callq 0x2370
movq %rax, 0x10(%rsp)
movq %rax, 0x28(%rbx)
movq 0x8(%r14), %rax
movq 0x10(%r14), %rcx
movq 0x30(%rax), %r12
movq 0x30(%rcx), %r15
movl 0x10(%rbx), %r13d
movl %ebp, 0x4(%rsp)
leaq (%r15,%r12), %rbp
movq %rbp, %rdi
callq 0x2280
movl (%rsp), %ecx
movq %rcx, 0x8(%rsp)
movq 0x10(%rsp), %rdx
movq %rax, (%rdx,%rcx,8)
addl %r13d, %ebp
movl %ebp, 0x10(%rbx)
movq 0x8(%r14), %rcx
movq 0x40(%rcx), %rsi
movq %rax, %rdi
movq %r12, %rdx
callq 0x2160
movq 0x8(%rsp), %r13
movq 0x10(%rsp), %rax
movq (%rax,%r13,8), %rdi
addq %r12, %rdi
movq 0x10(%r14), %rax
movq 0x40(%rax), %rsi
movq %r15, %rdx
callq 0x2160
shlq $0x20, %r12
orq %r15, %r12
movq 0x18(%rbx), %rcx
movl (%rsp), %eax
incl %eax
movl %eax, (%rsp)
movl %eax, 0x8(%rbx)
movq %r12, (%rcx,%r13,8)
movslq %ebp, %rax
movl %ebp, %r13d
cmpq %rax, 0x18(%r14)
jg 0x11746c
jmp 0x1175a1
callq 0x2220
jmp 0x1175ad
movl %r13d, %ebp
movslq (%rsp), %rax
addq %rax, 0x30(%r14)
testl %ebp, %ebp
jne 0x1175b7
movq %rbx, %rdi
callq 0x2220
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq