// File: /workspace/github_c_makefile_star2_O3/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 0x1a2ba
movq (%rax,%rbx,8), %rax
movq %rax, 0x20(%rsp)
jmp 0x1a2c3
movq $0x0, 0x20(%rsp)
movq %r13, %rdi
callq 0x20e0
movq %rax, %rbp
movl %ebp, %edi
movq %r13, %rsi
callq 0xe25a
leaq 0x48(%r15), %r12
movl $0x0, 0x48(%r15)
movq 0x40(%r14), %rax
movq (%rax,%rbx,8), %rdx
leaq 0x4ef1(%rip), %rsi      # 0x1f1e4
movq %r12, %rdi
movq %rbp, 0x8(%rsp)
movl %ebp, %ecx
xorl %eax, %eax
callq 0x19404
cmpl $0x0, 0x1c(%r14)
movq %r12, 0x10(%rsp)
movq %r15, 0x28(%rsp)
movq %r14, 0x18(%rsp)
movq %rbx, 0x30(%rsp)
je 0x1a425
movq (%r14), %rdi
leaq 0x30(%r15), %rdx
movl 0x14(%r14), %ecx
leaq 0x18(%r15), %r9
movq %r13, %rsi
movq %rdx, 0x50(%rsp)
movq %r15, %r8
callq 0x1999e
cmpl $0x0, 0x20(%r14)
movq 0x30(%r15), %rax
je 0x1a4d3
testq %rax, %rax
je 0x1a61e
movq %r13, 0x38(%rsp)
leaq 0x58(%r15), %rcx
movq %rcx, 0x48(%rsp)
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
xorl %r13d, %r13d
xorl %ebx, %ebx
movq 0x40(%r15), %rbp
movq 0x18(%rbp,%r13), %rcx
movq %rcx, %rdx
shrq $0x20, %rdx
subl %edx, %ecx
cmpl 0x24(%r14), %ecx
jl 0x1a3ee
movq (%r14), %rdi
leaq 0xe0(,%r13), %rdx
addq %rbp, %rdx
addq %r13, %rbp
movq %rbp, %rsi
xorl %ecx, %ecx
callq 0x4ef6
testl %r12d, %r12d
js 0x1a3bb
movl %r12d, %eax
imulq $0x1a0, %rax, %rsi      # imm = 0x1A0
addq 0x40(%r15), %rsi
jmp 0x1a3bd
xorl %esi, %esi
movq (%r14), %rdi
movq %rbp, %rdx
movq 0x8(%rsp), %rcx
movq 0x38(%rsp), %r8
movq 0x20(%rsp), %r9
pushq 0x48(%rsp)
pushq 0x18(%rsp)
callq 0x1a75c
addq $0x10, %rsp
movq 0x50(%rsp), %rax
movq (%rax), %rax
movl %ebx, %r12d
incq %rbx
addq $0x1a0, %r13            # imm = 0x1A0
cmpq %rax, %rbx
jb 0x1a373
movq (%r14), %rdi
testl %r12d, %r12d
movq 0x38(%rsp), %r13
js 0x1a679
movl %r12d, %eax
imulq $0x1a0, %rax, %rsi      # imm = 0x1A0
addq 0x40(%r15), %rsi
jmp 0x1a67b
movq (%r14), %rdi
leaq 0x40(%rsp), %rbx
leaq 0x60(%rsp), %rbp
movq %r13, %rsi
movq %rbx, %rdx
movq %rbp, %rcx
callq 0x19a03
movq (%rbx), %rbx
movq (%rbp), %r12
movq %r12, %r13
subq %rbx, %r13
jle 0x1a69f
leaq 0x4d94(%rip), %rsi      # 0x1f1ee
movq 0x10(%rsp), %rbp
movq %rbp, %rdi
movq 0x8(%rsp), %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0x19404
cmpq $0x0, 0x8(%r14)
je 0x1a4b9
movslq 0x10(%r14), %rax
cmpq %rax, %r13
jg 0x1a4b9
leaq 0x4d72(%rip), %r13      # 0x1f1fa
movq (%r14), %rdi
movq 0x8(%r14), %rsi
movq %rbx, %rdx
leaq 0x58(%rsp), %rcx
callq 0x18d5f
movq 0x58(%rsp), %rdx
movq %rbp, %rdi
movq %r13, %rsi
movq %rax, %rcx
xorl %eax, %eax
callq 0x19404
incq %rbx
cmpq %rbx, %r12
jne 0x1a488
movl 0x48(%r15), %ecx
leal 0x1(%rcx), %edx
cmpl 0x4c(%r15), %edx
jae 0x1a625
movq 0x50(%r15), %rax
jmp 0x1a661
testq %rax, %rax
je 0x1a69f
leaq 0x40(%rsp), %r15
leaq 0x4d12(%rip), %r14      # 0x1f1fa
xorl %r9d, %r9d
movq 0x18(%rsp), %rbx
movq 0x28(%rsp), %rcx
movq 0x40(%rcx), %r13
imulq $0x1a0, %r9, %rsi       # imm = 0x1A0
movq 0x18(%r13,%rsi), %rcx
movq %rcx, %rdx
shrq $0x20, %rdx
movl %ecx, %edi
subl %edx, %edi
movq 0x18(%rsp), %r8
cmpl 0x18(%r8), %edi
jb 0x1a60d
movq %r9, 0x8(%rsp)
addq %rsi, %r13
movq 0x10(%r13), %r8
movq %r12, %rdi
leaq 0x4cce(%rip), %rsi      # 0x1f203
xorl %eax, %eax
callq 0x19404
cmpq $0x0, 0x8(%rbx)
je 0x1a595
movq 0x10(%r13), %rax
movslq 0x10(%rbx), %rcx
cmpq %rcx, %rax
setae %cl
testq %rax, %rax
sete %al
orb %cl, %al
jne 0x1a595
movq %r12, %rbp
xorl %r12d, %r12d
movq (%rbx), %rdi
movq 0x8(%rbx), %rsi
movq (%r13), %rdx
addq %r12, %rdx
movq %r15, %rcx
callq 0x18d5f
movq 0x40(%rsp), %rdx
movq %rbp, %rdi
movq %r14, %rsi
movq %rax, %rcx
xorl %eax, %eax
callq 0x19404
incq %r12
cmpq 0x10(%r13), %r12
jb 0x1a561
movq 0x28(%rsp), %r13
movl 0x48(%r13), %ecx
leal 0x1(%rcx), %edx
cmpl 0x4c(%r13), %edx
jae 0x1a5ad
movq 0x50(%r13), %rax
jmp 0x1a5e9
movl %edx, %eax
shrl %eax
orl %edx, %eax
movl %eax, %ecx
shrl $0x2, %ecx
orl %eax, %ecx
movl %ecx, %eax
shrl $0x4, %eax
orl %ecx, %eax
movl %eax, %ecx
shrl $0x8, %ecx
orl %eax, %ecx
movl %ecx, %esi
shrl $0x10, %esi
orl %ecx, %esi
incl %esi
movl %esi, 0x4c(%r13)
movq 0x50(%r13), %rdi
callq 0x2260
movq %rax, 0x50(%r13)
movl 0x48(%r13), %ecx
leal 0x1(%rcx), %edx
movq 0x10(%rsp), %r12
movq 0x8(%rsp), %r9
movl %edx, 0x48(%r13)
movl %ecx, %ecx
movb $0xa, (%rax,%rcx)
movq 0x50(%r13), %rax
movl 0x48(%r13), %ecx
movb $0x0, (%rax,%rcx)
movq 0x30(%r13), %rax
incq %r9
cmpq %rax, %r9
jb 0x1a4f0
jmp 0x1a69f
movq (%r14), %rdi
xorl %esi, %esi
jmp 0x1a680
movl %edx, %eax
shrl %eax
orl %edx, %eax
movl %eax, %ecx
shrl $0x2, %ecx
orl %eax, %ecx
movl %ecx, %eax
shrl $0x4, %eax
orl %ecx, %eax
movl %eax, %ecx
shrl $0x8, %ecx
orl %eax, %ecx
movl %ecx, %esi
shrl $0x10, %esi
orl %ecx, %esi
incl %esi
movl %esi, 0x4c(%r15)
movq 0x50(%r15), %rdi
callq 0x2260
movq %rax, 0x50(%r15)
movl 0x48(%r15), %ecx
leal 0x1(%rcx), %edx
movl %edx, 0x48(%r15)
movl %ecx, %ecx
movb $0xa, (%rax,%rcx)
movq 0x50(%r15), %rax
movl 0x48(%r15), %ecx
movb $0x0, (%rax,%rcx)
jmp 0x1a69f
xorl %esi, %esi
movq 0x10(%rsp), %r12
leaq 0x58(%r15), %rax
xorl %edx, %edx
movq 0x8(%rsp), %rcx
movq %r13, %r8
movq 0x20(%rsp), %r9
pushq %rax
pushq %r12
callq 0x1a75c
addq $0x10, %rsp
movq 0x28(%rsp), %r15
movl 0x48(%r15), %ecx
leal 0x3(%rcx), %eax
cmpl 0x4c(%r15), %eax
jae 0x1a6b7
movq 0x50(%r15), %rax
jmp 0x1a6f0
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)
movl 0x48(%r15), %ecx
movq 0x30(%rsp), %rbx
movq 0x18(%rsp), %r14
movl %ecx, %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 0x50(%r14), %rax
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