// File: /workspace/github_c_makefile_star2_O3/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
movq %rdi, (%rsp)
je 0x765f
movq %rdx, %rbx
cmpl $0x2, %esi
je 0x763a
cmpl $0x1, %esi
jne 0x7669
cmpl $0x0, (%rbx)
jle 0x766d
leaq 0x10(%rbx), %r14
xorl %r15d, %r15d
leaq 0x2f13c(%rip), %r12     # 0x36700
xorl %r13d, %r13d
movq 0x8(%rbx), %rbp
movl (%rbp,%r15), %edx
testl %edx, %edx
jle 0x7603
movq 0x10(%rbp,%r15), %rsi
movq (%rsp), %rax
movq 0x20(%rax), %rax
movl 0x4(%rax), %ecx
movl 0x8(%rax), %r8d
movl 0x4(%rbp,%r15), %r9d
movl 0xc(%rax), %eax
andl $0x1, %eax
xorl %edi, %edi
pushq %r14
pushq %rax
callq 0x13720
addq $0x10, %rsp
jmp 0x760a
cmpl $0x2, (%r12)
jge 0x762f
movq 0x10(%rbp,%r15), %rdi
callq 0x2040
movq 0x8(%rbp,%r15), %rdi
callq 0x2040
incq %r13
movslq (%rbx), %rax
addq $0x28, %r15
cmpq %rax, %r13
jl 0x75c7
jmp 0x766d
leaq (%r15,%rbp), %rdi
callq 0x2e7c
jmp 0x760a
movq 0x20(%r15), %rdi
movl 0x10(%rbx), %esi
movq 0x20(%rbx), %rdx
callq 0x7cb0
movq 0x20(%rbx), %rsi
xorl %edi, %edi
callq 0x12587
movq %rbx, %rdi
callq 0x2040
jmp 0x7669
movq 0x10(%r15), %rax
cmpq 0x8(%r15), %rax
jbe 0x7690
xorl %ebx, %ebx
jmp 0x767e
movq 0x8(%rbx), %rdi
callq 0x2040
movq $0x0, 0x8(%rbx)
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, %edi
movl $0x28, %esi
callq 0x2230
movq %rax, %rbx
movq 0x18(%r15), %rdi
movslq (%r15), %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x1355c
movq %rax, 0x8(%rbx)
testq %rax, %rax
je 0x7655
movq 0x20(%r15), %r12
movl 0x10(%r12), %ecx
movslq (%rbx), %rax
leaq (%rax,%rcx), %rdx
shrq $0x20, %rdx
jne 0x799a
movl %ecx, %edx
decl %edx
addl %eax, %ecx
decl %ecx
movd %ecx, %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, %edx
pshufd $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
movd %xmm0, %ecx
cmpl %ecx, %edx
je 0x7760
incl %ecx
movq 0x20(%r12), %rsi
movq 0x50(%r12), %rdi
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rdx
callq 0x12755
movq 0x20(%r15), %r12
movq %rax, 0x20(%r12)
movl (%rbx), %eax
testb $0x2, 0xc(%r12)
jne 0x7865
testl %eax, %eax
jle 0x7798
movq 0x8(%rbx), %rcx
movl %eax, %edx
shlq $0x3, %rdx
leaq (%rdx,%rdx,4), %rsi
xorl %edi, %edi
xorl %edx, %edx
movslq (%rcx,%rdi), %r8
addq %r8, %rdx
addq $0x28, %rdi
cmpq %rdi, %rsi
jne 0x7782
addq $0x7, %rdx
jmp 0x779d
movl $0x7, %edx
movq %rdx, %xmm0
movdqa 0x25946(%rip), %xmm1    # 0x2d0f0
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, %rcx
movq %r15, %r13
movq %rcx, %r15
subq %r14, %r15
je 0x7865
movq 0x28(%r12), %rdi
leaq 0x4(,%rcx,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
movl (%rbx), %eax
testl %eax, %eax
jle 0x767e
movl 0x10(%r12), %ecx
xorl %r13d, %r13d
leaq 0x2ef94(%rip), %rbp     # 0x36810
movq (%rsp), %r15
movl %ecx, %eax
leaq (%rax,%rax,2), %r14
shlq $0x3, %r14
addq 0x20(%r12), %r14
movl 0xc(%r12), %edi
testb $0x4, %dil
jne 0x78e8
movq 0x50(%r12), %r15
movq 0x8(%rbx), %rax
leaq (,%r13,8), %rcx
leaq (%rcx,%rcx,4), %r12
movq 0x8(%rax,%r12), %rdi
callq 0x2130
leaq 0x1(%rax), %rsi
movq %r15, %rdi
movq (%rsp), %r15
callq 0x1264d
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 0x78ef
movq $0x0, (%r14)
movq 0x8(%rbx), %rax
leaq (,%r13,4), %rdx
addq %r13, %rdx
movl (%rax,%rdx,8), %ecx
movl %ecx, 0x10(%r14)
movq 0x10(%r15), %rsi
movq %rsi, 0x8(%r14)
movl $0x0, 0x14(%r14)
testb $0x2, %dil
jne 0x796c
testl %ecx, %ecx
je 0x796a
movq 0x10(%rax,%rdx,8), %rdi
movq 0x28(%r12), %r8
leal (,%rsi,4), %r9d
xorl %r10d, %r10d
leaq (%rsi,%r10), %r11
movzbl (%rdi,%r10), %ecx
movzbl (%rbp,%rcx), %r15d
movl %r9d, %ecx
andb $0x1c, %cl
shll %cl, %r15d
shrq $0x3, %r11
orl %r15d, (%r8,%r11,4)
incq %r10
movl 0x10(%r14), %ecx
addl $0x4, %r9d
cmpq %rcx, %r10
jb 0x7934
movq (%rsp), %r15
jmp 0x796c
xorl %ecx, %ecx
movl %ecx, %ecx
addq %rcx, %rsi
movq %rsi, 0x10(%r15)
movl 0x10(%r12), %esi
leal 0x1(%rsi), %ecx
movl %ecx, 0x10(%r12)
movl %esi, 0x4(%rax,%rdx,8)
incq %r13
movslq (%rbx), %rax
cmpq %rax, %r13
jl 0x7880
jmp 0x767e
leaq 0x25c1f(%rip), %rdi     # 0x2d5c0
leaq 0x25911(%rip), %rsi     # 0x2d2b9
leaq 0x25c41(%rip), %rcx     # 0x2d5f0
movl $0x146, %edx            # imm = 0x146
callq 0x21a0