// File: /workspace/github_c_makefile_star2_O3/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
movl 0x4(%rdi), %ebx
addl %ebx, %ebx
je 0x60ba
movq %rdi, %r14
movq 0x58(%rdi), %rax
movl %ebx, %r13d
pcmpeqd %xmm0, %xmm0
xorl %ecx, %ecx
movdqu (%rax,%rcx,8), %xmm1
pshufd $0xe8, %xmm1, %xmm1     # xmm1 = xmm1[0,2,2,3]
movdqa %xmm0, %xmm2
pcmpgtd %xmm1, %xmm0
pand %xmm0, %xmm2
pandn %xmm1, %xmm0
por %xmm2, %xmm0
addq $0x2, %rcx
cmpq %rcx, %r13
jne 0x5dda
pshufd $0x55, %xmm0, %xmm1     # xmm1 = xmm0[1,1,1,1]
movdqa %xmm0, %xmm2
pcmpgtd %xmm1, %xmm2
pand %xmm2, %xmm0
pandn %xmm1, %xmm2
por %xmm0, %xmm2
movd %xmm2, %eax
cmpl $0x1, %eax
je 0x60d1
movslq %eax, %rdi
shlq $0x3, %rdi
callq 0x2280
movq %rax, %r15
testl %ebx, %ebx
je 0x60c9
movabsq $0x4000000000000000, %r12 # imm = 0x4000000000000000
leaq 0x10(%r14), %rax
movq %rax, 0x18(%rsp)
xorl %ebp, %ebp
movq $0x0, (%rsp)
movq %r14, 0x10(%rsp)
movq %r13, 0x28(%rsp)
movq 0x58(%r14), %rax
movq (%rax,%rbp,8), %r8
testl %r8d, %r8d
movq %rbp, 0x30(%rsp)
jle 0x6077
movq 0x48(%r14), %rcx
movq %r8, %rdx
shrq $0x20, %rdx
shlq $0x5, %rdx
leaq (%rcx,%rdx), %r14
movl %r8d, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
addq %rdx, %rcx
addq $0x18, %rcx
xorl %edx, %edx
xorl %ebx, %ebx
testq %r12, (%rcx)
jne 0x5eb9
movl -0x10(%rcx), %esi
shlq $0x20, %rsi
addq %rdx, %rsi
movslq %ebx, %rdi
incl %ebx
movq %rsi, (%r15,%rdi,8)
incq %rdx
addq $0x20, %rcx
cmpq %rdx, %rax
jne 0x5ea1
testl %ebx, %ebx
jle 0x6077
movl %ebx, %eax
leaq (%r15,%rax,8), %rsi
movq %r15, %rdi
movq %r8, %r13
callq 0x47e4
movq %r13, %r10
movl %ebp, %r13d
xorl $0x1, %r13d
shrl %ebp
movq %rbp, 0x20(%rsp)
andl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
incl %ebx
xorl %ecx, %ecx
movl $0x1, %ebp
movq %r10, 0x8(%rsp)
cmpq %r10, %rbp
je 0x5f1e
movslq %ecx, %rax
movq (%r15,%rax,8), %rax
xorq (%r15,%rbp,8), %rax
shrq $0x20, %rax
je 0x606b
movl %ebp, %eax
subl %ecx, %eax
cmpl $0x2, %eax
jl 0x6069
movslq %ecx, %rdx
movq (%r15,%rdx,8), %rdx
incl %ecx
movslq %ecx, %rcx
cmpq %rcx, %rbp
jle 0x5f87
movslq %edx, %rsi
shlq $0x5, %rsi
movl 0xc(%r14,%rsi), %r8d
leaq 0x1(%rcx), %rsi
movq -0x8(%r15,%rsi,8), %rdi
movslq %edi, %r9
shlq $0x5, %r9
movl 0xc(%r14,%r9), %r9d
testl %r9d, %r9d
setns %r10b
cmpl %r8d, %r9d
setl %r11b
testb %r11b, %r10b
jne 0x5f75
movl %edx, %edi
movl %r8d, %r9d
movl %esi, %r10d
incq %rsi
movl %r9d, %r8d
movl %edi, %edx
cmpq %rbp, %r10
jne 0x5f4c
jmp 0x5f89
movl %edx, %edi
movslq %edi, %rsi
shlq $0x5, %rsi
movl 0x8(%r14,%rsi), %edx
cmpl %r13d, %edx
jne 0x5fc5
cmpl $0x2, 0x2c24f(%rip)     # 0x321f0
movq 0x8(%rsp), %r10
jl 0x6069
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x252c
movq 0x8(%rsp), %r10
jmp 0x6069
addq %r14, %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, %rbp
movq 0x8(%rsp), %r10
jle 0x6007
incq %rcx
movslq -0x8(%r15,%rcx,8), %r8
shlq $0x5, %r8
orq %r12, 0x18(%r14,%r8)
movl %ecx, %r8d
incq %rcx
cmpq %rbp, %r8
jne 0x5fee
testl %edx, %edx
jle 0x6050
movq %rdx, %rcx
shrq $0x20, %rcx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
shlq $0x5, %rcx
addq %rcx, %rdi
addq $0x18, %rdi
xorl %ecx, %ecx
cmpl %r13d, -0x10(%rdi)
jne 0x6045
movq (%rdi), %r8
movq %r8, %r9
xorq %rsi, %r9
shlq $0x3, %r9
testq %r9, %r9
je 0x6045
orq %r12, %r8
movq %r8, (%rdi)
incl %ecx
addq $0x20, %rdi
decq %rdx
jne 0x6025
jmp 0x6052
xorl %ecx, %ecx
leal -0x1(%rax), %edx
cmpl %edx, %ecx
jne 0x6107
movq (%rsp), %rcx
addl %eax, %ecx
decl %ecx
movq %rcx, (%rsp)
movl %ebp, %ecx
incq %rbp
cmpq %rbx, %rbp
jne 0x5f04
movq 0x30(%rsp), %rbp
incq %rbp
cmpq 0x28(%rsp), %rbp
movq 0x10(%rsp), %r14
jne 0x5e65
movq %r15, %rdi
callq 0x2040
movq (%rsp), %rbx
testl %ebx, %ebx
je 0x60d1
cmpl $0x2, 0x2c14a(%rip)     # 0x321f0
jge 0x60e4
movq %r14, %rdi
callq 0x5afe
movq %r14, %rdi
callq 0x54fe
jmp 0x60d3
movq $-0x8, %rdi
callq 0x2280
movq %rax, %r15
movq %r15, %rdi
callq 0x2040
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x2bf0d(%rip), %rax     # 0x31ff8
movq (%rax), %rdi
leaq 0x22308(%rip), %rsi     # 0x283fd
leaq 0x222bf(%rip), %rdx     # 0x283bb
movl %ebx, %ecx
xorl %eax, %eax
callq 0x2210
jmp 0x60a8
leaq 0x222bb(%rip), %rdi     # 0x283c9
leaq 0x220db(%rip), %rsi     # 0x281f0
leaq 0x222c1(%rip), %rcx     # 0x283dd
movl $0x194, %edx            # imm = 0x194
callq 0x2160