// File: /workspace/github_c_makefile_star2_O0/lh3[P]fermi2/match.c
// Function: discover
static void discover(const rld_t *e, const fmdsmem_t *q, const fmdsmem_t *p, int l_seq, const char *seq, const char *qual, kstring_t *s, kstring_t cmp[2])
{
	int start, end, i, ext[2], left, right, tmp_l, pos;
	int64_t occ[2];
	rldintv_t ovlp;

	// find the coordinate from which the extension will be applied
	if (q == 0 && p == 0) {
		start = 0; end = l_seq;
	} else if (q == 0) {
		if (p->ik.info>>32 == 0) return; // no novel allele
		start = 0; end = p->ik.info>>32;
	} else if (p == 0) {
		if ((uint32_t)q->ik.info == l_seq) return; // no novel allele
		start = (uint32_t)q->ik.info; end = l_seq;
	} else {
		start = (uint32_t)q->ik.info, end = p->ik.info>>32;
		if (start >= end && q->ok[1][0].x[2] == q->ik.x[2] && p->ik.x[2] == p->ok[0][0].x[2]) return;
	}
	// find the SAI for the overlap (if applicable)
	memset(&ovlp, 0, sizeof(rldintv_t));
	ovlp.x[2] = e->mcnt[0];
	if (start <= end) { // no overlap
		left = start - 1, right = end;
		for (i = left + 1; i < right; ++i)
			if (seq[i] < 5) break;
		if (i == end) return; // the gap is filled with "N"
	} else {
		rldintv_t ok[6];
		left = end - 1, right = start;
		for (i = right - 1; i > left; --i) {
			rld_extend(e, &ovlp, ok, 1);
			ovlp = ok[(int)seq[i]];
			assert(ovlp.x[2] > 0);
		}
	}
	occ[0] = occ[1] = 0;
	ext[0] = ext[1] = 0;
	// left extension
	if (left >= 0) {
		int64_t l = ovlp.x[0], u = l + ovlp.x[2];
		uint64_t ol[6], ou[6];
		for (i = left; i >= 0; --i) {
			int c = seq[i];
			rld_rank1a(e, l, ol);
			rld_rank1a(e, u, ou);
			l = e->cnt[c] + ol[c];
			u = e->cnt[c] + ou[c];
			if (u - l <= q->ik.x[2]) break;
		}
		assert(i >= 0 && u - l == q->ik.x[2]);
		ext[0] = left + 1 - i;
		occ[0] = u - l;
	}
	// right extension
	if (right < l_seq) {
		int64_t l = ovlp.x[1], u = l + ovlp.x[2];
		uint64_t ol[6], ou[6];
		for (i = right; i < l_seq; ++i) {
			int c = fmd_comp(seq[i]);
			rld_rank1a(e, l, ol);
			rld_rank1a(e, u, ou);
			l = e->cnt[c] + ol[c];
			u = e->cnt[c] + ou[c];
			if (u - l <= p->ik.x[2]) break;
		}
		assert(i < l_seq && u - l == p->ik.x[2]);
		ext[1] = i + 1 - right;
		occ[1] = u - l;
	}
	if (ovlp.x[2] == occ[0] + occ[1]) return;
	// cut sequence
	pos = left + 1 - ext[0];
	cmp[0].l = cmp[1].l = 0;
	kputsn(&seq[pos], (right + ext[1]) - (left + 1 - ext[0]), &cmp[0]);
	kputsn(cmp[0].s, cmp[0].l, &cmp[1]);
	seq_revcomp6(cmp[1].l, (uint8_t*)cmp[1].s);
	// print
	if (ovlp.x[2] == e->mcnt[0]) ovlp.x[2] = 0;
	ksprintf(s, "NS\t%d\t", pos);
	tmp_l = end < start? start - end : 0;
	if (strcmp(cmp[0].s, cmp[1].s) <= 0) {
		ksprintf(s, "+\t%d\t%d\t%d\t%ld\t%ld\t%ld\t", ext[0] + tmp_l, end - start, ext[1] + tmp_l, (long)occ[0], (long)ovlp.x[2], (long)occ[1]);
		for (i = 0; i < cmp[0].l; ++i)
			kputc("$ACGTN"[(int)cmp[0].s[i]], s);
		kputc('\t', s);
		if (qual) kputsn(&qual[pos], cmp[0].l, s);
		else kputc('*', s);
	} else {
		ksprintf(s, "-\t%d\t%d\t%d\t%ld\t%ld\t%ld\t", ext[1] + tmp_l, end - start, ext[0] + tmp_l, (long)occ[1], (long)ovlp.x[2], (long)occ[0]);
		for (i = 0; i < cmp[0].l; ++i)
			kputc("$ACGTN"[(int)cmp[1].s[i]], s);
		kputc('\t', s);
		if (qual) {
			for (i = pos + cmp[0].l - 1; i >= pos; --i)
				kputc(qual[i], s);
		} else kputc('*', s);
	}
	kputc('\n', s);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x260, %rsp            # imm = 0x260
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x28fca
cmpq $0x0, -0x18(%rbp)
jne 0x28fca
movl $0x0, -0x34(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x38(%rbp)
jmp 0x29080
cmpq $0x0, -0x10(%rbp)
jne 0x29000
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
shrq $0x20, %rax
cmpq $0x0, %rax
jne 0x28fe8
jmp 0x29779
movl $0x0, -0x34(%rbp)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
shrq $0x20, %rax
movl %eax, -0x38(%rbp)
jmp 0x2907e
cmpq $0x0, -0x18(%rbp)
jne 0x2902c
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
cmpl -0x1c(%rbp), %eax
jne 0x29019
jmp 0x29779
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movl %eax, -0x34(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x38(%rbp)
jmp 0x2907c
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movl %eax, -0x34(%rbp)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
shrq $0x20, %rax
movl %eax, -0x38(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
jl 0x2907a
movq -0x10(%rbp), %rax
movq 0xf0(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x2907a
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x30(%rcx), %rax
jne 0x2907a
jmp 0x29779
jmp 0x2907c
jmp 0x2907e
jmp 0x29080
leaq -0x90(%rbp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x2160
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movq (%rax), %rax
movq %rax, -0x80(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
jg 0x290fc
movl -0x34(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x48(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jge 0x290ea
movq -0x28(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x5, %eax
jge 0x290dd
jmp 0x290ea
jmp 0x290df
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x290c2
movl -0x3c(%rbp), %eax
cmpl -0x38(%rbp), %eax
jne 0x290f7
jmp 0x29779
jmp 0x291b8
movl -0x38(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x48(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x48(%rbp), %eax
jle 0x291b6
movq -0x8(%rbp), %rdi
leaq -0x150(%rbp), %rdx
leaq -0x90(%rbp), %rsi
movl $0x1, %ecx
callq 0x49a0
movq -0x28(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movslq %eax, %rcx
leaq -0x150(%rbp), %rax
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, -0x90(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x88(%rbp)
movq 0x10(%rax), %rcx
movq %rcx, -0x80(%rbp)
movq 0x18(%rax), %rax
movq %rax, -0x78(%rbp)
cmpq $0x0, -0x80(%rbp)
jbe 0x29187
jmp 0x291a6
leaq 0x4ec8(%rip), %rdi      # 0x2e056
leaq 0x4ecf(%rip), %rsi      # 0x2e064
movl $0xae, %edx
leaq 0x4ecb(%rip), %rcx      # 0x2e06c
callq 0x2140
jmp 0x291a8
movl -0x3c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x29114
jmp 0x291b8
movq $0x0, -0x68(%rbp)
movq $0x0, -0x70(%rbp)
movl $0x0, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
cmpl $0x0, -0x48(%rbp)
jl 0x29329
movq -0x90(%rbp), %rax
movq %rax, -0x158(%rbp)
movq -0x158(%rbp), %rax
addq -0x80(%rbp), %rax
movq %rax, -0x160(%rbp)
movl -0x48(%rbp), %eax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jl 0x292cc
movq -0x28(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movl %eax, -0x1c4(%rbp)
movq -0x8(%rbp), %rdi
movq -0x158(%rbp), %rsi
leaq -0x190(%rbp), %rdx
callq 0x3f60
movq -0x8(%rbp), %rdi
movq -0x160(%rbp), %rsi
leaq -0x1c0(%rbp), %rdx
callq 0x3f60
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x1c4(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x1c4(%rbp), %rcx
addq -0x190(%rbp,%rcx,8), %rax
movq %rax, -0x158(%rbp)
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x1c4(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x1c4(%rbp), %rcx
addq -0x1c0(%rbp,%rcx,8), %rax
movq %rax, -0x160(%rbp)
movq -0x160(%rbp), %rax
subq -0x158(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x10(%rcx), %rax
ja 0x292bc
jmp 0x292cc
jmp 0x292be
movl -0x3c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x29206
cmpl $0x0, -0x3c(%rbp)
jl 0x292ec
movq -0x160(%rbp), %rax
subq -0x158(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x292ec
jmp 0x2930b
leaq 0x4df7(%rip), %rdi      # 0x2e0ea
leaq 0x4d6a(%rip), %rsi      # 0x2e064
movl $0xbf, %edx
leaq 0x4d66(%rip), %rcx      # 0x2e06c
callq 0x2140
movl -0x48(%rbp), %eax
addl $0x1, %eax
subl -0x3c(%rbp), %eax
movl %eax, -0x44(%rbp)
movq -0x160(%rbp), %rax
subq -0x158(%rbp), %rax
movq %rax, -0x70(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x294cb
movq -0x88(%rbp), %rax
movq %rax, -0x1d0(%rbp)
movq -0x1d0(%rbp), %rax
addq -0x80(%rbp), %rax
movq %rax, -0x1d8(%rbp)
movl -0x4c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x2946c
movq -0x28(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x1, %eax
jl 0x293a4
movq -0x28(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x4, %eax
jg 0x293a4
movq -0x28(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsbl (%rax,%rcx), %ecx
movl $0x5, %eax
subl %ecx, %eax
movl %eax, -0x248(%rbp)
jmp 0x293b6
movq -0x28(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movl %eax, -0x248(%rbp)
movl -0x248(%rbp), %eax
movl %eax, -0x244(%rbp)
movq -0x8(%rbp), %rdi
movq -0x1d0(%rbp), %rsi
leaq -0x210(%rbp), %rdx
callq 0x3f60
movq -0x8(%rbp), %rdi
movq -0x1d8(%rbp), %rsi
leaq -0x240(%rbp), %rdx
callq 0x3f60
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x244(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x244(%rbp), %rcx
addq -0x210(%rbp,%rcx,8), %rax
movq %rax, -0x1d0(%rbp)
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x244(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x244(%rbp), %rcx
addq -0x240(%rbp,%rcx,8), %rax
movq %rax, -0x1d8(%rbp)
movq -0x1d8(%rbp), %rax
subq -0x1d0(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x10(%rcx), %rax
ja 0x2945c
jmp 0x2946c
jmp 0x2945e
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x2935b
movl -0x3c(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x2948e
movq -0x1d8(%rbp), %rax
subq -0x1d0(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x2948e
jmp 0x294ad
leaq 0x4c73(%rip), %rdi      # 0x2e108
leaq 0x4bc8(%rip), %rsi      # 0x2e064
movl $0xcf, %edx
leaq 0x4bc4(%rip), %rcx      # 0x2e06c
callq 0x2140
movl -0x3c(%rbp), %eax
addl $0x1, %eax
subl -0x4c(%rbp), %eax
movl %eax, -0x40(%rbp)
movq -0x1d8(%rbp), %rax
subq -0x1d0(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x80(%rbp), %rax
movq -0x70(%rbp), %rcx
addq -0x68(%rbp), %rcx
cmpq %rcx, %rax
jne 0x294e1
jmp 0x29779
movl -0x48(%rbp), %eax
addl $0x1, %eax
subl -0x44(%rbp), %eax
movl %eax, -0x54(%rbp)
movq 0x18(%rbp), %rax
movl $0x0, 0x10(%rax)
movq 0x18(%rbp), %rax
movl $0x0, (%rax)
movq -0x28(%rbp), %rdi
movslq -0x54(%rbp), %rax
addq %rax, %rdi
movl -0x4c(%rbp), %esi
addl -0x40(%rbp), %esi
movl -0x48(%rbp), %eax
addl $0x1, %eax
subl -0x44(%rbp), %eax
subl %eax, %esi
movq 0x18(%rbp), %rdx
callq 0x29790
movq 0x18(%rbp), %rax
movq 0x8(%rax), %rdi
movq 0x18(%rbp), %rax
movl (%rax), %esi
movq 0x18(%rbp), %rdx
addq $0x10, %rdx
callq 0x29790
movq 0x18(%rbp), %rax
movl 0x10(%rax), %edi
movq 0x18(%rbp), %rax
movq 0x18(%rax), %rsi
callq 0x14370
movq -0x80(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
cmpq (%rcx), %rax
jne 0x2956f
movq $0x0, -0x80(%rbp)
movq 0x10(%rbp), %rdi
movl -0x54(%rbp), %edx
leaq 0x4bac(%rip), %rsi      # 0x2e129
movb $0x0, %al
callq 0x273f0
movl -0x38(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0x2959a
movl -0x34(%rbp), %eax
subl -0x38(%rbp), %eax
movl %eax, -0x24c(%rbp)
jmp 0x295a4
xorl %eax, %eax
movl %eax, -0x24c(%rbp)
jmp 0x295a4
movl -0x24c(%rbp), %eax
movl %eax, -0x50(%rbp)
movq 0x18(%rbp), %rax
movq 0x8(%rax), %rdi
movq 0x18(%rbp), %rax
movq 0x18(%rax), %rsi
callq 0x21b0
cmpl $0x0, %eax
jg 0x2968e
movq 0x10(%rbp), %rdi
movl -0x44(%rbp), %edx
addl -0x50(%rbp), %edx
movl -0x38(%rbp), %ecx
subl -0x34(%rbp), %ecx
movl -0x40(%rbp), %r8d
addl -0x50(%rbp), %r8d
movq -0x70(%rbp), %r9
movq -0x80(%rbp), %r10
movq -0x68(%rbp), %rax
leaq 0x4b3a(%rip), %rsi      # 0x2e130
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x273f0
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq 0x18(%rbp), %rcx
cmpl (%rcx), %eax
jae 0x2964a
movq 0x18(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x3c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movslq %eax, %rcx
leaq 0x2d68(%rip), %rax      # 0x2c39a
movsbl (%rax,%rcx), %edi
movq 0x10(%rbp), %rsi
callq 0x28e70
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x2960d
movq 0x10(%rbp), %rsi
movl $0x9, %edi
callq 0x28e70
cmpq $0x0, -0x30(%rbp)
je 0x2967b
movq -0x30(%rbp), %rdi
movslq -0x54(%rbp), %rax
addq %rax, %rdi
movq 0x18(%rbp), %rax
movl (%rax), %esi
movq 0x10(%rbp), %rdx
callq 0x29790
jmp 0x29689
movq 0x10(%rbp), %rsi
movl $0x2a, %edi
callq 0x28e70
jmp 0x2976b
movq 0x10(%rbp), %rdi
movl -0x40(%rbp), %edx
addl -0x50(%rbp), %edx
movl -0x38(%rbp), %ecx
subl -0x34(%rbp), %ecx
movl -0x44(%rbp), %r8d
addl -0x50(%rbp), %r8d
movq -0x68(%rbp), %r9
movq -0x80(%rbp), %r10
movq -0x70(%rbp), %rax
leaq 0x4a8f(%rip), %rsi      # 0x2e148
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x273f0
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq 0x18(%rbp), %rcx
cmpl (%rcx), %eax
jae 0x2970d
movq 0x18(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x3c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movslq %eax, %rcx
leaq 0x2ca5(%rip), %rax      # 0x2c39a
movsbl (%rax,%rcx), %edi
movq 0x10(%rbp), %rsi
callq 0x28e70
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x296d0
movq 0x10(%rbp), %rsi
movl $0x9, %edi
callq 0x28e70
cmpq $0x0, -0x30(%rbp)
je 0x2975b
movl -0x54(%rbp), %eax
movq 0x18(%rbp), %rcx
addl (%rcx), %eax
subl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x54(%rbp), %eax
jl 0x29759
movq -0x30(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsbl (%rax,%rcx), %edi
movq 0x10(%rbp), %rsi
callq 0x28e70
movl -0x3c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x29731
jmp 0x29769
movq 0x10(%rbp), %rsi
movl $0x2a, %edi
callq 0x28e70
jmp 0x2976b
movq 0x10(%rbp), %rsi
movl $0xa, %edi
callq 0x28e70
addq $0x260, %rsp            # imm = 0x260
popq %rbp
retq
nopw %cs:(%rax,%rax)