// File: /workspace/github_c_makefile_star2_O2/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, 0x8(%rsp)
movl 0x4(%rdi), %ebp
addl %ebp, %ebp
pushq $-0x1
popq %rax
xorl %ecx, %ecx
cmpq %rcx, %rbp
je 0x505a
movq 0x8(%rsp), %rdx
movq 0x58(%rdx), %rdx
movl (%rdx,%rcx,8), %edx
cmpl %edx, %eax
cmovlel %edx, %eax
incq %rcx
jmp 0x503f
cmpl $0x1, %eax
je 0x52ef
movabsq $0x4000000000000000, %r15 # imm = 0x4000000000000000
movslq %eax, %rdi
shlq $0x3, %rdi
callq 0x2280
movq %rax, %r14
xorl %ecx, %ecx
movl $0x0, 0x14(%rsp)
movq %rbp, 0x28(%rsp)
cmpq %rbp, %rcx
je 0x52bf
movq 0x8(%rsp), %rax
movq 0x48(%rax), %rdx
movq 0x58(%rax), %rax
movq %rcx, 0x20(%rsp)
movq (%rax,%rcx,8), %rbx
movq %rbx, %rsi
shrq $0x1b, %rsi
andq $-0x20, %rsi
leaq (%rdx,%rsi), %r13
xorl %eax, %eax
testl %ebx, %ebx
movl $0x0, %ecx
cmovgl %ebx, %ecx
addq %rsi, %rdx
addq $0x18, %rdx
xorl %r12d, %r12d
cmpq %rax, %rcx
je 0x50f6
testq %r15, (%rdx)
jne 0x50ed
movl -0x10(%rdx), %esi
shlq $0x20, %rsi
addq %rax, %rsi
movslq %r12d, %rdi
incl %r12d
movq %rsi, (%r14,%rdi,8)
incq %rax
addq $0x20, %rdx
jmp 0x50cf
testl %r12d, %r12d
jle 0x52b2
movl %r12d, %eax
leaq (%r14,%rax,8), %rsi
movq %r14, %rdi
callq 0x3d53
movq 0x20(%rsp), %rax
movl %eax, %ebp
xorl $0x1, %ebp
shrl %eax
movl %ebx, %esi
incl %r12d
xorl %ecx, %ecx
shlq $0x6, %rax
movq %rax, 0x30(%rsp)
pushq $0x1
popq %rbx
movq %rsi, 0x18(%rsp)
cmpq %r12, %rbx
je 0x52ad
movslq %ecx, %rdx
cmpq %rsi, %rbx
je 0x5155
movq (%r14,%rdx,8), %rax
xorq (%r14,%rbx,8), %rax
shrq $0x20, %rax
je 0x52a5
movl %ebx, %eax
subl %ecx, %eax
cmpl $0x2, %eax
jl 0x5207
movq (%r14,%rdx,8), %rdx
movslq %edx, %rsi
shlq $0x5, %rsi
movl 0xc(%r13,%rsi), %edi
incl %ecx
movslq %ecx, %rcx
movq %rcx, %rsi
cmpq %rbx, %rsi
jge 0x51b3
movq (%r14,%rsi,8), %r8
movslq %r8d, %r9
shlq $0x5, %r9
movl 0xc(%r13,%r9), %r9d
testl %r9d, %r9d
setns %r10b
cmpl %edi, %r9d
setl %r11b
testb %r11b, %r10b
jne 0x51a8
movl %edx, %r8d
movl %edi, %r9d
incq %rsi
movl %r8d, %edx
movl %r9d, %edi
jmp 0x517a
movslq %edx, %rsi
shlq $0x5, %rsi
movl 0x8(%r13,%rsi), %edx
cmpl %ebp, %edx
jne 0x520e
cmpl $0x2, 0x29026(%rip)     # 0x2e1f0
jl 0x529e
movq 0x28e21(%rip), %rax     # 0x2dff8
movq (%rax), %rdi
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x30(%rsp), %rcx
movq 0x18(%rax,%rcx), %rcx
leaq 0x1e17e(%rip), %rsi     # 0x23372
leaq 0x1e1c0(%rip), %rdx     # 0x233bb
xorl %eax, %eax
callq 0x2210
jmp 0x529e
movl %ebx, %ecx
jmp 0x52a5
addq %r13, %rsi
movq 0x8(%rsp), %r8
movq 0x48(%r8), %rdi
movq 0x58(%r8), %r8
xorq $0x1, %rdx
movq (%r8,%rdx,8), %rdx
movq %rdx, %r8
shrq $0x20, %r8
movq 0x18(%rsi), %rsi
decl %eax
cmpq %rbx, %rcx
jge 0x524a
movslq (%r14,%rcx,8), %r9
shlq $0x5, %r9
orq %r15, 0x18(%r13,%r9)
incq %rcx
jmp 0x5233
xorl %ecx, %ecx
testl %edx, %edx
cmovlel %ecx, %edx
shlq $0x5, %rdx
shlq $0x5, %r8
addq %r8, %rdi
addq $0x18, %rdi
xorl %r8d, %r8d
cmpq %rcx, %rdx
je 0x5291
cmpl %ebp, -0x10(%rdi,%rcx)
jne 0x528b
movq (%rdi,%rcx), %r9
movq %r9, %r10
xorq %rsi, %r10
shlq $0x3, %r10
testq %r10, %r10
je 0x528b
orq %r15, %r9
movq %r9, (%rdi,%rcx)
incl %r8d
addq $0x20, %rcx
jmp 0x5263
cmpl %eax, %r8d
jne 0x5325
addl %eax, 0x14(%rsp)
movl %ebx, %ecx
movq 0x18(%rsp), %rsi
incq %rbx
jmp 0x5132
movq 0x28(%rsp), %rbp
movq 0x20(%rsp), %rcx
incq %rcx
jmp 0x508b
movq %r14, %rdi
callq 0x2040
movl 0x14(%rsp), %ebp
testl %ebp, %ebp
je 0x52ef
cmpl $0x2, 0x28f1a(%rip)     # 0x2e1f0
jge 0x5302
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x4dee
movq %rbx, %rdi
callq 0x483a
jmp 0x52f1
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x28cef(%rip), %rax     # 0x2dff8
movq (%rax), %rdi
leaq 0x1e0ea(%rip), %rsi     # 0x233fd
leaq 0x1e0a1(%rip), %rdx     # 0x233bb
movl %ebp, %ecx
xorl %eax, %eax
callq 0x2210
jmp 0x52d8
leaq 0x1e09d(%rip), %rdi     # 0x233c9
leaq 0x1debd(%rip), %rsi     # 0x231f0
leaq 0x1e0a3(%rip), %rcx     # 0x233dd
movl $0x194, %edx            # imm = 0x194
callq 0x2160