// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/inter.cpp
// Function: extract_contain_tig(asg_t*, unsigned long, R_to_U*, unsigned long, unsigned long, kv_ul_ov_t*)
uint32_t extract_contain_tig(asg_t *g, uint64_t v0, R_to_U *ri, uint64_t offset, uint64_t must_tip, kv_ul_ov_t *res)
{
	uint32_t v = v0, w, kv, kw, is_tip = 0, l = offset;
	ul_ov_t p; memset(&p, 0, sizeof(p));

	while (1) {
		if(!is_contain_r((*ri), (v>>1))) return 0;
		kv = get_arcs(g, v, &w, 1);        
		if(kv > 1) return 0;

		p.qn = 0; p.qs = l; p.qe = l + g->seq[v>>1].len; 
		p.tn = v>>1; p.ts = 0; p.te = g->seq[v>>1].len;
		p.el = 0; p.rev = v&1; kv_push(ul_ov_t, *res, p);

		if(kv == 0) {is_tip = 1; break;}

		l += asg_arc_len(g->arc[w]);
		w = g->arc[w].v;
        ///kv must be 1 here
        kw = get_arcs(g, w^1, NULL, 0);
		assert(kw >= 1);
		if(kw > 1) {
			p.qn = 0; p.qs = l; p.qe = l + g->seq[w>>1].len; 
			p.tn = w>>1; p.ts = 0; p.te = g->seq[w>>1].len;
			p.el = 1; p.rev = w&1; kv_push(ul_ov_t, *res, p);
			break;
		}
        v = w;
        if(v == v0) return 0;
    }
	if((must_tip) && (!is_tip)) return 0;
	return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r9, 0x8(%rsp)
movq %r8, 0x20(%rsp)
movq %rcx, %r14
movq %rdx, %r15
movq %rdi, %rbx
movq $0x0, 0x10(%rsp)
movq %rsi, 0x28(%rsp)
movl %esi, %r13d
xorl %ebp, %ebp
movq %rdi, 0x18(%rsp)
movq %rdx, 0x30(%rsp)
movl %r13d, %r12d
shrl %r12d
cmpq %r12, (%r15)
jbe 0x1dd180
movq 0x8(%r15), %rax
cmpl $0x0, (%rax,%r12,4)
js 0x1dd180
movq %rbx, %rdi
movl %r13d, %esi
leaq 0x4(%rsp), %rdx
movl $0x1, %ecx
callq 0x1efacc
cmpl $0x1, %eax
ja 0x1dd180
movl %eax, %r8d
movq 0x20(%rbx), %rax
movl (%rax,%r12,8), %r15d
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl %eax, %r15d
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
movq 0x8(%rdi), %rcx
cmpq 0x10(%rdi), %rcx
jne 0x1dd004
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rdx
movq %rdx, 0x10(%rdi)
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rsi
addq %rdx, %rsi
movq %rax, %rdi
movl %r8d, %ebx
callq 0x2370
movl %ebx, %r8d
movq 0x8(%rsp), %rdi
movq %rax, (%rdi)
movq 0x8(%rdi), %rcx
leal (%r15,%r14), %edx
shll $0x1f, %r13d
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl %esi, %ebp
movl %r13d, %ebx
orl %ebp, %ebx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x8(%rdi)
leaq (%rcx,%rcx,8), %rsi
leaq (%rsi,%rsi,2), %rsi
addq %rcx, %rsi
xorl %ecx, %ecx
movl %ecx, (%rax,%rsi)
movl %r14d, 0x4(%rax,%rsi)
movl %edx, 0x8(%rax,%rsi)
movl %r12d, 0xc(%rax,%rsi)
movq $0x0, 0x10(%rsp)
movl %ecx, 0x10(%rax,%rsi)
movl %r15d, 0x14(%rax,%rsi)
movl %ebx, 0x18(%rax,%rsi)
testl %r8d, %r8d
je 0x1dd167
movl %r8d, %r15d
movq 0x18(%rsp), %rdi
movq 0x8(%rdi), %rax
movl 0x4(%rsp), %ecx
leaq (%rcx,%rcx,2), %rcx
addl (%rax,%rcx,8), %r14d
movl 0x8(%rax,%rcx,8), %esi
movl %esi, 0x4(%rsp)
xorl $0x1, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1efacc
cmpl $0x1, %eax
jne 0x1dd0af
movl 0x4(%rsp), %r13d
movl %ebx, %ebp
cmpq 0x28(%rsp), %r13
movq 0x18(%rsp), %rbx
movq 0x30(%rsp), %r15
jne 0x1dcf6a
jmp 0x1dd180
testl %eax, %eax
je 0x1dd194
movq 0x18(%rsp), %rax
movq 0x20(%rax), %rax
movl 0x4(%rsp), %r12d
movl %r12d, %edi
shrl %edi
movl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
andl (%rax,%rdi,8), %r13d
leal (%r14,%r13), %ebx
shll $0x1f, %r12d
orl %ebp, %r12d
orl $0x40000000, %r12d      # imm = 0x40000000
movq 0x8(%rsp), %rsi
movq (%rsi), %rax
movq 0x8(%rsi), %rcx
cmpq 0x10(%rsi), %rcx
jne 0x1dd131
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %ecx
cmovneq %rdx, %rcx
movq %rcx, 0x10(%rsi)
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rsi
addq %rcx, %rsi
movq %rdi, %rbp
movq %rax, %rdi
callq 0x2370
movq %rbp, %rdi
movq 0x8(%rsp), %rsi
movq %rax, (%rsi)
movq 0x8(%rsi), %rcx
movl %r15d, %r8d
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%rsi)
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
xorl %ecx, %ecx
movl %ecx, (%rax,%rdx)
movl %r14d, 0x4(%rax,%rdx)
movl %ebx, 0x8(%rax,%rdx)
movl %edi, 0xc(%rax,%rdx)
movl %ecx, 0x10(%rax,%rdx)
movl %r13d, 0x14(%rax,%rdx)
movl %r12d, 0x18(%rax,%rdx)
testl %r8d, %r8d
sete %al
cmpq $0x0, 0x20(%rsp)
sete %cl
orb %al, %cl
movzbl %cl, %eax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6678e(%rip), %rdi     # 0x243929
leaq 0x62ab9(%rip), %rsi     # 0x23fc5b
leaq 0x66788(%rip), %rcx     # 0x243931
movl $0x47e9, %edx           # imm = 0x47E9
callq 0x2110