// File: /workspace/github_c_makefile_star2_O2/lh3[P]fermi2/match.c
// Function: worker
static void worker(void *data, long jid, int tid)
{
	global_t *g = (global_t*)data;
	thrmem_t *m = &g->mem[tid];
	char *seq = g->seq[jid], *qual = g->qual? g->qual[jid] : 0;
	int l_seq;

	l_seq = strlen(seq);
	seq_char2nt6(l_seq, (uint8_t*)seq);
	m->str.l = 0;
	ksprintf(&m->str, "SQ\t%s\t%d\n", g->name[jid], l_seq);
	if (!g->partial) { // full-length match
		int64_t k, l, u;
		fm_exact(g->e, seq, &l, &u);
		if (l < u) {
			ksprintf(&m->str, "EM\t0\t%d\t%ld", l_seq, (long)(u - l));
			if (g->sa && u - l <= g->max_sa_occ) {
				for (k = l; k < u; ++k) {
					int64_t idx, i;
					i = fm_sa(g->e, g->sa, k, &idx);
					ksprintf(&m->str, "\t%ld:%ld", (long)idx, (long)i);
				}
			}
			kputc('\n', &m->str);
		}
	} else { // SMEM
		size_t i;
		int64_t k;
		fmd_smem(g->e, (uint8_t*)seq, &m->smem, g->min_occ, &m->curr, &m->prev);
		if (g->discovery) {
			int pre;
			for (i = 0, pre = -1; i < m->smem.n; ++i) {
				fmdsmem_t *p = &m->smem.a[i];
				int start = p->ik.info>>32, end = (uint32_t)p->ik.info;
				if (end - start < g->kmer) continue; // skip short SMEMs
				rld_extend(g->e, &p->ik, p->ok[1], 0);
				discover(g->e, pre < 0? 0 : &m->smem.a[pre], p, l_seq, seq, qual, &m->str, m->cmp);
				pre = i;
			}
			discover(g->e, pre < 0? 0 : &m->smem.a[pre], 0, l_seq, seq, qual, &m->str, m->cmp);
		} else {
			for (i = 0; i < m->smem.n; ++i) {
				fmdsmem_t *p = &m->smem.a[i];
				uint32_t st = (uint32_t)(p->ik.info>>32), en = (uint32_t)p->ik.info;
				if (en - st < g->min_len) continue;
				ksprintf(&m->str, "EM\t%u\t%u\t%ld", st, en, (long)p->ik.x[2]);
				if (g->sa && p->ik.x[2] < g->max_sa_occ) {
					for (k = 0; k < p->ik.x[2]; ++k) {
						int64_t idx, j;
						j = fm_sa(g->e, g->sa, p->ik.x[0] + k, &idx);
						ksprintf(&m->str, "\t%ld:%ld", (long)idx, (long)j);
					}
				}
				kputc('\n', &m->str);
			}
		}
	}
	kputsn("//", 2, &m->str);
	free(g->qual[jid]); free(g->seq[jid]); free(g->name[jid]);
	g->out[jid] = strdup(m->str.s);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movslq %edx, %rax
imulq $0x78, %rax, %rax
addq 0x30(%rdi), %rax
movq %rax, 0x8(%rsp)
movq 0x48(%rdi), %rcx
movq 0x50(%rdi), %rax
movq (%rcx,%rsi,8), %r15
testq %rax, %rax
je 0x17139
movq (%rax,%rbx,8), %rax
movq %rax, 0x20(%rsp)
jmp 0x17142
movq $0x0, 0x20(%rsp)
movq %r15, %rdi
callq 0x20e0
movq %rax, %r13
movl %r13d, %edi
movq %r15, %rsi
callq 0xc519
movq 0x8(%rsp), %r12
andl $0x0, 0x48(%r12)
leaq 0x48(%r12), %rdi
movq 0x40(%r14), %rax
movq (%rax,%rbx,8), %rdx
leaq 0x3f5d(%rip), %rsi      # 0x1b0d4
movq %rdi, (%rsp)
movq %r13, 0x28(%rsp)
movl %r13d, %ecx
xorl %eax, %eax
callq 0x16308
cmpl $0x0, 0x1c(%r14)
movq %rbx, 0x40(%rsp)
je 0x1729c
movq (%r14), %rdi
leaq 0x30(%r12), %rdx
movl 0x14(%r14), %ecx
leaq 0x18(%r12), %r9
movq %r15, %rsi
movq %rdx, 0x10(%rsp)
movq %r12, %r8
callq 0x168ab
cmpl $0x0, 0x20(%r14)
je 0x17309
movq %r15, 0x18(%rsp)
leaq 0x58(%r12), %rax
movq %rax, 0x30(%rsp)
pushq $-0x1
popq %r13
xorl %r15d, %r15d
xorl %ebp, %ebp
movq %r12, %rdx
movq 0x10(%rsp), %rsi
movl %r13d, %r12d
cmpq (%rsi), %rbp
jae 0x17280
movq 0x40(%rdx), %rbx
movq 0x18(%rbx,%r15), %rax
movq %rax, %rcx
shrq $0x20, %rcx
subl %ecx, %eax
cmpl 0x24(%r14), %eax
jl 0x17271
movq (%r14), %rdi
leaq (%rbx,%r15), %rdx
addq $0xe0, %rdx
addq %r15, %rbx
movq %rbx, %rsi
xorl %ecx, %ecx
callq 0x39db
testl %r13d, %r13d
js 0x1723c
imulq $0x1a0, %r12, %rsi      # imm = 0x1A0
movq 0x8(%rsp), %rax
addq 0x40(%rax), %rsi
jmp 0x1723e
xorl %esi, %esi
movq (%r14), %rdi
movq %rbx, %rdx
movq 0x28(%rsp), %rcx
movq 0x18(%rsp), %r8
movq 0x20(%rsp), %r9
pushq 0x30(%rsp)
pushq 0x8(%rsp)
callq 0x1750e
addq $0x10, %rsp
movl %ebp, %r13d
movq 0x8(%rsp), %rdx
movq 0x10(%rsp), %rsi
incq %rbp
addq $0x1a0, %r15            # imm = 0x1A0
jmp 0x171e6
movq (%r14), %rdi
testl %r13d, %r13d
js 0x173d4
imulq $0x1a0, %r12, %rsi      # imm = 0x1A0
addq 0x40(%rdx), %rsi
jmp 0x173d6
movq (%r14), %rdi
leaq 0x38(%rsp), %rbx
leaq 0x50(%rsp), %r12
movq %r15, %rsi
movq %rbx, %rdx
movq %r12, %rcx
callq 0x1690d
movq (%rbx), %r13
movq (%r12), %r15
movq %r15, %rbx
subq %r13, %rbx
jle 0x173f6
leaq 0x3e0d(%rip), %rsi      # 0x1b0de
movq (%rsp), %rdi
movq 0x28(%rsp), %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x16308
cmpq $0x0, 0x8(%r14)
je 0x172f8
movslq 0x10(%r14), %rax
cmpq %rax, %rbx
jle 0x1745b
pushq $0xa
popq %rdi
movq (%rsp), %rsi
callq 0x1749d
jmp 0x173f6
leaq 0x38(%rsp), %rbx
leaq 0x3dd5(%rip), %rbp      # 0x1b0ea
xorl %r15d, %r15d
movq 0x10(%rsp), %rdi
cmpq (%rdi), %r15
jae 0x173fb
movq 0x40(%r12), %r13
imulq $0x1a0, %r15, %rax      # imm = 0x1A0
movq 0x18(%r13,%rax), %rcx
movq %rcx, %rdx
shrq $0x20, %rdx
movl %ecx, %esi
subl %edx, %esi
cmpl 0x18(%r14), %esi
jb 0x173cc
addq %rax, %r13
movq 0x10(%r13), %r8
movq (%rsp), %rdi
leaq 0x3d95(%rip), %rsi      # 0x1b0f3
xorl %eax, %eax
callq 0x16308
cmpq $0x0, 0x8(%r14)
je 0x173b6
movq 0x10(%r13), %rax
movslq 0x10(%r14), %rcx
cmpq %rcx, %rax
jae 0x173b6
xorl %r12d, %r12d
cmpq %rax, %r12
jae 0x173b6
movq (%r14), %rdi
movq 0x8(%r14), %rsi
movq (%r13), %rdx
addq %r12, %rdx
movq %rbx, %rcx
callq 0x15ccc
movq 0x38(%rsp), %rdx
movq (%rsp), %rdi
movq %rbp, %rsi
movq %rax, %rcx
xorl %eax, %eax
callq 0x16308
incq %r12
movq 0x10(%r13), %rax
jmp 0x1737c
pushq $0xa
popq %rdi
movq (%rsp), %rsi
callq 0x1749d
movq 0x8(%rsp), %r12
movq 0x10(%rsp), %rdi
incq %r15
jmp 0x1731d
xorl %esi, %esi
movq 0x18(%rsp), %r8
xorl %edx, %edx
movq 0x28(%rsp), %rcx
movq 0x20(%rsp), %r9
pushq 0x30(%rsp)
pushq 0x8(%rsp)
callq 0x1750e
popq %rax
popq %rcx
movq 0x8(%rsp), %r12
leaq 0x3cfe(%rip), %rdi      # 0x1b100
pushq $0x2
popq %rsi
movq (%rsp), %rdx
callq 0x17aab
movq 0x50(%r14), %rax
movq 0x40(%rsp), %rbx
movq (%rax,%rbx,8), %rdi
callq 0x2040
movq 0x48(%r14), %rax
movq (%rax,%rbx,8), %rdi
callq 0x2040
movq 0x40(%r14), %rax
movq (%rax,%rbx,8), %rdi
callq 0x2040
movq 0x50(%r12), %rdi
callq 0x2340
movq 0x58(%r14), %rcx
movq %rax, (%rcx,%rbx,8)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x48(%rsp), %rbx
leaq 0x3c83(%rip), %rbp      # 0x1b0ea
cmpq %r15, %r13
jge 0x172f8
movq (%r14), %rdi
movq 0x8(%r14), %rsi
movq %r13, %rdx
movq %rbx, %rcx
callq 0x15ccc
movq 0x48(%rsp), %rdx
movq (%rsp), %rdi
movq %rbp, %rsi
movq %rax, %rcx
xorl %eax, %eax
callq 0x16308
incq %r13
jmp 0x17467