// File: /workspace/github_c_makefile_star2_O2/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 $0x128, %rsp            # imm = 0x128
movq %r9, %r12
movq %r8, %r14
movl %esi, %r8d
movq 0x168(%rsp), %r15
movq (%rcx), %rsi
andq $0x0, (%r15)
movq %rdi, 0x8(%rsp)
andq $0x0, (%r14)
movq 0x160(%rsp), %r13
andq $0x0, (%r13)
movq %rsi, %rax
movq %rsi, 0x50(%rsp)
movl %eax, 0x14(%rsp)
movq (%r9), %rax
testq %rax, %rax
movq %rcx, (%rsp)
je 0x9fe8
movq 0x8(%r12), %rcx
cmpq %rcx, 0x8(%r15)
jae 0x9b61
decq %rcx
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, %rax
shrq $0x10, %rax
orq %rcx, %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%r15)
movq 0x10(%r15), %rdi
leaq 0x4(,%rax,4), %rsi
callq 0x21c0
movq %rax, 0x10(%r15)
movq (%r12), %rax
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x9b75
movq 0x10(%r15), %rdx
andl $0x0, (%rdx,%rcx,4)
incq %rcx
jmp 0x9b63
movslq 0x50(%rsp), %rcx
movq %rcx, 0x20(%rsp)
movq $0x0, 0x28(%rsp)
movq %r14, 0x18(%rsp)
testq %rax, %rax
sete %al
movq %r13, %rcx
testb $0x1, %al
jne 0x9f22
movq %r12, %r13
movq %rcx, %r12
andq $0x0, (%rcx)
xorl %ebx, %ebx
movq %r13, 0x58(%rsp)
cmpq %rbx, (%r13)
jbe 0x9e0a
movq 0x10(%r15), %rax
cmpl $0x0, (%rax,%rbx,4)
js 0x9df5
movq %rbx, %r14
shlq $0x5, %r14
movq 0x58(%rsp), %r13
addq 0x10(%r13), %r14
movq 0x8(%rsp), %rdi
movq %r14, %rsi
leaq 0x60(%rsp), %rdx
xorl %ecx, %ecx
callq 0x873b
cmpq $0x0, 0x70(%rsp)
movq 0x168(%rsp), %r15
je 0x9cbc
movq (%rsp), %rax
movq 0x20(%rsp), %rcx
cmpq (%rax), %rcx
je 0x9cbc
movq 0x8(%rsp), %rdi
leaq 0x60(%rsp), %rsi
leaq 0x30(%rsp), %rdx
pushq $0x1
popq %rcx
callq 0x885c
movq 0x40(%rsp), %rax
testq %rax, %rax
je 0x9cbc
movq 0x10(%r14), %rcx
movq 0x70(%rsp), %rdx
xorq %rcx, %rdx
xorq %rcx, %rax
orq %rdx, %rax
jne 0x9c9f
movq 0x10(%r15), %rax
movl (%rax,%rbx,4), %ecx
testq %rbx, %rbx
je 0x9c60
cmpl -0x4(%rax,%rbx,4), %ecx
jle 0xa16f
movl 0x18(%r14), %edx
movq 0x20(%rsp), %rsi
subq %rdx, %rsi
movq %rsi, 0x48(%rsp)
movq (%r13), %rdx
cmpq %rbx, %rdx
cmovbeq %rbx, %rdx
movq %rbx, %rsi
movq 0x18(%rsp), %r14
cmpq %rsi, %rdx
je 0x9da5
cmpl %ecx, (%rax,%rsi,4)
jne 0x9da5
orl $-0x1, (%rax,%rsi,4)
incq %rsi
jmp 0x9c84
cmpq $0x0, 0x170(%rsp)
je 0x9cbc
movq 0x170(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0xa1ad
movq 0x10(%r15), %rax
cmpl $0x0, (%rax,%rbx,4)
js 0x9df5
movabsq $0x100000000, %rbp      # imm = 0x100000000
xorl %r15d, %r15d
cmpq $0x80, %r15
je 0x9df5
cmpq $0x0, 0x90(%rsp,%r15)
je 0x9d8f
leaq 0x80(%rsp), %rax
leaq (%rax,%r15), %r13
movq 0x8(%rsp), %rdi
movq %r13, %rsi
leaq 0x30(%rsp), %rdx
pushq $0x1
popq %rcx
callq 0x885c
cmpq $0x0, 0x40(%rsp)
je 0x9d8f
movq 0x18(%r14), %rax
movabsq $-0xf00000001, %rcx     # imm = 0xFFFFFFF0FFFFFFFF
andq %rcx, %rax
addq %rbp, %rax
movq %rax, 0x98(%rsp,%r15)
movq (%r12), %rcx
movq 0x10(%r12), %rax
cmpq 0x8(%r12), %rcx
jne 0x9d70
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r12)
shlq $0x5, %rsi
movq %rax, %rdi
callq 0x21c0
movq %rax, 0x10(%r12)
movq (%r12), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%r12)
shlq $0x5, %rcx
movups (%r13), %xmm0
movups 0x10(%r13), %xmm1
movups %xmm1, 0x10(%rax,%rcx)
movups %xmm0, (%rax,%rcx)
addq $0x20, %r15
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %rbp
jmp 0x9cd7
movq (%r14), %rcx
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rcx
jne 0x9dd7
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
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 0x30(%rsp), %xmm0
movups 0x40(%rsp), %xmm1
movups %xmm1, 0x10(%rax,%rcx)
movups %xmm0, (%rax,%rcx)
incq %rbx
movq 0x168(%rsp), %r15
movq 0x58(%rsp), %r13
jmp 0x9baf
movb $0x1, %al
cmpq $0x0, (%r12)
movq %r13, %rcx
movq 0x18(%rsp), %r14
je 0x9b96
movq 0x8(%r12), %rax
cmpq %rax, 0x8(%r15)
jae 0x9e7b
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(%r15)
movq 0x10(%r15), %rdi
leaq 0x4(,%rcx,4), %rsi
callq 0x21c0
movq %rax, 0x10(%r15)
movq 0x10(%r12), %rax
movl 0x1c(%rax), %eax
andl $0xf, %eax
leal -0x1(%rax), %ecx
pushq $0x5
popq %rdi
subl %eax, %edi
cmpl $0x4, %ecx
cmovael %eax, %edi
movq (%rsp), %rsi
callq 0x8a58
movq (%r12), %rdi
movq 0x10(%r12), %rsi
callq 0x90bc
movq 0x10(%r12), %rcx
movq 0x18(%rcx), %r8
movl %r8d, %eax
shrq $0x20, %r8
movq 0x10(%r15), %rdx
andl $0x0, (%rdx)
movq %rax, 0x18(%rcx)
movq (%r12), %rax
addq $0x38, %rcx
xorl %esi, %esi
pushq $0x1
popq %rdi
cmpq %rdi, %rax
jbe 0x9f0b
movq (%rcx), %r9
movl %r9d, %r10d
shrq $0x20, %r9
movl %r8d, %r11d
cmpq %r11, %r9
cmovel %r8d, %r9d
cmovnel %edi, %esi
movl %esi, (%rdx,%rdi,4)
movq %rsi, %r8
shlq $0x24, %r8
orq %r10, %r8
movq %r8, (%rcx)
incq %rdi
addq $0x20, %rcx
movl %r9d, %r8d
jmp 0x9ed3
testl %esi, %esi
pushq $0x1
popq %rcx
movq 0x28(%rsp), %rdx
cmovnel %ecx, %edx
movq %rdx, 0x28(%rsp)
jmp 0x9b8d
movq (%r14), %rax
testq %rax, %rax
pushq $-0x1
popq %rdx
je 0xa15b
movq 0x10(%r14), %rcx
movl 0x18(%rcx), %ecx
movl 0x14(%rsp), %edx
subl %ecx, %edx
cmpq $0x1, %rax
jne 0xa141
cmpl $0x0, 0x28(%rsp)
movq (%rsp), %rcx
je 0xa145
movq 0x8(%rsp), %rax
movq 0x20(%rax), %rax
movq (%rax), %rcx
leaq 0x30(%rsp), %rbx
movq %rcx, (%rbx)
movq 0x8(%rax), %rax
subq %rcx, %rax
movq %rax, 0x10(%rbx)
movq %rcx, 0x8(%rbx)
andq $0x0, 0x18(%rbx)
movl %edx, %r13d
movslq %edx, %r15
movslq 0x50(%rsp), %r12
leaq 0x60(%rsp), %r14
cmpq %r12, %r15
jge 0xa047
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x873b
movq (%rsp), %rax
movq 0x10(%rax), %rax
movzbl (%rax,%r15), %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, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
incq %r15
jmp 0x9f8f
movslq %edx, %rbx
movl 0x14(%rsp), %eax
movl %eax, %edx
subl %ebx, %edx
movq 0x10(%rcx), %rcx
addq %rbx, %rcx
leal -0x1(%rdx), %r9d
subq $0x8, %rsp
leaq 0x68(%rsp), %rdi
movq 0x10(%rsp), %rsi
pushq $0x0
pushq %r12
pushq $0x0
callq 0x980a
addq $0x20, %rsp
movq (%r12), %rax
testq %rax, %rax
je 0xa13c
movq 0x10(%r12), %rcx
addq $0x18, %rcx
movq %rax, %rdx
subq $0x1, %rdx
jb 0x9b01
addq %rbx, (%rcx)
addq $0x20, %rcx
jmp 0xa034
leaq 0x30(%rsp), %rbx
leaq 0x60(%rsp), %r14
pushq $-0x1
popq %rbp
movq 0x20(%rsp), %r12
movq (%rsp), %rsi
cmpq %r12, (%rsi)
jbe 0xa11f
xorl %r15d, %r15d
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x873b
pushq $0x1
popq %rdx
xorl %ecx, %ecx
movl %ebp, %eax
cmpq $0x80, %r15
je 0xa0cc
movq 0x90(%rsp,%r15), %rsi
testq %rsi, %rsi
je 0xa0c4
movq 0x80(%rsp,%r15), %rdi
movq 0x18(%rsp), %r8
movq 0x10(%r8), %r9
movq (%r9), %r8
cmpq %r8, %rdi
ja 0xa0c4
addq 0x10(%r9), %r8
addq %rsi, %rdi
cmpq %r8, %rdi
sbbl $-0x1, %ecx
cmpq %r8, %rdi
cmovael %edx, %eax
addq $0x20, %r15
incl %edx
jmp 0xa082
testl %ecx, %ecx
jne 0xa0d8
cmpq $0x0, 0x70(%rsp)
jne 0xa11f
cmpl $0x1, %ecx
jne 0xa18e
leal -0x1(%rax), %ecx
movb $0x5, %dl
subb %al, %dl
cmpl $0x4, %ecx
movzbl %dl, %ecx
cmovael %eax, %ecx
movq (%rsp), %rsi
movq 0x10(%rsi), %rdx
movb %cl, (%rdx,%r12)
cltq
shlq $0x5, %rax
movups 0x60(%rsp,%rax), %xmm0
movups 0x70(%rsp,%rax), %xmm1
movaps %xmm1, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
incq %r12
jmp 0xa05d
movq (%rsp), %rcx
movq %r12, (%rcx)
movq 0x10(%rcx), %rax
movb $0x0, (%rax,%r12)
movq 0x18(%rsp), %rax
movq (%rax), %rax
movl %r13d, %edx
jmp 0xa145
pushq $-0x1
popq %rdx
jmp 0xa15b
movq (%rsp), %rcx
cmpq $0x2, %rax
jb 0xa15b
movq 0x20(%rsp), %rsi
movq %rsi, (%rcx)
movq 0x10(%rcx), %rax
movb $0x0, (%rax,%rsi)
movl %edx, %eax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xa795(%rip), %rdi      # 0x1490b
leaq 0xa724(%rip), %rsi      # 0x148a1
leaq 0xa7a9(%rip), %rcx      # 0x1492d
movl $0xa6, %edx
callq 0x20e0
leaq 0xa80c(%rip), %rdi      # 0x149a1
leaq 0xa705(%rip), %rsi      # 0x148a1
leaq 0xa78a(%rip), %rcx      # 0x1492d
movl $0xda, %edx
callq 0x20e0