// File: /workspace/github_c_makefile_star2_O2/lh3[P]minimap2/index.c
// Function: worker_pipeline
static void *worker_pipeline(void *shared, int step, void *in)
{
	int i;
    pipeline_t *p = (pipeline_t*)shared;
    if (step == 0) { // step 0: read sequences
        step_t *s;
		if (p->sum_len > p->batch_size) return 0;
        s = (step_t*)calloc(1, sizeof(step_t));
		s->seq = mm_bseq_read(p->fp, p->mini_batch_size, 0, &s->n_seq); // read a mini-batch
		if (s->seq) {
			uint32_t old_m, m;
			assert((uint64_t)p->mi->n_seq + s->n_seq <= UINT32_MAX); // to prevent integer overflow
			// make room for p->mi->seq
			old_m = p->mi->n_seq, m = p->mi->n_seq + s->n_seq;
			kroundup32(m); kroundup32(old_m);
			if (old_m != m)
				p->mi->seq = (mm_idx_seq_t*)krealloc(p->mi->km, p->mi->seq, m * sizeof(mm_idx_seq_t));
			// make room for p->mi->S
			if (!(p->mi->flag & MM_I_NO_SEQ)) {
				uint64_t sum_len, old_max_len, max_len;
				for (i = 0, sum_len = 0; i < s->n_seq; ++i) sum_len += s->seq[i].l_seq;
				old_max_len = (p->sum_len + 7) / 8;
				max_len = (p->sum_len + sum_len + 7) / 8;
				kroundup64(old_max_len); kroundup64(max_len);
				if (old_max_len != max_len) {
					p->mi->S = (uint32_t*)realloc(p->mi->S, max_len * 4);
					memset(&p->mi->S[old_max_len], 0, 4 * (max_len - old_max_len));
				}
			}
			// populate p->mi->seq
			for (i = 0; i < s->n_seq; ++i) {
				mm_idx_seq_t *seq = &p->mi->seq[p->mi->n_seq];
				uint32_t j;
				if (!(p->mi->flag & MM_I_NO_NAME)) {
					seq->name = (char*)kmalloc(p->mi->km, strlen(s->seq[i].name) + 1);
					strcpy(seq->name, s->seq[i].name);
				} else seq->name = 0;
				seq->len = s->seq[i].l_seq;
				seq->offset = p->sum_len;
				seq->is_alt = 0;
				// copy the sequence
				if (!(p->mi->flag & MM_I_NO_SEQ)) {
					for (j = 0; j < seq->len; ++j) { // TODO: this is not the fastest way, but let's first see if speed matters here
						uint64_t o = p->sum_len + j;
						int c = seq_nt4_table[(uint8_t)s->seq[i].seq[j]];
						mm_seq4_set(p->mi->S, o, c);
					}
				}
				// update p->sum_len and p->mi->n_seq
				p->sum_len += seq->len;
				s->seq[i].rid = p->mi->n_seq++;
			}
			return s;
		} else free(s);
    } else if (step == 1) { // step 1: compute sketch
        step_t *s = (step_t*)in;
		for (i = 0; i < s->n_seq; ++i) {
			mm_bseq1_t *t = &s->seq[i];
			if (t->l_seq > 0)
				mm_sketch(0, t->seq, t->l_seq, p->mi->w, p->mi->k, t->rid, p->mi->flag&MM_I_HPC, &s->a);
			else if (mm_verbose >= 2)
				fprintf(stderr, "[WARNING] the length database sequence '%s' is 0\n", t->name);
			free(t->seq); free(t->name);
		}
		free(s->seq); s->seq = 0;
		return s;
    } else if (step == 2) { // dispatch sketch to buckets
        step_t *s = (step_t*)in;
		mm_idx_add(p->mi, s->a.n, s->a.a);
		kfree(0, s->a.a); free(s);
	}
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r15
testl %esi, %esi
je 0x6617
movq %rdx, %rbx
cmpl $0x2, %esi
je 0x65f2
cmpl $0x1, %esi
jne 0x6621
movq %r15, %rbp
leaq 0x10(%rbx), %r14
pushq $0x10
popq %r13
xorl %r15d, %r15d
movslq (%rbx), %rax
movq 0x8(%rbx), %r12
cmpq %rax, %r15
jge 0x6625
movl -0x10(%r12,%r13), %edx
testl %edx, %edx
jle 0x65ab
movq (%r12,%r13), %rsi
movq 0x20(%rbp), %rax
movl 0x4(%rax), %ecx
movl 0x8(%rax), %r8d
movl -0xc(%r12,%r13), %r9d
movl 0xc(%rax), %eax
andl $0x1, %eax
xorl %edi, %edi
pushq %r14
pushq %rax
callq 0x119f8
popq %rax
popq %rcx
jmp 0x65b7
leaq 0x2c14e(%rip), %rax     # 0x32700
cmpl $0x2, (%rax)
jge 0x65d3
movq (%r12,%r13), %rdi
callq 0x2040
movq -0x8(%r12,%r13), %rdi
callq 0x2040
incq %r15
addq $0x28, %r13
jmp 0x656a
movq 0x2ba1e(%rip), %rax     # 0x31ff8
movq (%rax), %rdi
movq -0x8(%r12,%r13), %rdx
leaq 0x22032(%rip), %rsi     # 0x2861b
xorl %eax, %eax
callq 0x2260
jmp 0x65b7
movq 0x20(%r15), %rdi
movl 0x10(%rbx), %esi
movq 0x20(%rbx), %rdx
callq 0x6c0b
movq 0x20(%rbx), %rsi
xorl %edi, %edi
callq 0x10a07
movq %rbx, %rdi
callq 0x2040
jmp 0x6621
movq 0x10(%r15), %rax
cmpq 0x8(%r15), %rax
jbe 0x6644
xorl %ebx, %ebx
jmp 0x6632
movq %r12, %rdi
callq 0x2040
andq $0x0, 0x8(%rbx)
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x1
popq %rdi
pushq $0x28
popq %rsi
callq 0x2230
movq %rax, %rbx
movq 0x18(%r15), %rdi
movslq (%r15), %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x11804
movq %rax, 0x8(%rbx)
testq %rax, %rax
je 0x660d
movq 0x20(%r15), %r12
movl 0x10(%r12), %eax
movslq (%rbx), %rcx
leaq (%rcx,%rax), %rdx
shrq $0x20, %rdx
jne 0x6916
movl %eax, %edx
decl %edx
addl %ecx, %eax
decl %eax
movd %eax, %xmm0
movd %edx, %xmm1
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movdqa %xmm1, %xmm0
psrld $0x1, %xmm0
por %xmm1, %xmm0
movdqa %xmm0, %xmm1
psrld $0x2, %xmm1
por %xmm0, %xmm1
movdqa %xmm1, %xmm0
psrld $0x4, %xmm0
por %xmm1, %xmm0
movdqa %xmm0, %xmm1
psrld $0x8, %xmm1
por %xmm0, %xmm1
movdqa %xmm1, %xmm0
psrld $0x10, %xmm0
por %xmm1, %xmm0
movd %xmm0, %ecx
pshufd $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
movd %xmm0, %eax
cmpl %eax, %ecx
je 0x670a
incl %eax
movq 0x20(%r12), %rsi
movq 0x50(%r12), %rdi
imulq $0x18, %rax, %rdx
callq 0x10c04
movq 0x20(%r15), %r12
movq %rax, 0x20(%r12)
testb $0x2, 0xc(%r12)
jne 0x6808
movl (%rbx), %ecx
xorl %eax, %eax
testl %ecx, %ecx
cmovlel %eax, %ecx
imulq $0x28, %rcx, %rdx
xorl %ecx, %ecx
cmpq %rax, %rdx
je 0x673b
movq 0x8(%rbx), %rsi
movslq (%rsi,%rax), %rsi
addq %rsi, %rcx
addq $0x28, %rax
jmp 0x6725
addq $0x7, %rcx
movq %rcx, %xmm0
movdqa 0x219a4(%rip), %xmm1    # 0x280f0
punpcklqdq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0]
movq 0x10(%r15), %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
paddq %xmm1, %xmm0
psrlq $0x3, %xmm0
pcmpeqd %xmm1, %xmm1
paddq %xmm0, %xmm1
movdqa %xmm1, %xmm0
psrlq $0x1, %xmm0
por %xmm1, %xmm0
movdqa %xmm0, %xmm1
psrlq $0x2, %xmm1
por %xmm0, %xmm1
movdqa %xmm1, %xmm0
psrlq $0x4, %xmm0
por %xmm1, %xmm0
movdqa %xmm0, %xmm1
psrlq $0x8, %xmm1
por %xmm0, %xmm1
movdqa %xmm1, %xmm0
psrlq $0x10, %xmm0
por %xmm1, %xmm0
movdqa %xmm0, %xmm1
psrlq $0x20, %xmm1
por %xmm0, %xmm1
movq %xmm1, %r14
pshufd $0xee, %xmm1, %xmm0     # xmm0 = xmm1[2,3,2,3]
movq %xmm0, %rax
movq %r15, %r13
movq %rax, %r15
subq %r14, %r15
je 0x6805
movq 0x28(%r12), %rdi
leaq 0x4(,%rax,4), %rsi
callq 0x2320
movq 0x20(%r13), %r12
movq %rax, 0x28(%r12)
leaq (%rax,%r14,4), %rdi
addq $0x4, %rdi
shlq $0x2, %r15
xorl %esi, %esi
movq %r15, %rdx
callq 0x21b0
movq %r13, %r15
xorl %r13d, %r13d
leaq 0x2bffe(%rip), %rbp     # 0x32810
movq %r15, (%rsp)
movslq (%rbx), %rax
cmpq %rax, %r13
jge 0x6632
movl 0xc(%r12), %edi
movl 0x10(%r12), %eax
imulq $0x18, %rax, %r14
addq 0x20(%r12), %r14
testb $0x4, %dil
jne 0x6881
movq 0x50(%r12), %r15
movq 0x8(%rbx), %rax
imulq $0x28, %r13, %r12
movq 0x8(%rax,%r12), %rdi
callq 0x2130
leaq 0x1(%rax), %rsi
movq %r15, %rdi
movq (%rsp), %r15
callq 0x10afc
movq %rax, (%r14)
movq 0x8(%rbx), %rcx
movq 0x8(%rcx,%r12), %rsi
movq %rax, %rdi
callq 0x2090
movq 0x20(%r15), %r12
movl 0xc(%r12), %edi
jmp 0x6885
andq $0x0, (%r14)
movq 0x8(%rbx), %rax
imulq $0x28, %r13, %rdx
movl (%rax,%rdx), %ecx
movl %ecx, 0x10(%r14)
movq 0x10(%r15), %rsi
movq %rsi, 0x8(%r14)
andl $0x0, 0x14(%r14)
testb $0x2, %dil
jne 0x68f6
leaq (%rax,%rdx), %rdi
addq $0x10, %rdi
leal (,%rsi,4), %r8d
xorl %r9d, %r9d
movl %ecx, %ecx
cmpq %rcx, %r9
jae 0x68f6
leaq (%rsi,%r9), %r10
movq (%rdi), %rcx
movzbl (%rcx,%r9), %ecx
movzbl (%rbp,%rcx), %r11d
movl %r8d, %ecx
andb $0x1c, %cl
shll %cl, %r11d
movq 0x28(%r12), %rcx
shrq $0x3, %r10
orl %r11d, (%rcx,%r10,4)
incq %r9
movl 0x10(%r14), %ecx
addl $0x4, %r8d
jmp 0x68ba
addq %rcx, %rsi
movq %rsi, 0x10(%r15)
movl 0x10(%r12), %ecx
leal 0x1(%rcx), %esi
movl %esi, 0x10(%r12)
movl %ecx, 0x4(%rax,%rdx)
incq %r13
jmp 0x6816
leaq 0x21ca3(%rip), %rdi     # 0x285c0
leaq 0x21995(%rip), %rsi     # 0x282b9
leaq 0x21cc5(%rip), %rcx     # 0x285f0
movl $0x146, %edx            # imm = 0x146
callq 0x21a0