// File: /workspace/github_c_makefile_star2_O1/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, %r14
testl %esi, %esi
je 0x76af
movq %rdx, %rbx
cmpl $0x2, %esi
je 0x7687
cmpl $0x1, %esi
jne 0x79c2
cmpl $0x0, (%rbx)
jle 0x76c2
leaq 0x10(%rbx), %r15
xorl %r12d, %r12d
xorl %ebp, %ebp
movq 0x8(%rbx), %r13
movl (%r13,%r12), %edx
testl %edx, %edx
jle 0x764b
movq 0x10(%r13,%r12), %rsi
movq 0x20(%r14), %rax
movl 0x4(%rax), %ecx
movl 0x8(%rax), %r8d
movl 0x4(%r13,%r12), %r9d
movl 0xc(%rax), %eax
andl $0x1, %eax
xorl %edi, %edi
pushq %r15
pushq %rax
callq 0x1376c
addq $0x10, %rsp
jmp 0x7657
leaq 0x2e0ae(%rip), %rax     # 0x35700
cmpl $0x2, (%rax)
jge 0x767c
movq 0x10(%r13,%r12), %rdi
callq 0x2040
movq 0x8(%r13,%r12), %rdi
callq 0x2040
incq %rbp
movslq (%rbx), %rax
addq $0x28, %r12
cmpq %rax, %rbp
jl 0x7613
jmp 0x76c2
leaq (%r12,%r13), %rdi
callq 0x2e86
jmp 0x7657
movq 0x20(%r14), %rdi
movl 0x10(%rbx), %esi
movq 0x20(%rbx), %rdx
callq 0x7ce5
movq 0x20(%rbx), %rsi
xorl %edi, %edi
callq 0x1261e
movq %rbx, %rdi
callq 0x2040
jmp 0x79c2
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rax
jbe 0x76d8
xorl %eax, %eax
xorl %ebx, %ebx
jmp 0x79be
movq 0x8(%rbx), %rdi
callq 0x2040
movq $0x0, 0x8(%rbx)
jmp 0x79c4
movl $0x1, %edi
movl $0x28, %esi
callq 0x2230
movq %rax, %rbx
movq 0x18(%r14), %rdi
movslq (%r14), %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x135ac
movq %rax, 0x8(%rbx)
testq %rax, %rax
je 0x77cb
movq 0x20(%r14), %rax
movl 0x10(%rax), %ecx
movslq (%rbx), %rdx
leaq (%rdx,%rcx), %rsi
shrq $0x20, %rsi
jne 0x79d6
movl %ecx, %esi
decl %esi
addl %edx, %ecx
decl %ecx
movl %ecx, %edx
shrl %edx
orl %ecx, %edx
movl %edx, %ecx
shrl $0x2, %ecx
orl %edx, %ecx
movl %ecx, %edx
shrl $0x4, %edx
orl %ecx, %edx
movl %edx, %edi
shrl $0x8, %edi
orl %edx, %edi
movl %edi, %ecx
shrl $0x10, %ecx
orl %edi, %ecx
movl %esi, %edx
shrl %edx
orl %esi, %edx
movl %edx, %esi
shrl $0x2, %esi
orl %edx, %esi
movl %esi, %edx
shrl $0x4, %edx
orl %esi, %edx
movl %edx, %esi
shrl $0x8, %esi
orl %edx, %esi
movl %esi, %edx
shrl $0x10, %edx
orl %esi, %edx
cmpl %ecx, %edx
je 0x778f
incl %ecx
movq 0x20(%rax), %rsi
movq 0x50(%rax), %rdi
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rdx
callq 0x127ec
movq 0x20(%r14), %rcx
movq %rax, 0x20(%rcx)
movq 0x20(%r14), %rax
testb $0x2, 0xc(%rax)
jne 0x78a5
movslq (%rbx), %rcx
testq %rcx, %rcx
jle 0x77da
movq 0x8(%rbx), %rdx
shlq $0x3, %rcx
leaq (%rcx,%rcx,4), %rsi
xorl %edi, %edi
xorl %ecx, %ecx
movslq (%rdx,%rdi), %r8
addq %r8, %rcx
addq $0x28, %rdi
cmpq %rdi, %rsi
jne 0x77b5
addq $0x7, %rcx
jmp 0x77df
movq %rbx, %rdi
callq 0x2040
movb $0x1, %al
jmp 0x79be
movl $0x7, %ecx
movq 0x10(%r14), %rdx
leaq 0x7(%rdx), %rsi
shrq $0x3, %rsi
addq %rdx, %rcx
shrq $0x3, %rcx
decq %rsi
movq %rsi, %rdx
shrq %rdx
orq %rsi, %rdx
movq %rdx, %rsi
shrq $0x2, %rsi
orq %rdx, %rsi
movq %rsi, %rdx
shrq $0x4, %rdx
orq %rsi, %rdx
movq %rdx, %rsi
shrq $0x8, %rsi
orq %rdx, %rsi
movq %rsi, %rdx
shrq $0x10, %rdx
orq %rsi, %rdx
movq %rdx, %r12
shrq $0x20, %r12
orq %rdx, %r12
decq %rcx
movq %rcx, %rdx
shrq %rdx
orq %rcx, %rdx
movq %rdx, %rcx
shrq $0x2, %rcx
orq %rdx, %rcx
movq %rcx, %rdx
shrq $0x4, %rdx
orq %rcx, %rdx
movq %rdx, %rcx
shrq $0x8, %rcx
orq %rdx, %rcx
movq %rcx, %rdx
shrq $0x10, %rdx
orq %rcx, %rdx
movq %rdx, %rcx
shrq $0x20, %rcx
orq %rdx, %rcx
movq %rcx, %r15
subq %r12, %r15
je 0x78a5
movq 0x28(%rax), %rdi
leaq 0x4(,%rcx,4), %rsi
callq 0x2320
movq 0x20(%r14), %rcx
movq %rax, 0x28(%rcx)
leaq (%rax,%r12,4), %rdi
addq $0x4, %rdi
shlq $0x2, %r15
xorl %esi, %esi
movq %r15, %rdx
callq 0x21b0
cmpl $0x0, (%rbx)
jle 0x79bc
xorl %r12d, %r12d
leaq 0x2df58(%rip), %r13     # 0x35810
movq %r14, (%rsp)
movq 0x20(%r14), %rax
movl 0x10(%rax), %ecx
leaq (%rcx,%rcx,2), %rbp
shlq $0x3, %rbp
addq 0x20(%rax), %rbp
testb $0x4, 0xc(%rax)
jne 0x791a
movq 0x50(%rax), %r15
movq 0x8(%rbx), %rax
leaq (,%r12,8), %rcx
leaq (%rcx,%rcx,4), %r14
movq 0x8(%rax,%r14), %rdi
callq 0x2130
leaq 0x1(%rax), %rsi
movq %r15, %rdi
callq 0x126e9
movq %rax, (%rbp)
movq 0x8(%rbx), %rcx
movq 0x8(%rcx,%r14), %rsi
movq (%rsp), %r14
movq %rax, %rdi
callq 0x2090
jmp 0x7922
movq $0x0, (%rbp)
movq 0x8(%rbx), %rax
leaq (%r12,%r12,4), %rdx
movl (%rax,%rdx,8), %ecx
movl %ecx, 0x10(%rbp)
movq 0x10(%r14), %rdi
movq %rdi, 0x8(%rbp)
movl $0x0, 0x14(%rbp)
movq 0x20(%r14), %rsi
testb $0x2, 0xc(%rsi)
jne 0x7992
cmpl $0x0, 0x10(%rbp)
je 0x7992
movq 0x10(%rax,%rdx,8), %r8
movq 0x28(%rsi), %r9
leal (,%rdi,4), %r10d
xorl %r11d, %r11d
leaq (%rdi,%r11), %r14
movzbl (%r8,%r11), %ecx
movzbl (%r13,%rcx), %r15d
movl %r10d, %ecx
andb $0x1c, %cl
shll %cl, %r15d
shrq $0x3, %r14
orl %r15d, (%r9,%r14,4)
incq %r11
movl 0x10(%rbp), %ecx
addl $0x4, %r10d
cmpq %rcx, %r11
jb 0x7963
movl 0x10(%rbp), %ecx
addq %rcx, %rdi
movq (%rsp), %r14
movq %rdi, 0x10(%r14)
movl 0x10(%rsi), %ecx
leal 0x1(%rcx), %edi
movl %edi, 0x10(%rsi)
movl %ecx, 0x4(%rax,%rdx,8)
incq %r12
movslq (%rbx), %rax
cmpq %rax, %r12
jl 0x78bc
xorl %eax, %eax
testb %al, %al
je 0x79c4
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x24bbf(%rip), %rdi     # 0x2c59c
leaq 0x248b1(%rip), %rsi     # 0x2c295
leaq 0x24be1(%rip), %rcx     # 0x2c5cc
movl $0x146, %edx            # imm = 0x146
callq 0x21a0