// File: /workspace/github_cpp_makefile_star2_O2/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
movq %r9, -0x8(%rsp)
movq %rsi, %rbx
movl 0x4(%rdi), %r11d
movb 0x24(%rdi), %r15b
testb $0x3f, %r15b
je 0x1bb128
movl 0xc(%rdi), %ebp
movl 0x10(%rdi), %r14d
subq %r14, %rdx
movq %rbp, %rax
jmp 0x1bb138
movl 0xc(%rdi), %ebp
movl 0x10(%rdi), %r14d
subq %r14, %rdx
movq %rdx, %rax
movq %rbp, %rdx
cmpq %r11, %rdx
movq %r11, %r10
cmovlq %rdx, %r10
movl 0x8(%rdi), %r13d
movq %rbx, %rsi
subq %r13, %rsi
cmpq %rax, %rsi
movq %rax, %r12
cmovlq %rsi, %r12
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
testq %r10, %r10
jg 0x1bb2c6
testq %r12, %r12
jg 0x1bb2c6
cmpq %rdx, %r11
jg 0x1bb182
cmpq %rax, %rsi
jg 0x1bb182
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
jmp 0x1bb2c9
cmpq %rdx, %r11
jl 0x1bb196
cmpq %rax, %rsi
jl 0x1bb196
movl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
jmp 0x1bb2c9
testb $0x3f, %r15b
sete -0x11(%rsp)
addq %r13, %rax
movq %rbx, %rsi
subq %rax, %rsi
movq %r11, %rax
subq %rdx, %rax
setg -0x12(%rsp)
cmovleq %rsi, %rax
movq %rax, -0x10(%rsp)
addq %r10, %r12
movq %r12, %rsi
subq %r11, %rsi
addq %r13, %rsi
movq 0x40(%rsp), %r13
movl $0xfffffffc, %eax       # imm = 0xFFFFFFFC
cmpq %r13, %rsi
jl 0x1bb2c9
movl %r14d, %esi
movl %ebp, %r10d
addq %rsi, %r12
subq %r10, %r12
cmpq %r13, %r12
jl 0x1bb2c9
movl 0x14(%rdi), %r14d
movl 0x18(%rdi), %eax
subq %rax, %rcx
testb $0x3f, %r15b
je 0x1bb20c
movl 0x1c(%rdi), %r15d
movl 0x20(%rdi), %eax
subq %rax, %r8
jmp 0x1bb21b
movl 0x1c(%rdi), %eax
movl 0x20(%rdi), %esi
subq %rsi, %r8
movq %r8, %r15
movq %rax, %r8
cmpq %r14, %r8
movq %r14, %rsi
cmovlq %r8, %rsi
cmpq %r15, %rcx
movq %r15, %rax
cmovlq %rcx, %rax
testq %rsi, %rsi
jg 0x1bb2c6
testq %rax, %rax
jg 0x1bb2c6
cmpq %r14, %r8
jle 0x1bb250
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
cmpq %r15, %rcx
jl 0x1bb2c9
cmpq %r14, %r8
jge 0x1bb25f
movl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
cmpq %r15, %rcx
jg 0x1bb2c9
cmpq %r14, %r8
jne 0x1bb2d4
cmpq %r15, %rcx
jne 0x1bb2d4
movq 0x48(%rsp), %rax
testq %rax, %rax
movq -0x10(%rsp), %r8
je 0x1bb2c1
movb -0x11(%rsp), %cl
xorb -0x12(%rsp), %cl
movzbl %cl, %ecx
movq 0x38(%rsp), %rsi
xorl %edi, %edi
cmpq %rdx, %r11
setle %dil
leal (%rcx,%rsi,2), %ecx
movq -0x8(%rsp), %rdx
shlq $0x21, %rdx
shlq $0x20, %rdi
orq %rdx, %rdi
orq %r8, %rdi
movq %rdi, (%rax)
movl %ecx, 0x8(%rax)
subl %r8d, %ebx
andl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
movl %ebx, 0xc(%rax)
movb $0x1, 0x12(%rax)
orb $-0x40, 0x11(%rax)
movl %r8d, %eax
jmp 0x1bb2c9
movl %r9d, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpq %r15, %rcx
setg %dil
setge %r10b
cmpq %rdx, %r11
setg %al
cmpq %r14, %r8
setl %sil
setne %cl
orb %dil, %cl
movl %ecx, %edi
notb %dil
testb %r10b, %dil
jne 0x1bb269
xorb %sil, %al
xorb %cl, %al
movl %r9d, %eax
je 0x1bb2c9
jmp 0x1bb269