// File: /workspace/github_cpp_makefile_star2_O1/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), %ebx
movb 0x24(%rdi), %r12b
testb $0x3f, %r12b
je 0x1fbcc7
movl 0xc(%rdi), %r11d
movl 0x10(%rdi), %eax
subq %rax, %rdx
jmp 0x1fbcd7
movl 0xc(%rdi), %eax
movl 0x10(%rdi), %r10d
subq %r10, %rdx
movq %rdx, %r11
movq %rax, %rdx
cmpq %rbx, %rdx
movq %rbx, %r10
cmovlq %rdx, %r10
movl 0x8(%rdi), %ebp
movq %rsi, %r14
subq %rbp, %r14
cmpq %r11, %r14
movq %r11, %r13
cmovlq %r14, %r13
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testq %r10, %r10
jg 0x1fbed6
testq %r13, %r13
jg 0x1fbed6
cmpq %rdx, %rbx
jg 0x1fbd1e
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
cmpq %r11, %r14
jle 0x1fbed6
cmpq %rdx, %rbx
jl 0x1fbd31
movl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
cmpq %r11, %r14
jge 0x1fbed6
movq 0x40(%rsp), %r15
testb $0x3f, %r12b
sete -0x2(%rsp)
addq %rbp, %r11
movq %rsi, %rax
subq %r11, %rax
xorl %r14d, %r14d
movq %rbx, %r11
subq %rdx, %r11
setg -0x3(%rsp)
setle -0x1(%rsp)
cmovleq %rax, %r11
addq %r10, %r13
movq %r13, %r10
subq %rbx, %r10
addq %rbp, %r10
movl $0xfffffffc, %eax       # imm = 0xFFFFFFFC
cmpq %r15, %r10
jl 0x1fbed6
movl 0xc(%rdi), %r10d
movl 0x10(%rdi), %ebp
addq %rbp, %r13
subq %r10, %r13
cmpq %r15, %r13
jl 0x1fbed6
movl 0x14(%rdi), %r13d
movl 0x18(%rdi), %eax
subq %rax, %rcx
testb $0x3f, %r12b
je 0x1fbdab
movl 0x1c(%rdi), %r12d
movl 0x20(%rdi), %eax
subq %rax, %r8
jmp 0x1fbdba
movl 0x1c(%rdi), %eax
movl 0x20(%rdi), %edi
subq %rdi, %r8
movq %r8, %r12
movq %rax, %r8
cmpq %r13, %r8
movq %r13, %rbp
cmovlq %r8, %rbp
cmpq %r12, %rcx
movq %r12, %r15
cmovlq %rcx, %r15
xorl %r10d, %r10d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq $-0x1, %rdi
testq %rbp, %rbp
jg 0x1fbe68
testq %r15, %r15
jg 0x1fbe68
cmpq %r13, %r8
jle 0x1fbdff
cmpq %r12, %rcx
jge 0x1fbdff
xorl %r10d, %r10d
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
jmp 0x1fbe68
cmpq %r13, %r8
jge 0x1fbe13
cmpq %r12, %rcx
jle 0x1fbe13
xorl %r10d, %r10d
movl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
jmp 0x1fbe68
cmpq %r13, %r8
setl %al
xorl %edi, %edi
cmpq %r12, %rcx
setge %dil
movq %r8, %r10
xorq %r13, %r10
movq %rcx, %r15
xorq %r12, %r15
xorl %ebp, %ebp
orq %r10, %r15
sete %bpl
orb %bpl, %al
negq %rbp
testb %al, %al
movl $0x1, %r10d
cmovneq %rbp, %r10
negq %rdi
cmpq %r12, %rcx
cmovgq %r10, %rdi
cmpq %r13, %r8
cmovgq %r10, %rdi
testb %al, %al
cmovneq %r10, %rdi
movl $0xfffffc00, %eax       # imm = 0xFFFFFC00
movb $0x1, %r10b
testb %r10b, %r10b
je 0x1fbed6
cmpq $-0x1, %rdi
je 0x1fbe84
movb -0x1(%rsp), %al
movb %al, %r14b
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %r14, %rdi
jne 0x1fbed6
movq 0x48(%rsp), %rax
testq %rax, %rax
je 0x1fbed3
movb -0x2(%rsp), %cl
xorb -0x3(%rsp), %cl
movzbl %cl, %ecx
movq 0x38(%rsp), %rdi
xorl %r8d, %r8d
cmpq %rdx, %rbx
setle %r8b
leal (%rcx,%rdi,2), %ecx
shlq $0x21, %r9
shlq $0x20, %r8
orq %r9, %r8
orq %r11, %r8
movq %r8, (%rax)
movl %ecx, 0x8(%rax)
subl %r11d, %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
movl %esi, 0xc(%rax)
movb $0x1, 0x12(%rax)
orb $-0x40, 0x11(%rax)
movl %r11d, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq