// File: /workspace/github_c_makefile_star2_O1/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 $0x68, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movslq %edx, %rax
imulq $0x78, %rax, %r15
addq 0x30(%rdi), %r15
movq 0x48(%rdi), %rcx
movq 0x50(%rdi), %rax
movq (%rcx,%rsi,8), %r13
testq %rax, %rax
je 0x195f0
movq (%rax,%rbx,8), %rax
movq %rax, 0x10(%rsp)
jmp 0x195f9
movq $0x0, 0x10(%rsp)
movq %r13, %rdi
callq 0x20e0
movq %rax, %rbp
movl %ebp, %edi
movq %r13, %rsi
callq 0xdcaf
leaq 0x48(%r15), %r12
movl $0x0, 0x48(%r15)
movq 0x40(%r14), %rax
movq (%rax,%rbx,8), %rdx
leaq 0x49b3(%rip), %rsi      # 0x1dfdc
movq %r12, %rdi
movq %rbp, 0x8(%rsp)
movl %ebp, %ecx
xorl %eax, %eax
callq 0x18871
cmpl $0x0, 0x1c(%r14)
movq %r15, 0x20(%rsp)
movq %r14, 0x18(%rsp)
movq %rbx, 0x48(%rsp)
je 0x19739
movq (%r14), %rdi
leaq 0x30(%r15), %rdx
movl 0x14(%r14), %ecx
leaq 0x18(%r15), %r9
movq %r13, %rsi
movq %rdx, 0x38(%rsp)
movq %r15, %r8
callq 0x18e50
cmpl $0x0, 0x20(%r14)
movq 0x30(%r15), %rax
je 0x19838
movq %r13, 0x28(%rsp)
movq %r12, 0x30(%rsp)
testq %rax, %rax
je 0x1996d
leaq 0x58(%r15), %rax
movq %rax, 0x50(%rsp)
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
xorl %ebp, %ebp
xorl %r13d, %r13d
movq 0x40(%r15), %rbx
movq 0x18(%rbx,%rbp), %rax
movq %rax, %rcx
shrq $0x20, %rcx
subl %ecx, %eax
cmpl 0x24(%r14), %eax
jl 0x1971c
movq (%r14), %rdi
leaq (%rbx,%rbp), %rdx
addq $0xe0, %rdx
addq %rbp, %rbx
movq %rbx, %rsi
xorl %ecx, %ecx
callq 0x5027
testl %r12d, %r12d
js 0x196f1
movl %r12d, %eax
imulq $0x1a0, %rax, %rsi      # imm = 0x1A0
addq 0x40(%r15), %rsi
jmp 0x196f3
xorl %esi, %esi
movq (%r14), %rdi
movq %rbx, %rdx
movq 0x8(%rsp), %rcx
movq 0x28(%rsp), %r8
movq 0x10(%rsp), %r9
pushq 0x50(%rsp)
pushq 0x38(%rsp)
callq 0x19a69
addq $0x10, %rsp
movl %r13d, %r12d
incq %r13
addq $0x1a0, %rbp            # imm = 0x1A0
movq 0x38(%rsp), %rax
cmpq (%rax), %r13
jb 0x196a9
jmp 0x19973
movq (%r14), %rdi
leaq 0x40(%rsp), %rbx
leaq 0x60(%rsp), %rbp
movq %r13, %rsi
movq %rbx, %rdx
movq %rbp, %rcx
callq 0x18eb5
movq (%rbx), %r13
movq (%rbp), %rbx
movq %rbx, %rbp
subq %r13, %rbp
jle 0x199b0
leaq 0x4878(%rip), %rsi      # 0x1dfe6
movq %r12, %rdi
movq 0x8(%rsp), %rdx
movq %rbp, %rcx
xorl %eax, %eax
callq 0x18871
cmpq $0x0, 0x8(%r14)
je 0x197d3
movslq 0x10(%r14), %rax
cmpq %rax, %rbp
setg %al
cmpq %r13, %rbx
setle %cl
orb %al, %cl
jne 0x197d3
leaq 0x4850(%rip), %rbp      # 0x1dff2
movq (%r14), %rdi
movq 0x8(%r14), %rsi
movq %r13, %rdx
leaq 0x58(%rsp), %rcx
callq 0x181b8
movq 0x58(%rsp), %rdx
movq %r12, %rdi
movq %rbp, %rsi
movq %rax, %rcx
xorl %eax, %eax
callq 0x18871
incq %r13
cmpq %r13, %rbx
jne 0x197a2
movl 0x48(%r15), %eax
incl %eax
cmpl 0x4c(%r15), %eax
jb 0x19814
movl %eax, %ecx
shrl %ecx
orl %eax, %ecx
movl %ecx, %eax
shrl $0x2, %eax
orl %ecx, %eax
movl %eax, %ecx
shrl $0x4, %ecx
orl %eax, %ecx
movl %ecx, %eax
shrl $0x8, %eax
orl %ecx, %eax
movl %eax, %esi
shrl $0x10, %esi
orl %eax, %esi
incl %esi
movl %esi, 0x4c(%r15)
movq 0x50(%r15), %rdi
callq 0x2260
movq %rax, 0x50(%r15)
movq 0x50(%r15), %rax
movl 0x48(%r15), %ecx
leal 0x1(%rcx), %edx
movl %edx, 0x48(%r15)
movb $0xa, (%rax,%rcx)
movq 0x50(%r15), %rax
movl 0x48(%r15), %ecx
movb $0x0, (%rax,%rcx)
jmp 0x199b0
testq %rax, %rax
je 0x199b0
leaq 0x40(%rsp), %r15
leaq 0x47a5(%rip), %r14      # 0x1dff2
xorl %r8d, %r8d
movq 0x18(%rsp), %rbp
movq 0x20(%rsp), %rax
movq 0x40(%rax), %r13
imulq $0x1a0, %r8, %rax       # imm = 0x1A0
movq 0x18(%r13,%rax), %rcx
movq %rcx, %rdx
shrq $0x20, %rdx
movl %ecx, %esi
subl %edx, %esi
movq 0x18(%rsp), %rdi
cmpl 0x18(%rdi), %esi
jb 0x1995a
movq %r8, 0x8(%rsp)
addq %rax, %r13
movq 0x10(%r13), %r8
movq %r12, %rdi
leaq 0x4762(%rip), %rsi      # 0x1dffb
xorl %eax, %eax
callq 0x18871
cmpq $0x0, 0x8(%rbp)
movq %r12, %rbx
je 0x198f3
movslq 0x10(%rbp), %rax
cmpq %rax, 0x10(%r13)
jae 0x198f3
cmpq $0x0, 0x10(%r13)
je 0x198f3
xorl %r12d, %r12d
movq (%rbp), %rdi
movq 0x8(%rbp), %rsi
movq (%r13), %rdx
addq %r12, %rdx
movq %r15, %rcx
callq 0x181b8
movq 0x40(%rsp), %rdx
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rcx
xorl %eax, %eax
callq 0x18871
incq %r12
cmpq 0x10(%r13), %r12
jb 0x198be
movq %rbx, %r12
movq 0x20(%rsp), %rbx
movl 0x48(%rbx), %eax
incl %eax
cmpl 0x4c(%rbx), %eax
jb 0x19939
movl %eax, %ecx
shrl %ecx
orl %eax, %ecx
movl %ecx, %eax
shrl $0x2, %eax
orl %ecx, %eax
movl %eax, %ecx
shrl $0x4, %ecx
orl %eax, %ecx
movl %ecx, %eax
shrl $0x8, %eax
orl %ecx, %eax
movl %eax, %esi
shrl $0x10, %esi
orl %eax, %esi
incl %esi
movl %esi, 0x4c(%rbx)
movq 0x50(%rbx), %rdi
callq 0x2260
movq %rax, 0x50(%rbx)
movq 0x50(%rbx), %rax
movl 0x48(%rbx), %ecx
leal 0x1(%rcx), %edx
movl %edx, 0x48(%rbx)
movb $0xa, (%rax,%rcx)
movq 0x50(%rbx), %rax
movl 0x48(%rbx), %ecx
movb $0x0, (%rax,%rcx)
movq 0x8(%rsp), %r8
incq %r8
movq 0x38(%rsp), %rax
cmpq (%rax), %r8
jb 0x19855
jmp 0x199b0
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movq (%r14), %rdi
testl %r12d, %r12d
movq 0x28(%rsp), %r8
js 0x19990
movl %r12d, %eax
imulq $0x1a0, %rax, %rsi      # imm = 0x1A0
addq 0x40(%r15), %rsi
jmp 0x19992
xorl %esi, %esi
leaq 0x58(%r15), %rax
xorl %edx, %edx
movq 0x8(%rsp), %rcx
movq 0x10(%rsp), %r9
pushq %rax
pushq 0x38(%rsp)
callq 0x19a69
addq $0x10, %rsp
movq 0x20(%rsp), %r15
movl 0x48(%r15), %eax
addl $0x3, %eax
cmpl 0x4c(%r15), %eax
jb 0x199f7
movl %eax, %ecx
shrl %ecx
orl %eax, %ecx
movl %ecx, %eax
shrl $0x2, %eax
orl %ecx, %eax
movl %eax, %ecx
shrl $0x4, %ecx
orl %eax, %ecx
movl %ecx, %eax
shrl $0x8, %eax
orl %ecx, %eax
movl %eax, %esi
shrl $0x10, %esi
orl %eax, %esi
incl %esi
movl %esi, 0x4c(%r15)
movq 0x50(%r15), %rdi
callq 0x2260
movq %rax, 0x50(%r15)
movq 0x50(%r15), %rax
movl 0x48(%r15), %ecx
movw $0x2f2f, (%rax,%rcx)    # imm = 0x2F2F
movl 0x48(%r15), %eax
addl $0x2, %eax
movl %eax, 0x48(%r15)
movq 0x50(%r15), %rcx
movb $0x0, (%rcx,%rax)
movq 0x18(%rsp), %r14
movq 0x50(%r14), %rax
movq 0x48(%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(%r15), %rdi
callq 0x2340
movq 0x58(%r14), %rcx
movq %rax, (%rcx,%rbx,8)
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq