// File: /workspace/github_c_makefile_star2_O1/lh3[P]minigraph/gfa-base.c
// Function: gfa_fix_semi_arc
uint32_t gfa_fix_semi_arc(gfa_t *g)
{
	uint32_t n_err = 0, v, n_vtx = gfa_n_vtx(g);
	int i, j;
	for (v = 0; v < n_vtx; ++v) {
		int nv = gfa_arc_n(g, v);
		gfa_arc_t *av = gfa_arc_a(g, v);
		for (i = 0; i < nv; ++i) {
			if (!av[i].del && (av[i].ow == INT32_MAX || av[i].ov == INT32_MAX)) { // overlap length is missing
				uint32_t w = av[i].w^1;
				int is_multi = 0, c, jv = -1, nw = gfa_arc_n(g, w);
				gfa_arc_t *aw = gfa_arc_a(g, w);
				for (j = 0, c = 0; j < nw; ++j)
					if (!aw[j].del && aw[j].w == (v^1)) ++c, jv = j;
				if (c == 1) {
					if (av[i].ov != INT32_MAX && aw[jv].ow != INT32_MAX && av[i].ov != aw[jv].ow) is_multi = 1;
					if (av[i].ow != INT32_MAX && aw[jv].ov != INT32_MAX && av[i].ow != aw[jv].ov) is_multi = 1;
				}
				if (c == 1 && !is_multi) {
					if (aw[jv].ov != INT32_MAX) av[i].ow = aw[jv].ov;
					if (aw[jv].ow != INT32_MAX) av[i].ov = aw[jv].ow;
				} else {
					if (gfa_verbose >= 2)
						fprintf(stderr, "[W] can't infer overlap length for %s%c -> %s%c\n",
								g->seg[v>>1].name, "+-"[v&1], g->seg[w>>1].name, "+-"[(w^1)&1]);
					++n_err;
					av[i].del = 1;
				}
			}
		}
	}
	return n_err;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl 0x4(%rdi), %eax
addl %eax, %eax
je 0x5996
movq %rdi, %r14
movabsq $0x4000000000000000, %r13 # imm = 0x4000000000000000
leaq 0x10(%rdi), %rcx
movq %rcx, 0x10(%rsp)
movl %eax, %eax
movq %rax, 0x28(%rsp)
xorl %r15d, %r15d
movl $0x0, 0x4(%rsp)
movq %rdi, 0x30(%rsp)
movq 0x58(%r14), %rax
movq (%rax,%r15,8), %r12
testl %r12d, %r12d
jle 0x5986
movq %r12, %r10
shrq $0x1b, %r10
andq $-0x20, %r10
addq 0x48(%r14), %r10
movl %r15d, %eax
shrl %eax
movq %rax, 0x20(%rsp)
movl %r15d, %ecx
andl $0x1, %ecx
leaq 0x22b85(%rip), %rax     # 0x2836f
addq %rax, %rcx
movq %rcx, 0x18(%rsp)
andl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
xorl %ebp, %ebp
movq %r12, 0x38(%rsp)
movq %r10, 0x8(%rsp)
movq %rbp, %rbx
shlq $0x5, %rbx
testq %r13, 0x18(%r10,%rbx)
jne 0x5958
addq %r10, %rbx
movl 0x14(%rbx), %ecx
cmpl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
je 0x5832
cmpl $0x7fffffff, 0x10(%rbx) # imm = 0x7FFFFFFF
jne 0x5958
movl 0x8(%rbx), %esi
movq %rsi, 0x40(%rsp)
xorq $0x1, %rsi
movq 0x48(%r14), %rax
movq 0x58(%r14), %rdi
movq (%rdi,%rsi,8), %r9
movq %r9, %r8
shrq $0x20, %r8
shlq $0x5, %r8
xorl %esi, %esi
testl %r9d, %r9d
jle 0x58b1
andl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
leaq (%rax,%r8), %r10
addq $0x18, %r10
xorl %r12d, %r12d
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
xorl %edi, %edi
testq %r13, (%r10)
jne 0x5891
movl -0x10(%r10), %r14d
xorl %r15d, %r14d
xorl %edx, %edx
cmpl $0x1, %r14d
sete %dl
cmovel %r12d, %r11d
addl %edx, %edi
incq %r12
addq $0x20, %r10
cmpq %r12, %r9
jne 0x5876
movslq %r11d, %r9
movq 0x30(%rsp), %r14
movq 0x38(%rsp), %r12
movq 0x8(%rsp), %r10
jmp 0x58ba
movq $-0x1, %r9
xorl %edi, %edi
addq %r8, %rax
cmpl $0x1, %edi
jne 0x5918
movl 0x10(%rbx), %r8d
xorl %esi, %esi
cmpl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
je 0x58f2
movq %r9, %rdx
shlq $0x5, %rdx
movl 0x14(%rax,%rdx), %edx
cmpl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
setne %sil
cmpl %edx, %r8d
setne %dl
andb %sil, %dl
movzbl %dl, %esi
cmpl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
je 0x5918
movq %r9, %rdx
shlq $0x5, %rdx
movl 0x10(%rax,%rdx), %edx
cmpl %edx, %ecx
movl $0x1, %ecx
cmovel %esi, %ecx
cmpl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
cmovnel %ecx, %esi
cmpl $0x1, %edi
jne 0x5947
testl %esi, %esi
jne 0x5947
shlq $0x5, %r9
movl 0x10(%rax,%r9), %ecx
cmpl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
je 0x5935
movl %ecx, 0x14(%rbx)
addq %r9, %rax
movl 0x14(%rax), %eax
cmpl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
je 0x5958
movl %eax, 0x10(%rbx)
jmp 0x5958
cmpl $0x2, 0x2c8a2(%rip)     # 0x321f0
jge 0x5966
incl 0x4(%rsp)
orq %r13, 0x18(%rbx)
incq %rbp
cmpq %r12, %rbp
jne 0x5805
jmp 0x5986
movq 0x10(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq 0x40(%rsp), %rcx
callq 0x252c
movq 0x8(%rsp), %r10
jmp 0x5950
incq %r15
cmpq 0x28(%rsp), %r15
jne 0x57b3
jmp 0x599e
movl $0x0, 0x4(%rsp)
movl 0x4(%rsp), %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq