// File: /workspace/github_c_makefile_star2_O1/lh3[P]minigraph/gfa-base.c
// Function: gfa_fix_multi
uint32_t gfa_fix_multi(gfa_t *g)
{
	uint32_t v, n_vtx = gfa_n_vtx(g), n_rm = 0;
	int32_t max_nv = -1;
	uint64_t *buf; // actually, uint32_t is enough
	for (v = 0; v < n_vtx; ++v) {
		int32_t nv = gfa_arc_n(g, v);
		max_nv = max_nv > nv? max_nv : nv;
	}
	if (max_nv == 1) return 0;
	GFA_MALLOC(buf, max_nv);
	for (v = 0; v < n_vtx; ++v) {
		int32_t i, j, s, nv = gfa_arc_n(g, v), nb;
		gfa_arc_t *av = gfa_arc_a(g, v);
		for (i = j = 0; i < nv; ++i)
			if (!av[i].del) buf[j++] = (uint64_t)av[i].w<<32 | i;
		nb = j;
		if (nb < 1) continue;
		radix_sort_gfa64(buf, buf + nb);
		for (s = 0, i = 1; i <= nb; ++i) {
			if (i == nv || buf[i]>>32 != buf[s]>>32) {
				if (i - s > 1) {
					int32_t k = (int32_t)buf[s], min_rank = av[k].rank; // prefer longest overlap
					for (j = s + 1; j < i; ++j) { // rank has higher priority
						int32_t t = (int32_t)buf[j];
						if (av[t].rank >= 0 && av[t].rank < min_rank)
							min_rank = av[t].rank, k = t;
					}
					if (av[k].w == (v^1)) { // a weird loop
						if (gfa_verbose >= 2)
							fprintf(stderr, "[W::%s] can't fix multiple edges due to '>v -- <v' involving segment %s\n", __func__, g->seg[v>>1].name);
					} else {
						int32_t nw = gfa_arc_n(g, av[k].w^1), n_wdel;
						gfa_arc_t *aw = gfa_arc_a(g, av[k].w^1);
						uint64_t link_id = av[k].link_id;
						n_rm += i - s - 1;
						for (j = s + 1; j < i; ++j)
							av[(int32_t)buf[j]].del = 1;
						for (j = 0, n_wdel = 0; j < nw; ++j)
							if (aw[j].w == (v^1) && aw[j].link_id != link_id)
								aw[j].del = 1, ++n_wdel;
						assert(n_wdel == i - s - 1);
					}
				}
				s = i;
			}
		}
	}
	free(buf);
	if (n_rm > 0) {
		if (gfa_verbose >= 2)
			fprintf(stderr, "[W::%s] removed %d multiple link(s)\n", __func__, n_rm);
		gfa_arc_rm(g);
		gfa_arc_index(g);
	}
	return n_rm;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %r14
movl 0x4(%rdi), %ebx
addl %ebx, %ebx
je 0x5e57
movq 0x58(%r14), %rcx
movl %ebx, %edx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
xorl %esi, %esi
movl (%rcx,%rsi,8), %edi
cmpl %edi, %eax
cmovlel %edi, %eax
incq %rsi
cmpq %rsi, %rdx
jne 0x5e45
jmp 0x5e5c
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
xorl %r15d, %r15d
cmpl $0x1, %eax
je 0x60fe
movslq %eax, %rdi
shlq $0x3, %rdi
callq 0x2280
movq %rax, %r15
testl %ebx, %ebx
je 0x60cc
movabsq $0x4000000000000000, %rbp # imm = 0x4000000000000000
leaq 0x10(%r14), %rax
movq %rax, 0x18(%rsp)
movl %ebx, %eax
movq %rax, 0x28(%rsp)
xorl %ebx, %ebx
movq $0x0, (%rsp)
movq %r14, 0x10(%rsp)
movq 0x48(%r14), %r12
movq 0x58(%r14), %rax
movq (%rax,%rbx,8), %r13
movq %r13, %rax
shrq $0x20, %rax
shlq $0x5, %rax
movl $0x0, %r14d
testl %r13d, %r13d
jle 0x5f05
movl %r13d, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
leaq (%r12,%rax), %rdx
addq $0x18, %rdx
xorl %esi, %esi
xorl %r14d, %r14d
testq %rbp, (%rdx)
jne 0x5ef9
movl -0x10(%rdx), %edi
shlq $0x20, %rdi
addq %rsi, %rdi
movslq %r14d, %r8
incl %r14d
movq %rdi, (%r15,%r8,8)
incq %rsi
addq $0x20, %rdx
cmpq %rsi, %rcx
jne 0x5ee0
testl %r14d, %r14d
movq %rbx, 0x30(%rsp)
jle 0x60b2
addq %rax, %r12
movl %r14d, %eax
leaq (%r15,%rax,8), %rsi
movq %r15, %rdi
callq 0x48ff
movq %rbx, %rax
xorl $0x1, %ebx
shrl %eax
movq %rax, 0x20(%rsp)
movl %r13d, %edx
incl %r14d
xorl %ecx, %ecx
movl $0x1, %r13d
movq %rdx, 0x8(%rsp)
cmpq %rdx, %r13
je 0x5f5f
movslq %ecx, %rax
movq (%r15,%rax,8), %rax
xorq (%r15,%r13,8), %rax
shrq $0x20, %rax
je 0x60a6
movl %r13d, %eax
subl %ecx, %eax
cmpl $0x2, %eax
jl 0x5fc5
movslq %ecx, %rdx
movq (%r15,%rdx,8), %rdx
incl %ecx
movslq %ecx, %rcx
cmpq %rcx, %r13
jle 0x5fcd
movslq %edx, %rsi
shlq $0x5, %rsi
movl 0xc(%r12,%rsi), %r8d
leaq 0x1(%rcx), %rsi
movq -0x8(%r15,%rsi,8), %rdi
movslq %edi, %r9
shlq $0x5, %r9
movl 0xc(%r12,%r9), %r9d
testl %r9d, %r9d
setns %r10b
cmpl %r8d, %r9d
setl %r11b
testb %r11b, %r10b
jne 0x5fb3
movl %edx, %edi
movl %r8d, %r9d
movl %esi, %r10d
incq %rsi
movl %r9d, %r8d
movl %edi, %edx
cmpq %r13, %r10
jne 0x5f8a
jmp 0x5fcf
movl %r13d, %ecx
jmp 0x60a6
movl %edx, %edi
movslq %edi, %rsi
shlq $0x5, %rsi
movl 0x8(%r12,%rsi), %edx
cmpl %ebx, %edx
jne 0x6000
cmpl $0x2, 0x2c20a(%rip)     # 0x321f0
jl 0x609e
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x2579
jmp 0x609e
addq %r12, %rsi
movq 0x10(%rsp), %r8
movq 0x48(%r8), %rdi
movq 0x58(%r8), %r8
xorq $0x1, %rdx
movq (%r8,%rdx,8), %rdx
movq 0x18(%rsi), %rsi
cmpq %rcx, %r13
jle 0x603d
incq %rcx
movslq -0x8(%r15,%rcx,8), %r8
shlq $0x5, %r8
orq %rbp, 0x18(%r12,%r8)
movl %ecx, %r8d
incq %rcx
cmpq %r13, %r8
jne 0x6024
testl %edx, %edx
jle 0x6085
movq %rdx, %rcx
shrq $0x20, %rcx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
shlq $0x5, %rcx
addq %rcx, %rdi
addq $0x18, %rdi
xorl %ecx, %ecx
cmpl %ebx, -0x10(%rdi)
jne 0x607a
movq (%rdi), %r8
movq %r8, %r9
xorq %rsi, %r9
shlq $0x3, %r9
testq %r9, %r9
je 0x607a
orq %rbp, %r8
movq %r8, (%rdi)
incl %ecx
addq $0x20, %rdi
decq %rdx
jne 0x605b
jmp 0x6087
xorl %ecx, %ecx
leal -0x1(%rax), %edx
cmpl %edx, %ecx
jne 0x6134
movq (%rsp), %rcx
addl %eax, %ecx
decl %ecx
movq %rcx, (%rsp)
movl %r13d, %ecx
movq 0x8(%rsp), %rdx
incq %r13
cmpq %r14, %r13
jne 0x5f45
movq 0x30(%rsp), %rbx
incq %rbx
cmpq 0x28(%rsp), %rbx
movq 0x10(%rsp), %r14
jne 0x5ea8
jmp 0x60d4
movq $0x0, (%rsp)
movq %r15, %rdi
callq 0x2040
movq (%rsp), %r15
testl %r15d, %r15d
je 0x60fe
cmpl $0x2, 0x2c104(%rip)     # 0x321f0
jge 0x6110
movq %r14, %rdi
callq 0x5b95
movq %r14, %rdi
callq 0x55e1
movl %r15d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x2bee1(%rip), %rax     # 0x31ff8
movq (%rax), %rdi
leaq 0x222dc(%rip), %rsi     # 0x283fd
leaq 0x22293(%rip), %rdx     # 0x283bb
movl %r15d, %ecx
xorl %eax, %eax
callq 0x2210
jmp 0x60ee
leaq 0x2228e(%rip), %rdi     # 0x283c9
leaq 0x220ae(%rip), %rsi     # 0x281f0
leaq 0x22294(%rip), %rcx     # 0x283dd
movl $0x194, %edx            # imm = 0x194
callq 0x2160