// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: gen_ext_tip(unsigned int, asg_t*, ug_opt_t*, unsigned char*, unsigned int, unsigned long*, unsigned long*)
int32_t gen_ext_tip(uint32_t v, asg_t *sg, ug_opt_t *uopt, uint8_t *ff, uint32_t min_ovlp, uint64_t *res, uint64_t *path_len)
{
    uint32_t k, qn, tn, cc, ccu; int32_t r; asg_arc_t p, pmax;
    ma_hit_t_alloc *s = &(uopt->sources[v>>1]); memset(&pmax, 0, sizeof(pmax)); pmax.ol = 0;
    for (k = 0; k < s->length; k++) {
        qn = Get_qn(s->buffer[k]); tn = Get_tn(s->buffer[k]);
        r = ma_hit2arc(&(s->buffer[k]), sg->seq[qn].len, sg->seq[tn].len, uopt->max_hang, asm_opt.max_hang_rate, uopt->min_ovlp, &p);
        if(r < 0) continue;
        if((p.ul>>32) != v) continue;
        if(p.ol < min_ovlp) continue;
        if(p.ol > pmax.ol) pmax = p;
    }
    if(pmax.ol == 0) return 0;

    tn = pmax.v>>1;
    if((!(sg->seq[tn].del)) || (ff[tn])) return -1;///not a tip
    get_R_to_U(uopt->ruIndex, tn, &cc, &ccu);
    if(ccu == 1) return -1;
    if((cc != (uint32_t)-1) && 
                    ((!(sg->seq[cc].del)) || (ff[cc]))) {
        return -1;///contained in an existing read 
    }

    if((*path_len) >= sg->seq[v>>1].len) (*path_len) -= sg->seq[v>>1].len;
    else (*path_len) = 0;
    (*path_len) += (uint32_t)(pmax.ul) + sg->seq[pmax.v>>1].len;
    
    uint32_t v0 = v; (*res) = pmax.v;
    v = (pmax.v^1); s = &(uopt->sources[v>>1]); pmax.ol = 0;
    for (k = 0; k < s->length; k++) {
        qn = Get_qn(s->buffer[k]); tn = Get_tn(s->buffer[k]);
        r = ma_hit2arc(&(s->buffer[k]), sg->seq[qn].len, sg->seq[tn].len, uopt->max_hang, asm_opt.max_hang_rate, uopt->min_ovlp, &p);
        if(r < 0) continue;
        if((p.ul>>32) != v) continue;
        if(p.ol < min_ovlp) continue;
        if(p.ol > pmax.ol) pmax = p;
    }
    if((pmax.v^1) == v0) {
        ff[(*res)>>1] = 1; return 1;
    }
    (*res) = (uint64_t)-1; return -1;///not the longest overlap
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %r9, 0x70(%rsp)
movl %r8d, 0x34(%rsp)
movq 0x8(%rdx), %rax
movl %edi, %r9d
shrl %r9d
leaq (%r9,%r9,2), %r8
movl 0xc(%rax,%r8,8), %r10d
testq %r10, %r10
je 0x1fba12
movq %r9, 0x78(%rsp)
movq %rcx, 0x18(%rsp)
leaq (%rax,%r8,8), %rax
movq (%rax), %rax
movq %rsi, 0x28(%rsp)
movq 0x20(%rsi), %rsi
movl 0x40(%rdx), %ecx
movl %ecx, 0x24(%rsp)
movq %rdx, 0x68(%rsp)
movl 0x44(%rdx), %ecx
movl %ecx, 0x48(%rsp)
leaq 0x9a269(%rip), %rcx     # 0x295758
movss 0x158(%rcx), %xmm0
movl %edi, 0x60(%rsp)
movl %edi, %ecx
movq %rcx, 0x40(%rsp)
shlq $0x3, %r10
leaq (%r10,%r10,4), %rcx
movq %rcx, 0x58(%rsp)
xorl %r9d, %r9d
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
movl $0x0, 0x20(%rsp)
movl $0x0, 0xc(%rsp)
movq $0x0, 0x38(%rsp)
movq %rsi, 0x10(%rsp)
movl 0xc(%rax,%r9), %ecx
movq %rcx, 0x50(%rsp)
movl (%rsi,%rcx,8), %edi
andl %r8d, %edi
movq 0x18(%rax,%r9), %r14
testl %r14d, %r14d
js 0x1fb565
movl 0x10(%rax,%r9), %r10d
movl 0x14(%rax,%r9), %r15d
subl %r15d, %edi
movl %edi, %r11d
movl %r10d, %edi
jmp 0x1fb575
movl 0x10(%rax,%r9), %r10d
movl 0x14(%rax,%r9), %r15d
subl %r15d, %edi
movl %r10d, %r11d
movl 0x24(%rsp), %edx
movq (%rax,%r9), %rbp
movq %rbp, %rcx
shrq $0x20, %rcx
movl (%rsi,%rcx,8), %ecx
movl %ecx, %r12d
andl %r8d, %r12d
cmpl %ebp, %edi
movl %ebp, %ebx
cmovll %edi, %ebx
movl 0x8(%rax,%r9), %esi
movl %r12d, %r13d
subl %esi, %r13d
cmpl %r11d, %r13d
movl %r11d, %r8d
cmovll %r13d, %r8d
cmpl %edx, %ebx
jg 0x1fb5f6
cmpl %edx, %r8d
jg 0x1fb5f6
movl %esi, %edx
subl %ebp, %edx
xorps %xmm1, %xmm1
cvtsi2ss %rdx, %xmm1
addl %ebx, %edx
addl %r8d, %edx
xorps %xmm2, %xmm2
cvtsi2ss %rdx, %xmm2
mulss %xmm0, %xmm2
ucomiss %xmm1, %xmm2
ja 0x1fb5f6
subl %r10d, %r15d
xorps %xmm1, %xmm1
cvtsi2ss %r15, %xmm1
addl %ebx, %r8d
addl %r15d, %r8d
xorps %xmm2, %xmm2
cvtsi2ss %r8, %xmm2
mulss %xmm0, %xmm2
ucomiss %xmm1, %xmm2
jbe 0x1fb615
addq $0x28, %r9
cmpq %r9, 0x58(%rsp)
movq 0x10(%rsp), %rsi
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
jne 0x1fb536
jmp 0x1fb6e3
cmpl %r11d, %r13d
setl %r10b
setg %r15b
cmpl %edi, %ebp
setg %r13b
setl %bl
orb %r15b, %r13b
cmpb $0x1, %r13b
jne 0x1fb5f6
orb %r10b, %bl
je 0x1fb5f6
movl 0x48(%rsp), %r10d
cmpl %r10d, %edx
jl 0x1fb5f6
cmpl %r10d, %r8d
jl 0x1fb5f6
testl %r14d, %r14d
setns %r8b
addl %esi, %r11d
subl %r11d, %r12d
xorl %r10d, %r10d
movl %ebp, %esi
subl %edi, %esi
setle %r10b
setg %dl
cmovlel %r12d, %esi
shrq $0x1f, %rbp
andl $-0x2, %ebp
orq %r10, %rbp
testl %esi, %esi
setns %dil
cmpq 0x40(%rsp), %rbp
sete %r10b
andb %dil, %r10b
cmpb $0x1, %r10b
jne 0x1fb5f6
subl %esi, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl 0x34(%rsp), %ecx
setae %dil
movl 0x20(%rsp), %r10d
andl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
cmpl %r10d, %ecx
seta %r10b
andb %dil, %r10b
cmpb $0x1, %r10b
jne 0x1fb5f6
xorb %dl, %r8b
movzbl %r8b, %edx
movq 0x50(%rsp), %rdi
leal (%rdx,%rdi,2), %edx
movl %edx, 0xc(%rsp)
shlq $0x20, %rbp
orq %rbp, %rsi
movq %rsi, 0x38(%rsp)
movl %ecx, 0x20(%rsp)
jmp 0x1fb5f6
testl $0x7fffffff, 0x20(%rsp) # imm = 0x7FFFFFFF
je 0x1fba12
movl 0xc(%rsp), %eax
movl %eax, %ebx
shrl %ebx
movq 0x28(%rsp), %rax
movq 0x20(%rax), %rax
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
cmpl $0x0, (%rax,%rbx,8)
jns 0x1fba15
movq 0x18(%rsp), %rax
cmpb $0x0, (%rax,%rbx)
jne 0x1fba15
movq 0x68(%rsp), %rax
movq 0x30(%rax), %rdi
leaq 0x64(%rsp), %rdx
leaq 0x84(%rsp), %r14
movl %ebx, %esi
movq %r14, %rcx
callq 0xa3c62
cmpl $0x1, (%r14)
je 0x1fba15
movl 0x64(%rsp), %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq 0x28(%rsp), %rdx
movq 0x20(%rdx), %r10
cmpq %rcx, %rax
movq 0x18(%rsp), %rdi
movl 0xc(%rsp), %r9d
je 0x1fb781
cmpl $0x0, (%r10,%rax,8)
jns 0x1fba15
cmpb $0x0, (%rdi,%rax)
jne 0x1fba15
movq 0xc0(%rsp), %rdx
movq (%rdx), %rax
movq 0x78(%rsp), %rcx
movl (%r10,%rcx,8), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
subq %rcx, %rax
movl $0x0, %ecx
cmovaeq %rax, %rcx
movq %rcx, (%rdx)
movl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
movl (%r10,%rbx,8), %eax
andl %r15d, %eax
addl 0x38(%rsp), %eax
addq %rcx, %rax
movq %rax, (%rdx)
movl %r9d, %ecx
movq 0x70(%rsp), %rax
movq %rcx, 0x40(%rsp)
movq %rcx, (%rax)
movq 0x68(%rsp), %rsi
movq 0x8(%rsi), %rcx
leaq (%rbx,%rbx,2), %rdx
movl 0xc(%rcx,%rdx,8), %eax
testq %rax, %rax
je 0x1fba2a
movq $0x0, 0x28(%rsp)
leaq (%rcx,%rdx,8), %rcx
movl %r9d, %edx
xorl $0x1, %edx
movq %rdx, 0x38(%rsp)
movq (%rcx), %r8
movl 0x40(%rsi), %ecx
movl %ecx, 0x24(%rsp)
movl 0x44(%rsi), %r11d
leaq 0x99f40(%rip), %rcx     # 0x295758
movss 0x158(%rcx), %xmm0
shlq $0x3, %rax
leaq (%rax,%rax,4), %rax
movq %rax, 0x58(%rsp)
xorl %ebx, %ebx
movq %r10, 0x10(%rsp)
movl %r11d, 0x20(%rsp)
movl 0xc(%r8,%rbx), %eax
movq %rax, 0x50(%rsp)
movl (%r10,%rax,8), %ebp
andl %r15d, %ebp
movq 0x18(%r8,%rbx), %rax
movq %rax, 0x48(%rsp)
testl %eax, %eax
movl %r9d, 0xc(%rsp)
js 0x1fb870
movl 0x10(%r8,%rbx), %r11d
movl 0x14(%r8,%rbx), %esi
subl %esi, %ebp
movl %ebp, %edi
movl %r11d, %ebp
jmp 0x1fb87f
movl 0x10(%r8,%rbx), %r11d
movl 0x14(%r8,%rbx), %esi
subl %esi, %ebp
movl %r11d, %edi
movq (%r8,%rbx), %rcx
movq %rcx, %rax
shrq $0x20, %rax
movl (%r10,%rax,8), %r14d
movl %r14d, %r10d
andl %r15d, %r10d
cmpl %ecx, %ebp
movl %ecx, %r15d
cmovll %ebp, %r15d
movl 0x8(%r8,%rbx), %edx
movl %r10d, %r12d
subl %edx, %r12d
cmpl %edi, %r12d
movl %edi, %r9d
cmovll %r12d, %r9d
movl 0x24(%rsp), %eax
cmpl %eax, %r15d
jg 0x1fb905
cmpl %eax, %r9d
jg 0x1fb905
movl %edx, %eax
subl %ecx, %eax
xorps %xmm1, %xmm1
cvtsi2ss %rax, %xmm1
addl %r15d, %eax
addl %r9d, %eax
xorps %xmm2, %xmm2
cvtsi2ss %rax, %xmm2
mulss %xmm0, %xmm2
ucomiss %xmm1, %xmm2
ja 0x1fb905
subl %r11d, %esi
xorps %xmm1, %xmm1
cvtsi2ss %rsi, %xmm1
addl %r15d, %r9d
addl %esi, %r9d
xorps %xmm2, %xmm2
cvtsi2ss %r9, %xmm2
mulss %xmm0, %xmm2
ucomiss %xmm1, %xmm2
jbe 0x1fb92e
movq 0x18(%rsp), %rdi
movl 0xc(%rsp), %r9d
movq 0x10(%rsp), %r10
movl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
addq $0x28, %rbx
cmpq %rbx, 0x58(%rsp)
jne 0x1fb839
jmp 0x1fba2a
cmpl %edi, %r12d
setl %sil
setg %r15b
cmpl %ebp, %ecx
setg %r12b
setl %r11b
orb %r15b, %r12b
cmpb $0x1, %r12b
jne 0x1fb905
orb %sil, %r11b
movl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
je 0x1fb9fe
movl 0x20(%rsp), %r11d
cmpl %r11d, %eax
jl 0x1fb9fe
cmpl %r11d, %r9d
jl 0x1fb9fe
addl %edx, %edi
subl %edi, %r10d
xorl %edx, %edx
movl %ecx, %eax
subl %ebp, %eax
setle %sil
cmovlel %r10d, %eax
testl %eax, %eax
movq 0x18(%rsp), %rdi
movl 0xc(%rsp), %r9d
js 0x1fba08
movb %sil, %dl
movq %rcx, %rsi
shrq $0x1f, %rsi
andl $-0x2, %esi
orq %rdx, %rsi
cmpl 0x38(%rsp), %esi
movq 0x10(%rsp), %r10
jne 0x1fb91a
cmpl %ebp, %ecx
setg %cl
cmpl $0x0, 0x48(%rsp)
setns %dl
subl %eax, %r14d
andl %r15d, %r14d
xorb %cl, %dl
movzbl %dl, %eax
movq 0x50(%rsp), %rcx
leal (%rax,%rcx,2), %eax
cmpl 0x34(%rsp), %r14d
setae %cl
movq 0x28(%rsp), %rsi
movl %esi, %edx
andl %r15d, %edx
cmpl %edx, %r14d
seta %dl
testb %dl, %cl
cmovnel %eax, %r9d
cmovnel %r14d, %esi
movq %rsi, 0x28(%rsp)
jmp 0x1fb91a
movq 0x18(%rsp), %rdi
movl 0xc(%rsp), %r9d
movq 0x10(%rsp), %r10
jmp 0x1fb91a
xorl %r13d, %r13d
movl %r13d, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl 0x60(%rsp), %r9d
cmpl $0x1, %r9d
jne 0x1fba48
movq 0x40(%rsp), %rax
shrl %eax
movb $0x1, (%rdi,%rax)
movl $0x1, %r13d
jmp 0x1fba15
movq 0x70(%rsp), %rax
movq $-0x1, (%rax)
jmp 0x1fba15