// File: /workspace/github_c_makefile_star2_O3/lh3[P]fermi-lite/unitig.c
// Function: fm6_get_nei
int fm6_get_nei(const rld_t *e, int min_match, int beg, kstring_t *s, rldintv_v *nei, // input and output variables
				rldintv_v *prev, rldintv_v *curr, fm32s_v *cat,                        // temporary arrays
				uint64_t *used)                                                      // optional info
{
	int ori_l = s->l, j, i, c, rbeg, is_forked = 0;
	rldintv_v *swap;
	rldintv_t ok[6], ok0;

	curr->n = nei->n = cat->n = 0;
	if (prev->n == 0) { // when this routine is called for the seed, prev may filled by fm6_is_contained()
		overlap_intv(e, s->l - beg, (uint8_t*)s->s + beg, min_match, s->l - beg - 1, 0, prev, 0);
		if (prev->n == 0) return -1; // no overlap
		for (j = 0; j < prev->n; ++j) prev->a[j].info += beg;
	}
	kv_resize(int, *cat, prev->m);
	for (j = 0; j < prev->n; ++j) cat->a[j] = 0; // only one interval; all point to 0
	while (prev->n) {
		for (j = 0, curr->n = 0; j < prev->n; ++j) {
			rldintv_t *p = &prev->a[j];
			if (cat->a[j] < 0) continue;
			rld_extend(e, p, ok, 0); // forward extension
			if (ok[0].x[2] && ori_l != s->l) { // some (partial) reads end here
				rld_extend0(e, &ok[0], &ok0, 1); // backward extension to look for sentinels
				if (ok0.x[2]) { // the match is bounded by sentinels - a full-length match
					if (ok[0].x[2] == p->x[2] && p->x[2] == ok0.x[2]) { // never consider a read contained in another read
						int cat0 = cat->a[j]; // a category approximately corresponds to one neighbor, though not always
						assert(j == 0 || cat->a[j] > cat->a[j-1]); // otherwise not irreducible
						ok0.info = ori_l - (p->info&0xffffffffU);
						for (i = j; i < prev->n && cat->a[i] == cat0; ++i) cat->a[i] = -1; // mask out other intervals of the same cat
						kv_push(rldintv_t, *nei, ok0); // keep in the neighbor vector
						continue; // no need to go through for(c); do NOT set "used" as this neighbor may be rejected later
					} else if (used) set_bits(used, &ok0); // the read is contained in another read; mark it as used
				}
			} // ~if(ok[0].x[2])
			if (cat->a[j] < 0) continue; // no need to proceed if we have finished this path
			for (c = 1; c < 5; ++c) // collect extensible intervals
				if (ok[c].x[2]) {
					rld_extend0(e, &ok[c], &ok0, 1);
					if (ok0.x[2]) { // do not extend intervals whose left end is not bounded by a sentinel
						ok[c].info = (p->info&0xfffffff0ffffffffLLU) | (uint64_t)c<<32;
						kv_push(rldintv_t, *curr, ok[c]);
					}
				}
		} // ~for(j)
		if (curr->n) { // update category
			uint32_t last, cat0;
			kv_resize(int, *cat, curr->m);
			c = curr->a[0].info>>32&0xf;
			kputc(fm6_comp(c), s);
			ks_introsort(infocmp, curr->n, curr->a);
			last = curr->a[0].info >> 32;
			cat->a[0] = 0;
			curr->a[0].info &= 0xffffffff;
			for (j = 1, cat0 = 0; j < curr->n; ++j) { // this loop recalculate cat
				if (curr->a[j].info>>32 != last)
					last = curr->a[j].info>>32, cat0 = j;
				cat->a[j] = cat0;
				curr->a[j].info = (curr->a[j].info&0xffffffff) | (uint64_t)cat0<<36;
			}
			if (cat0 != 0) is_forked = 1;
		}
		swap = curr; curr = prev; prev = swap; // swap curr and prev
	} // ~while(prev->n)
	if (nei->n == 0) return -1; // no overlap
	rbeg = ori_l - (uint32_t)nei->a[0].info;
	if (nei->n == 1 && is_forked) { // this may happen if there are contained reads; fix this
		fm6_set_intv(e, 0, ok0);
		for (i = rbeg; i < ori_l; ++i) {
			rld_extend(e, &ok0, ok, 0);
			ok0 = ok[fm6_comp(s->s[i])];
		}
		for (i = ori_l; i < s->l; ++i) {
			int c0 = -1;
			rld_extend(e, &ok0, ok, 0);
			for (c = 1, j = 0; c < 5; ++c)
				if (ok[c].x[2] && ok[c].x[0] <= nei->a[0].x[0] && ok[c].x[0] + ok[c].x[2] >= nei->a[0].x[0] + nei->a[0].x[2])
					++j, c0 = c;
			if (j == 0 && ok[0].x[2]) break;
			assert(j == 1);
			s->s[i] = fm6_comp(c0);
			ok0 = ok[c0];
		}
		s->l = i; s->s[s->l] = 0;
	}
	if (nei->n > 1) s->l = ori_l, s->s[s->l] = 0;
	return rbeg;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x188, %rsp            # imm = 0x188
movq %r9, %r14
movq %rcx, %r13
movl %edx, %eax
movq %rdi, %r12
movq 0x1c8(%rsp), %rbp
movq 0x1c0(%rsp), %rbx
movq (%rcx), %rcx
movq %rcx, 0x8(%rsp)
xorl %r10d, %r10d
movq %r10, (%rbp)
movq %r8, 0x40(%rsp)
movq %r10, (%r8)
movq %r10, (%rbx)
movq (%r9), %rdx
testq %rdx, %rdx
jne 0xb640
movl %esi, %r11d
movslq %eax, %r15
movq 0x8(%rsp), %rdx
subl %r15d, %edx
movq 0x10(%r13), %rcx
addq %r15, %rcx
leal -0x1(%rdx), %r9d
subq $0x8, %rsp
leaq 0x68(%rsp), %rdi
movq %r12, %rsi
movl %r11d, %r8d
pushq %r10
pushq %r14
pushq %r10
callq 0xb2fe
addq $0x20, %rsp
movq (%r14), %rdx
testq %rdx, %rdx
je 0xbd50
movq 0x10(%r14), %rax
addq $0x18, %rax
movq %rdx, %rcx
addq %r15, (%rax)
addq $0x20, %rax
decq %rcx
jne 0xb634
movq 0x8(%r14), %rax
cmpq %rax, 0x8(%rbp)
movq %r12, 0x18(%rsp)
jae 0xb6ac
decq %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
leaq 0x1(%rcx), %rax
movq %rax, 0x8(%rbp)
movq 0x10(%rbp), %rdi
leaq 0x4(,%rcx,4), %rsi
callq 0x21c0
movq %rax, 0x10(%rbp)
movq (%r14), %rdx
testq %rdx, %rdx
je 0xbd67
movabsq $0x100000000, %r15      # imm = 0x100000000
movq 0x10(%rbp), %rdi
shlq $0x2, %rdx
movq $0x0, 0x48(%rsp)
xorl %esi, %esi
callq 0x2100
movslq 0x8(%rsp), %rax
movq %rax, 0x58(%rsp)
movq %r13, 0x50(%rsp)
movq $0x0, (%rbx)
movq %r14, 0x10(%rsp)
cmpq $0x0, (%r14)
je 0xbb80
xorl %r13d, %r13d
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax,%r13,4)
js 0xb9ba
movq %r13, %r14
shlq $0x5, %r14
movq 0x10(%rsp), %rax
addq 0x10(%rax), %r14
movq 0x18(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
leaq 0x60(%rsp), %rdx
xorl %ecx, %ecx
callq 0xa1c6
movq 0x70(%rsp), %rdx
testq %rdx, %rdx
movq 0x1c8(%rsp), %rbp
je 0xb8ba
movq 0x50(%rsp), %rax
movq 0x58(%rsp), %rcx
cmpq (%rax), %rcx
je 0xb8ba
movq 0x60(%rsp), %rsi
addq %rsi, %rdx
movq %r12, %rdi
leaq 0x150(%rsp), %rcx
leaq 0x120(%rsp), %r8
callq 0x9ef0
movq 0x150(%rsp), %rcx
movq %rcx, 0x20(%rsp)
movq 0x68(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x120(%rsp), %rax
subq %rcx, %rax
movq %rax, 0x30(%rsp)
je 0xb8ba
movq 0x10(%r14), %rcx
movq 0x70(%rsp), %rdx
xorq %rcx, %rdx
xorq %rcx, %rax
orq %rdx, %rax
jne 0xb863
movq 0x10(%rbp), %rax
movl (%rax,%r13,4), %ecx
testq %r13, %r13
je 0xb7d2
cmpl -0x4(%rax,%r13,4), %ecx
jle 0xbd6e
movl 0x18(%r14), %edx
movq 0x58(%rsp), %rsi
subq %rdx, %rsi
movq %rsi, 0x38(%rsp)
movq 0x10(%rsp), %rdx
movq (%rdx), %rdx
cmpq %r13, %rdx
jbe 0xb807
movq %r13, %rsi
cmpl %ecx, (%rax,%rsi,4)
jne 0xb807
movl $0xffffffff, (%rax,%rsi,4) # imm = 0xFFFFFFFF
incq %rsi
cmpq %rsi, %rdx
ja 0xb7f3
movq 0x40(%rsp), %r14
movq (%r14), %rcx
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rcx
jne 0xb840
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r14)
shlq $0x5, %rsi
movq %rax, %rdi
callq 0x21c0
movq %rax, 0x10(%r14)
movq (%r14), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%r14)
shlq $0x5, %rcx
movups 0x20(%rsp), %xmm0
movups 0x30(%rsp), %xmm1
movups %xmm1, 0x10(%rax,%rcx)
movups %xmm0, (%rax,%rcx)
jmp 0xb9ba
cmpq $0x0, 0x1d0(%rsp)
je 0xb8ba
xorl %eax, %eax
movq 0x20(%rsp), %rcx
addq %rax, %rcx
movq %rcx, %rdx
movl $0x1, %esi
shlq %cl, %rsi
shrq $0x6, %rdx
movq 0x1d0(%rsp), %rdi
lock
orq %rsi, (%rdi,%rdx,8)
movq 0x28(%rsp), %rcx
addq %rax, %rcx
movq %rcx, %rdx
movl $0x1, %esi
shlq %cl, %rsi
shrq $0x6, %rdx
lock
orq %rsi, (%rdi,%rdx,8)
incq %rax
cmpq 0x30(%rsp), %rax
jb 0xb870
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax,%r13,4)
js 0xb9ba
xorl %ebp, %ebp
movq %r15, %r12
movq 0x90(%rsp,%rbp), %rdx
testq %rdx, %rdx
je 0xb9a6
movq 0x80(%rsp,%rbp), %rsi
addq %rsi, %rdx
movq 0x18(%rsp), %rdi
leaq 0x150(%rsp), %rcx
leaq 0x120(%rsp), %r8
callq 0x9ef0
movq 0x150(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x88(%rsp,%rbp), %rcx
movq %rcx, 0x28(%rsp)
movq 0x120(%rsp), %rcx
subq %rax, %rcx
movq %rcx, 0x30(%rsp)
je 0xb9a6
movq 0x18(%r14), %rax
movabsq $-0xf00000001, %rcx     # imm = 0xFFFFFFF0FFFFFFFF
andq %rcx, %rax
addq %r12, %rax
movq %rax, 0x98(%rsp,%rbp)
movq (%rbx), %rcx
movq 0x10(%rbx), %rax
cmpq 0x8(%rbx), %rcx
jne 0xb980
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rbx)
shlq $0x5, %rsi
movq %rax, %rdi
callq 0x21c0
movq %rax, 0x10(%rbx)
movq (%rbx), %rcx
leaq 0x80(%rsp), %rdx
addq %rbp, %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%rbx)
shlq $0x5, %rcx
movups (%rdx), %xmm0
movups 0x10(%rdx), %xmm1
movups %xmm1, 0x10(%rax,%rcx)
movups %xmm0, (%rax,%rcx)
addq %r15, %r12
addq $0x20, %rbp
cmpq $0x80, %rbp
jne 0xb8ce
incq %r13
movq 0x10(%rsp), %rax
cmpq %r13, (%rax)
movq 0x1c8(%rsp), %rbp
ja 0xb6f6
cmpq $0x0, (%rbx)
je 0xbb76
movq 0x8(%rbx), %rax
cmpq %rax, 0x8(%rbp)
movq 0x50(%rsp), %r13
jae 0xba3d
decq %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
leaq 0x1(%rcx), %rax
movq %rax, 0x8(%rbp)
movq 0x10(%rbp), %rdi
leaq 0x4(,%rcx,4), %rsi
callq 0x21c0
movq %rax, 0x10(%rbp)
movq 0x10(%rbx), %rax
movl 0x1c(%rax), %eax
andl $0xf, %eax
leal -0x1(%rax), %ecx
movl $0x5, %ebp
subl %eax, %ebp
cmpl $0x4, %ecx
cmovael %eax, %ebp
movq (%r13), %rdx
leaq 0x1(%rdx), %rcx
cmpq 0x8(%r13), %rcx
movq 0x18(%rsp), %r12
jae 0xba70
movq 0x10(%r13), %rax
jmp 0xbabd
movq %rcx, %rax
shrq %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rsi
shrq $0x10, %rsi
orq %rcx, %rsi
incq %rsi
movq %rsi, 0x8(%r13)
movq 0x10(%r13), %rdi
callq 0x21c0
movq %rax, 0x10(%r13)
movq (%r13), %rdx
leaq 0x1(%rdx), %rcx
movq %rcx, (%r13)
movb %bpl, (%rax,%rdx)
movq (%r13), %rax
movq 0x10(%r13), %rcx
movb $0x0, (%rcx,%rax)
movq (%rbx), %rdi
movq 0x10(%rbx), %rsi
callq 0xab49
movq 0x10(%rbx), %rcx
movq 0x18(%rcx), %r8
movq 0x1c8(%rsp), %rbp
movq 0x10(%rbp), %rdx
movl $0x0, (%rdx)
movl %r8d, %eax
movq %rax, 0x18(%rcx)
movq (%rbx), %rax
cmpq $0x2, %rax
jb 0xbb63
shrq $0x20, %r8
addq $0x38, %rcx
xorl %esi, %esi
movl $0x1, %edi
movq (%rcx), %r10
movq %r10, %r9
shrq $0x20, %r9
movl %r8d, %r11d
cmpq %r11, %r9
cmovel %r8d, %r9d
movl %r10d, %r8d
cmovnel %edi, %esi
movl %esi, (%rdx,%rdi,4)
movq %rsi, %r10
shlq $0x24, %r10
orq %r8, %r10
movq %r10, (%rcx)
incq %rdi
addq $0x20, %rcx
movl %r9d, %r8d
cmpq %rdi, %rax
jne 0xbb16
testl %esi, %esi
movq 0x48(%rsp), %rcx
movl $0x1, %edx
cmovnel %edx, %ecx
movq %rcx, 0x48(%rsp)
movq %rbx, %r14
movq 0x10(%rsp), %rbx
testq %rax, %rax
jne 0xb6dd
jmp 0xbb80
movq 0x50(%rsp), %r13
movq 0x18(%rsp), %r12
cmpl $0x0, 0x48(%rsp)
setne %cl
movq 0x40(%rsp), %rdx
movq (%rdx), %rdi
testq %rdi, %rdi
je 0xbd50
movq 0x10(%rdx), %rdx
movq 0x8(%rsp), %rsi
movl %esi, %eax
subl 0x18(%rdx), %eax
cmpq $0x1, %rdi
sete %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0xbd37
movq 0x20(%r12), %rdx
movq (%rdx), %rcx
movq %rcx, 0x20(%rsp)
movq 0x8(%rdx), %rdx
subq %rcx, %rdx
movq %rdx, 0x30(%rsp)
movq %rcx, 0x28(%rsp)
movq $0x0, 0x38(%rsp)
movl %eax, 0x10(%rsp)
cmpl 0x8(%rsp), %eax
jge 0xbc4a
movslq 0x10(%rsp), %rbx
movslq 0x8(%rsp), %r15
leaq 0x20(%rsp), %r14
leaq 0x60(%rsp), %rbp
movq %r12, %rdi
movq %r14, %rsi
movq %rbp, %rdx
xorl %ecx, %ecx
callq 0xa1c6
movq 0x10(%r13), %rax
movzbl (%rax,%rbx), %eax
movb $0x5, %cl
subb %al, %cl
leal -0x1(%rax), %edx
cmpb $0x4, %dl
movzbl %cl, %ecx
cmovael %eax, %ecx
movsbq %cl, %rax
shlq $0x5, %rax
movups 0x60(%rsp,%rax), %xmm0
movups 0x70(%rsp,%rax), %xmm1
movaps %xmm1, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
incq %rbx
cmpq %rbx, %r15
jne 0xbbfe
movslq 0x8(%rsp), %rbx
cmpq %rbx, (%r13)
jbe 0xbd1f
leaq 0x20(%rsp), %r14
leaq 0x60(%rsp), %r12
xorl %r15d, %r15d
movq 0x18(%rsp), %rdi
movq %r14, %rsi
movq %r12, %rdx
xorl %ecx, %ecx
callq 0xa1c6
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl $0x1, %edx
xorl %ecx, %ecx
movq 0x90(%rsp,%r15), %rsi
testq %rsi, %rsi
je 0xbcbd
movq 0x80(%rsp,%r15), %rdi
movq 0x40(%rsp), %r8
movq 0x10(%r8), %r9
movq (%r9), %r8
cmpq %r8, %rdi
ja 0xbcbd
addq 0x10(%r9), %r8
addq %rsi, %rdi
cmpq %r8, %rdi
sbbl $-0x1, %ecx
cmpq %r8, %rdi
cmovael %edx, %eax
addq $0x20, %r15
incl %edx
cmpq $0x80, %r15
jne 0xbc84
testl %ecx, %ecx
jne 0xbcd8
cmpq $0x0, 0x70(%rsp)
jne 0xbd1f
cmpl $0x1, %ecx
jne 0xbd8d
leal -0x1(%rax), %ecx
movb $0x5, %dl
subb %al, %dl
cmpl $0x4, %ecx
movzbl %dl, %ecx
cmovael %eax, %ecx
movq 0x10(%r13), %rdx
movb %cl, (%rdx,%rbx)
cltq
shlq $0x5, %rax
movups 0x60(%rsp,%rax), %xmm0
movups 0x70(%rsp,%rax), %xmm1
movaps %xmm1, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
incq %rbx
cmpq %rbx, (%r13)
ja 0xbc63
movq %rbx, (%r13)
movq 0x10(%r13), %rax
movb $0x0, (%rax,%rbx)
movq 0x40(%rsp), %rax
movq (%rax), %rdi
movl 0x10(%rsp), %eax
cmpq $0x2, %rdi
jb 0xbd55
movslq 0x8(%rsp), %rdx
movq %rdx, (%r13)
movq 0x10(%r13), %rcx
movb $0x0, (%rcx,%rdx)
jmp 0xbd55
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %ecx, %ecx
jmp 0xbb88
leaq 0xbbe6(%rip), %rdi      # 0x1795b
leaq 0xbb75(%rip), %rsi      # 0x178f1
leaq 0xbbfa(%rip), %rcx      # 0x1797d
movl $0xa6, %edx
callq 0x20e0
leaq 0xbc5d(%rip), %rdi      # 0x179f1
leaq 0xbb56(%rip), %rsi      # 0x178f1
leaq 0xbbdb(%rip), %rcx      # 0x1797d
movl $0xda, %edx
callq 0x20e0