// File: /workspace/github_cpp_makefile_star2_O1/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 0x1d30f2
movq 0x8(%r15), %rax
cmpl $0x0, (%rax,%r12,4)
js 0x1d30f2
movq %rbx, %rdi
movl %r13d, %esi
leaq 0x4(%rsp), %rdx
movl $0x1, %ecx
callq 0x1e50d4
cmpl $0x1, %eax
ja 0x1d30f2
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 0x10(%rdi), %rax
cmpq %rax, 0x8(%rdi)
jne 0x1d2f6c
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x10(%rdi)
movq 0x8(%rsp), %rax
movq (%rax), %rdi
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rsi
addq %rcx, %rsi
movl %r8d, %ebx
callq 0x2370
movl %ebx, %r8d
movq 0x8(%rsp), %rdi
movq %rax, (%rdi)
leal (%r15,%r14), %eax
shll $0x1f, %r13d
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %ebp
movl %r13d, %ebx
orl %ebp, %ebx
movq (%rdi), %rcx
movq 0x8(%rdi), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, 0x8(%rdi)
leaq (%rdx,%rdx,8), %rsi
leaq (%rsi,%rsi,2), %rsi
addq %rdx, %rsi
xorl %edx, %edx
movl %edx, (%rcx,%rsi)
movl %r14d, 0x4(%rcx,%rsi)
movl %eax, 0x8(%rcx,%rsi)
movl %r12d, 0xc(%rcx,%rsi)
movq $0x0, 0x10(%rsp)
movl %edx, 0x10(%rcx,%rsi)
movl %r15d, 0x14(%rcx,%rsi)
movl %ebx, 0x18(%rcx,%rsi)
testl %r8d, %r8d
je 0x1d30d9
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 0x1e50d4
cmpl $0x1, %eax
jne 0x1d301e
movl 0x4(%rsp), %r13d
movl %ebx, %ebp
cmpq 0x28(%rsp), %r13
movq 0x18(%rsp), %rbx
movq 0x30(%rsp), %r15
jne 0x1d2ed4
jmp 0x1d30f2
testl %eax, %eax
je 0x1d3106
movq 0x18(%rsp), %rax
movq 0x20(%rax), %rax
movl 0x4(%rsp), %r12d
movl %r12d, %r13d
shrl %r13d
movl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
andl (%rax,%r13,8), %ebx
leal (%rbx,%r14), %edi
shll $0x1f, %r12d
orl %ebp, %r12d
orl $0x40000000, %r12d      # imm = 0x40000000
movq 0x8(%rsp), %rsi
movq 0x10(%rsi), %rax
cmpq %rax, 0x8(%rsi)
jne 0x1d309c
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmovneq %rcx, %rax
movq %rax, 0x10(%rsi)
movq 0x8(%rsp), %rcx
movl %edi, %ebp
movq (%rcx), %rdi
leaq (%rax,%rax,8), %rcx
leaq (%rcx,%rcx,2), %rsi
addq %rax, %rsi
callq 0x2370
movl %ebp, %edi
movq 0x8(%rsp), %rsi
movq %rax, (%rsi)
movq (%rsi), %rax
movq 0x8(%rsi), %rcx
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 %edi, 0x8(%rax,%rdx)
movl %r13d, 0xc(%rax,%rdx)
movl %ecx, 0x10(%rax,%rdx)
movl %ebx, 0x14(%rax,%rdx)
movl %r12d, 0x18(%rax,%rdx)
movl %r15d, %r8d
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 0x6454c(%rip), %rdi     # 0x237659
leaq 0x60877(%rip), %rsi     # 0x23398b
leaq 0x64546(%rip), %rcx     # 0x237661
movl $0x47e9, %edx           # imm = 0x47E9
callq 0x2110