// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: integer_hit2arc(ul2ul_t const*, long, long, long, long, unsigned long, unsigned long, long, asg_arc_t*)
static inline int integer_hit2arc(const ul2ul_t *z, int64_t ql, int64_t tl, int64_t qocc, int64_t tocc, uint64_t qid, uint64_t tid, 
int64_t min_ovlp, asg_arc_t *p)
{
    int64_t tl5, tl3, ext5, ext3, qs = z->qs, rf;
    uint64_t u, v, l, rr; // u: query end; v: target end; l: length from u to v

    ///if query and target are in different strand
    if (z->is_rev) tl5 = tl - z->te, tl3 = z->ts; // tl5: 5'-end overhang (on the query strand); tl3: similar
    else tl5 = z->ts, tl3 = tl - z->te;

    ///ext5 and ext3 is the hang on left side and right side, respectively
    ext5 = qs < tl5? qs : tl5;
    ext3 = (((ql - ((int64_t)z->qe)) < tl3)? (ql - ((int64_t)z->qe)) : tl3);

    if(ext5 > 0 || ext3 > 0) return MA_HT_INT;///overhang
    if (qs <= tl5 && (ql - (int64_t)z->qe) <= tl3) { // query contained in target
        return MA_HT_QCONT; 
    } else if (qs >= tl5 && (ql - (int64_t)z->qe) >= tl3) { // target contained in query
        return MA_HT_TCONT;  
    } else if (qs > tl5) { ///u = 0 means query-to-target overlap, l is the length of node in string graph (not the overlap length)
        u = 0, v = !!(z->is_rev), l = qs - tl5; 
    } else { ///u = 1 means target-to-query overlaps, l is the length of node in string graph (not the overlap length)
        u = 1, v = !(z->is_rev), l = (ql - z->qe) - tl3; 
    }
    if ((int64_t)z->qe - qs + ext5 + ext3 < min_ovlp || (int64_t)z->te - (int64_t)z->ts + ext5 + ext3 < min_ovlp) {
        return MA_HT_SHORT_OVLP; // short overlap
    }
    rf = integer_hit2arc_idx_contain(z, qocc, tocc, &rr);
    if(rf != MA_HT_DOUBLE) return rf;
    if(rr != (uint64_t)-1 && rr != u) {
        // fprintf(stderr, "[M::%s::] z->is_rev::%u, z->qs::%u, z->qe::%u, z->ts::%u, z->te::%u, z->qs_k::%u, z->qe_k::%u, z->ts_k::%u, z->te_k::%u, ql::%ld, tl::%ld, qocc::%ld, tocc::%ld\n", __func__, 
        //     z->is_rev, z->qs, z->qe, z->ts, z->te, z->qs_k, z->qe_k, z->ts_k, z->te_k, ql, tl, qocc, tocc);
        return MA_HT_INT;///overhang
    }
    ///u = 0 / 1 means query-to-target / target-to-query overlaps, 
    ///l is the length of node in string graph (not the overlap length between two reads)
    u |= qid<<1, v |= tid<<1;
    /**
    p->ul: |____________31__________|__________1___________|______________32_____________|
                        qn            direction of overlap       length of this node (not overlap length)
                                        (in the view of query)
    p->v : |___________31___________|__________1___________|
                        tn             reverse direction of overlap
                                      (in the view of target)
    p->ol: overlap length
    **/
    if(p) {
        p->ul = (uint64_t)u<<32 | l, p->v = v, p->ol = ql - l, p->del = 0;
        ///l is the length of node in string graph (not the overlap length)

        p->strong = 1; p->el = 1; p->no_l_indel = 1;
    }
    return l;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movl 0x4(%rdi), %ebp
movb 0x24(%rdi), %al
testb $0x3f, %al
je 0x207396
movl 0xc(%rdi), %r15d
movl 0x10(%rdi), %r12d
subq %r12, %rdx
movq %r15, %r11
jmp 0x2073a7
movl 0xc(%rdi), %r15d
movl 0x10(%rdi), %r12d
subq %r12, %rdx
movq %rdx, %r11
movq %r15, %rdx
cmpq %rbp, %rdx
movq %rbp, %r10
cmovlq %rdx, %r10
movl 0x8(%rdi), %ebx
movq %rsi, %r14
subq %rbx, %r14
cmpq %r11, %r14
movq %r11, %r13
cmovlq %r14, %r13
testq %r10, %r10
jg 0x207540
testq %r13, %r13
jg 0x207540
movb %al, -0x13(%rsp)
movq %rsi, -0x10(%rsp)
movq %r9, -0x8(%rsp)
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
cmpq %rdx, %rbp
jg 0x2073f7
cmpq %r11, %r14
jle 0x207545
movl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
cmpq %rdx, %rbp
jl 0x20740a
cmpq %r11, %r14
jge 0x207545
movq 0x40(%rsp), %r14
testb $0x3f, -0x13(%rsp)
sete %r9b
addq %rbx, %r11
movq -0x10(%rsp), %rax
subq %r11, %rax
movq %rbp, %r11
subq %rdx, %r11
setg -0x11(%rsp)
cmovleq %rax, %r11
addq %r10, %r13
movq %r13, %rsi
subq %rbp, %rsi
addq %rbx, %rsi
movl $0xfffffffc, %eax       # imm = 0xFFFFFFFC
cmpq %r14, %rsi
jl 0x207545
movb %r9b, -0x12(%rsp)
movl %r12d, %esi
movl %r15d, %r10d
addq %rsi, %r13
subq %r10, %r13
cmpq %r14, %r13
jl 0x207545
movl 0x14(%rdi), %r15d
movl 0x18(%rdi), %eax
subq %rax, %rcx
testb $0x3f, -0x13(%rsp)
je 0x207486
movl 0x1c(%rdi), %r14d
movl 0x20(%rdi), %eax
subq %rax, %r8
movq %r8, %rax
jmp 0x207492
movl 0x1c(%rdi), %eax
movl 0x20(%rdi), %esi
movq %r8, %r14
subq %rsi, %r14
cmpq %r15, %rax
movq %r15, %rsi
movq %rax, %r8
cmovlq %rax, %rsi
cmpq %r14, %rcx
movq %r14, %rax
cmovlq %rcx, %rax
testq %rsi, %rsi
jg 0x207540
testq %rax, %rax
jg 0x207540
cmpq %r15, %r8
jle 0x2074ca
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
cmpq %r14, %rcx
jl 0x207545
cmpq %r15, %r8
jge 0x2074d9
movl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
cmpq %r14, %rcx
jg 0x207545
cmpq %r15, %r8
jne 0x207550
cmpq %r14, %rcx
jne 0x207550
movq 0x48(%rsp), %rax
testq %rax, %rax
je 0x20753b
movb -0x12(%rsp), %bl
xorb -0x11(%rsp), %bl
movzbl %bl, %ecx
movq 0x38(%rsp), %rsi
xorl %edi, %edi
cmpq %rdx, %rbp
setle %dil
leal (%rcx,%rsi,2), %edx
movq -0x8(%rsp), %r9
shlq $0x21, %r9
shlq $0x20, %rdi
orq %r9, %rdi
orq %r11, %rdi
movq %rdi, (%rax)
movl %edx, 0x8(%rax)
movq -0x10(%rsp), %rcx
subl %r11d, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl %ecx, 0xc(%rax)
movb $0x1, 0x12(%rax)
orb $-0x40, 0x11(%rax)
movl %r11d, %eax
jmp 0x207545
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpq %r14, %rcx
setg %dil
setge %r10b
cmpq %rdx, %rbp
setg %al
cmpq %r15, %r8
setl %sil
setne %cl
orb %dil, %cl
movl %ecx, %edi
notb %dil
testb %r10b, %dil
jne 0x2074e3
xorb %sil, %al
xorb %cl, %al
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
je 0x207545
jmp 0x2074e3