// File: /workspace/github_c_makefile_star2_O1/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, %rbx
movq %rcx, %r13
movl %esi, %r10d
movq %rdi, %rbp
movq 0x1c8(%rsp), %rcx
movq 0x1c0(%rsp), %rsi
movq (%r13), %rax
movq %rax, 0x8(%rsp)
xorl %eax, %eax
movq %rax, (%rcx)
movq %r8, 0x38(%rsp)
movq %rax, (%r8)
movq %rsi, (%rsp)
movq %rax, (%rsi)
cmpq %rax, (%r9)
jne 0xb165
movslq %edx, %r14
movq 0x8(%rsp), %rdx
subl %r14d, %edx
movq 0x10(%r13), %rcx
addq %r14, %rcx
leal -0x1(%rdx), %r9d
subq $0x8, %rsp
leaq 0x68(%rsp), %rdi
movq %rbp, %rsi
movl %r10d, %r8d
pushq %rax
pushq %rbx
pushq %rax
callq 0xae17
addq $0x20, %rsp
movq (%rbx), %rax
testq %rax, %rax
je 0xb89f
movq 0x10(%rbx), %rcx
addq $0x18, %rcx
addq %r14, (%rcx)
addq $0x20, %rcx
decq %rax
jne 0xb159
movq 0x8(%rbx), %rax
movq 0x1c8(%rsp), %rcx
cmpq %rax, 0x8(%rcx)
jae 0xb1d0
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 0x1c8(%rsp), %r14
movq %rax, 0x8(%r14)
movq 0x10(%r14), %rdi
leaq 0x4(,%rcx,4), %rsi
callq 0x21d0
movq %rax, 0x10(%r14)
movq (%rbx), %rdx
testq %rdx, %rdx
je 0xb1ef
movq 0x1c8(%rsp), %rax
movq 0x10(%rax), %rdi
shlq $0x2, %rdx
xorl %esi, %esi
callq 0x2100
xorl %edi, %edi
cmpq $0x0, (%rbx)
movq %rbp, 0x40(%rsp)
je 0xb6da
movq $0x0, 0x48(%rsp)
movabsq $0x100000000, %r15      # imm = 0x100000000
movslq 0x8(%rsp), %rax
movq %rax, 0x58(%rsp)
movq %r13, 0x50(%rsp)
movq (%rsp), %r14
movq $0x0, (%r14)
movq %rbx, (%rsp)
cmpq $0x0, (%rbx)
je 0xb521
xorl %r13d, %r13d
movq 0x1c8(%rsp), %rax
movq 0x10(%rax), %rax
cmpl $0x0, (%rax,%r13,4)
js 0xb511
movq %r13, %rbx
shlq $0x5, %rbx
movq (%rsp), %rax
addq 0x10(%rax), %rbx
movq 0x40(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
leaq 0x60(%rsp), %rdx
xorl %ecx, %ecx
callq 0x9d23
movq 0x70(%rsp), %rdx
testq %rdx, %rdx
je 0xb408
movq 0x50(%rsp), %rax
movq 0x58(%rsp), %rcx
cmpq (%rax), %rcx
je 0xb408
movq 0x60(%rsp), %rsi
addq %rsi, %rdx
movq %r12, %rdi
leaq 0x150(%rsp), %rcx
leaq 0x120(%rsp), %r8
callq 0x9a53
movq 0x150(%rsp), %rcx
movq %rcx, 0x10(%rsp)
movq 0x68(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x120(%rsp), %rax
subq %rcx, %rax
movq %rax, 0x20(%rsp)
je 0xb408
movq 0x10(%rbx), %rcx
movq 0x70(%rsp), %rdx
xorq %rcx, %rdx
xorq %rcx, %rax
orq %rdx, %rax
jne 0xb3b1
movq 0x1c8(%rsp), %rax
movq 0x10(%rax), %rax
movl (%rax,%r13,4), %ecx
testq %r13, %r13
je 0xb321
cmpl -0x4(%rax,%r13,4), %ecx
jle 0xb8b6
movl 0x18(%rbx), %edx
movq 0x58(%rsp), %rsi
subq %rdx, %rsi
movq %rsi, 0x28(%rsp)
movq (%rsp), %rdx
movq (%rdx), %rdx
cmpq %r13, %rdx
jbe 0xb354
movq %r13, %rsi
cmpl %ecx, (%rax,%rsi,4)
jne 0xb354
movl $0xffffffff, (%rax,%rsi,4) # imm = 0xFFFFFFFF
incq %rsi
cmpq %rsi, %rdx
ja 0xb340
movq 0x38(%rsp), %rbx
movq 0x8(%rbx), %rax
cmpq %rax, (%rbx)
jne 0xb387
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%rbx)
movq 0x10(%rbx), %rdi
shlq $0x5, %rsi
callq 0x21d0
movq %rax, 0x10(%rbx)
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%rbx)
shlq $0x5, %rax
movups 0x10(%rsp), %xmm0
movups 0x20(%rsp), %xmm1
movups %xmm1, 0x10(%rcx,%rax)
movups %xmm0, (%rcx,%rax)
jmp 0xb511
cmpq $0x0, 0x1d0(%rsp)
je 0xb408
xorl %eax, %eax
movq 0x10(%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 0x18(%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 0x20(%rsp), %rax
jb 0xb3be
movq 0x1c8(%rsp), %rax
movq 0x10(%rax), %rax
cmpl $0x0, (%rax,%r13,4)
js 0xb511
xorl %ebp, %ebp
movq %r15, %r12
movq 0x90(%rsp,%rbp), %rdx
testq %rdx, %rdx
je 0xb4fd
movq 0x80(%rsp,%rbp), %rsi
addq %rsi, %rdx
movq 0x40(%rsp), %rdi
leaq 0x150(%rsp), %rcx
leaq 0x120(%rsp), %r8
callq 0x9a53
movq 0x150(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x88(%rsp,%rbp), %rcx
movq %rcx, 0x18(%rsp)
movq 0x120(%rsp), %rcx
subq %rax, %rcx
movq %rcx, 0x20(%rsp)
je 0xb4fd
movq 0x18(%rbx), %rax
movabsq $-0xf00000001, %rcx     # imm = 0xFFFFFFF0FFFFFFFF
andq %rcx, %rax
addq %r12, %rax
movq %rax, 0x98(%rsp,%rbp)
movq 0x8(%r14), %rax
cmpq %rax, (%r14)
jne 0xb4d0
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r14)
movq 0x10(%r14), %rdi
shlq $0x5, %rsi
callq 0x21d0
movq %rax, 0x10(%r14)
leaq 0x80(%rsp), %rax
addq %rbp, %rax
movq (%r14), %rcx
movq 0x10(%r14), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%r14)
shlq $0x5, %rcx
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups %xmm1, 0x10(%rdx,%rcx)
movups %xmm0, (%rdx,%rcx)
addq %r15, %r12
addq $0x20, %rbp
cmpq $0x80, %rbp
jne 0xb424
incq %r13
movq (%rsp), %rax
cmpq %r13, (%rax)
ja 0xb23e
cmpq $0x0, (%r14)
je 0xb6ba
movq 0x8(%r14), %rax
movq 0x1c8(%rsp), %rcx
cmpq %rax, 0x8(%rcx)
movq 0x50(%rsp), %r13
jae 0xb59b
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 0x1c8(%rsp), %rbx
movq %rax, 0x8(%rbx)
movq 0x10(%rbx), %rdi
leaq 0x4(,%rcx,4), %rsi
callq 0x21d0
movq %rax, 0x10(%rbx)
movq 0x10(%r14), %rax
movl 0x1c(%rax), %eax
andl $0xf, %eax
leal -0x1(%rax), %ecx
movl $0x5, %ebx
subl %eax, %ebx
cmpl $0x4, %ecx
cmovael %eax, %ebx
movq (%r13), %rax
incq %rax
cmpq 0x8(%r13), %rax
jb 0xb607
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, %rsi
shrq $0x10, %rsi
orq %rax, %rsi
incq %rsi
movq %rsi, 0x8(%r13)
movq 0x10(%r13), %rdi
callq 0x21d0
movq %rax, 0x10(%r13)
movq (%r13), %rax
movq 0x10(%r13), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r13)
movb %bl, (%rcx,%rax)
movq (%r13), %rax
movq 0x10(%r13), %rcx
movb $0x0, (%rcx,%rax)
movq (%r14), %rdi
movq 0x10(%r14), %rsi
callq 0xa665
movq 0x10(%r14), %rax
movq 0x18(%rax), %r8
movq 0x1c8(%rsp), %rcx
movq 0x10(%rcx), %rcx
movl $0x0, (%rcx)
movl %r8d, %edx
movq %rdx, 0x18(%rax)
movq (%r14), %rdx
cmpq $0x2, %rdx
jb 0xb6bf
shrq $0x20, %r8
addq $0x38, %rax
xorl %esi, %esi
movl $0x1, %edi
movq (%rax), %r10
movq %r10, %r9
shrq $0x20, %r9
movl %r8d, %r11d
cmpq %r11, %r9
cmovel %r8d, %r9d
movl %r10d, %r8d
cmovnel %edi, %esi
movl %esi, (%rcx,%rdi,4)
movq %rsi, %r10
shlq $0x24, %r10
orq %r8, %r10
movq %r10, (%rax)
incq %rdi
addq $0x20, %rax
movl %r9d, %r8d
cmpq %rdi, %rdx
jne 0xb66b
testl %esi, %esi
movq 0x48(%rsp), %rax
movl $0x1, %ecx
cmovnel %ecx, %eax
movq %rax, 0x48(%rsp)
jmp 0xb6bf
movq 0x50(%rsp), %r13
cmpq $0x0, (%r14)
movq %r14, %rbx
jne 0xb222
cmpl $0x0, 0x48(%rsp)
setne %dil
movq 0x40(%rsp), %rbp
movq 0x38(%rsp), %rdx
movq (%rdx), %r8
testq %r8, %r8
je 0xb89f
movq 0x10(%rdx), %rcx
movq 0x8(%rsp), %rsi
movl %esi, %eax
subl 0x18(%rcx), %eax
cmpq $0x1, %r8
sete %cl
andb %dil, %cl
cmpb $0x1, %cl
jne 0xb886
movq 0x20(%rbp), %rdx
movq (%rdx), %rcx
movq %rcx, 0x10(%rsp)
movq 0x8(%rdx), %rcx
subq (%rdx), %rcx
movq %rcx, 0x20(%rsp)
movq (%rdx), %rcx
movq %rcx, 0x18(%rsp)
movq $0x0, 0x28(%rsp)
movl %eax, (%rsp)
cmpl 0x8(%rsp), %eax
jge 0xb79d
movslq (%rsp), %rbx
movslq 0x8(%rsp), %r15
leaq 0x10(%rsp), %r14
leaq 0x60(%rsp), %r12
movq %rbp, %rdi
movq %r14, %rsi
movq %r12, %rdx
xorl %ecx, %ecx
callq 0x9d23
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, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
incq %rbx
cmpq %rbx, %r15
jne 0xb751
movslq 0x8(%rsp), %rbx
cmpq %rbx, (%r13)
jbe 0xb872
leaq 0x10(%rsp), %r14
leaq 0x60(%rsp), %r12
xorl %r15d, %r15d
movq 0x40(%rsp), %rdi
movq %r14, %rsi
movq %r12, %rdx
xorl %ecx, %ecx
callq 0x9d23
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl $0x1, %edx
xorl %ecx, %ecx
movq 0x90(%rsp,%r15), %rsi
testq %rsi, %rsi
je 0xb810
movq 0x80(%rsp,%r15), %rdi
movq 0x38(%rsp), %r8
movq 0x10(%r8), %r9
movq (%r9), %r8
cmpq %r8, %rdi
ja 0xb810
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 0xb7d7
testl %ecx, %ecx
jne 0xb82b
cmpq $0x0, 0x70(%rsp)
jne 0xb872
cmpl $0x1, %ecx
jne 0xb8d5
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, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
incq %rbx
cmpq %rbx, (%r13)
ja 0xb7b6
movq %rbx, (%r13)
movq 0x10(%r13), %rax
movb $0x0, (%rax,%rbx)
movq 0x38(%rsp), %rdx
movl (%rsp), %eax
cmpq $0x2, (%rdx)
jb 0xb8a4
movslq 0x8(%rsp), %rdx
movq %rdx, (%r13)
movq 0x10(%r13), %rcx
movb $0x0, (%rcx,%rdx)
jmp 0xb8a4
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xc02e(%rip), %rdi      # 0x178eb
leaq 0xbfbd(%rip), %rsi      # 0x17881
leaq 0xc042(%rip), %rcx      # 0x1790d
movl $0xa6, %edx
callq 0x20e0
leaq 0xc0a5(%rip), %rdi      # 0x17981
leaq 0xbf9e(%rip), %rsi      # 0x17881
leaq 0xc023(%rip), %rcx      # 0x1790d
movl $0xda, %edx
callq 0x20e0