// File: 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
movq %rsp, %rbp
subq $0xa0, %rsp
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movb 0x24(%rax), %al
andb $0x3f, %al
cmpb $0x0, %al
je 0x338a86
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
movl 0x10(%rcx), %ecx
subq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movq %rax, -0x48(%rbp)
jmp 0x338aa3
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
movl 0x10(%rcx), %ecx
subq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x40(%rbp), %rax
jge 0x338aba
movq -0x60(%rbp), %rax
movq %rax, -0x90(%rbp)
jmp 0x338ac5
movq -0x40(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
movl 0x8(%rcx), %ecx
subq %rcx, %rax
cmpq -0x48(%rbp), %rax
jge 0x338afb
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
movl 0x8(%rcx), %ecx
subq %rcx, %rax
movq %rax, -0x98(%rbp)
jmp 0x338b06
movq -0x48(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x50(%rbp)
jg 0x338b1f
cmpq $0x0, -0x58(%rbp)
jle 0x338b2b
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x338d47
movq -0x60(%rbp), %rax
cmpq -0x40(%rbp), %rax
jg 0x338b55
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
movl 0x8(%rcx), %ecx
subq %rcx, %rax
cmpq -0x48(%rbp), %rax
jg 0x338b55
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x338d47
movq -0x60(%rbp), %rax
cmpq -0x40(%rbp), %rax
jl 0x338b7f
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
movl 0x8(%rcx), %ecx
subq %rcx, %rax
cmpq -0x48(%rbp), %rax
jl 0x338b7f
movl $0xfffffffd, -0x4(%rbp) # imm = 0xFFFFFFFD
jmp 0x338d47
movq -0x60(%rbp), %rax
cmpq -0x40(%rbp), %rax
jle 0x338bba
movq $0x0, -0x70(%rbp)
movq -0x10(%rbp), %rax
movb 0x24(%rax), %al
andb $0x3f, %al
cmpb $0x0, %al
setne %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
movq %rax, -0x78(%rbp)
movq -0x60(%rbp), %rax
subq -0x40(%rbp), %rax
movq %rax, -0x80(%rbp)
jmp 0x338bf1
movq $0x1, -0x70(%rbp)
movq -0x10(%rbp), %rax
movb 0x24(%rax), %al
andb $0x3f, %al
cmpb $0x0, %al
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
movq %rax, -0x78(%rbp)
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
movl 0x8(%rcx), %ecx
subq %rcx, %rax
subq -0x48(%rbp), %rax
movq %rax, -0x80(%rbp)
jmp 0x338bf3
jmp 0x338bf5
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
subq -0x60(%rbp), %rax
addq -0x50(%rbp), %rax
addq -0x58(%rbp), %rax
cmpq 0x18(%rbp), %rax
jl 0x338c2d
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
movq -0x10(%rbp), %rcx
movl 0xc(%rcx), %ecx
subq %rcx, %rax
addq -0x50(%rbp), %rax
addq -0x58(%rbp), %rax
cmpq 0x18(%rbp), %rax
jge 0x338c39
movl $0xfffffffc, -0x4(%rbp) # imm = 0xFFFFFFFC
jmp 0x338d47
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
leaq -0x88(%rbp), %rcx
callq 0x37b840
movq %rax, -0x68(%rbp)
cmpq $-0x400, -0x68(%rbp)    # imm = 0xFC00
je 0x338c6b
movq -0x68(%rbp), %rax
movl %eax, -0x4(%rbp)
jmp 0x338d47
cmpq $-0x1, -0x88(%rbp)
je 0x338c8e
movq -0x88(%rbp), %rax
cmpq -0x70(%rbp), %rax
je 0x338c8e
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x338d47
movq -0x38(%rbp), %rax
shlq %rax
orq -0x70(%rbp), %rax
movq %rax, -0x70(%rbp)
movq 0x10(%rbp), %rax
shlq %rax
orq -0x78(%rbp), %rax
movq %rax, -0x78(%rbp)
cmpq $0x0, 0x20(%rbp)
je 0x338d40
movq -0x70(%rbp), %rcx
shlq $0x20, %rcx
orq -0x80(%rbp), %rcx
movq 0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x78(%rbp), %rax
movl %eax, %ecx
movq 0x20(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x18(%rbp), %rax
subq -0x80(%rbp), %rax
movl %eax, %edx
movq 0x20(%rbp), %rax
movl 0xc(%rax), %ecx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl $0x80000000, %ecx       # imm = 0x80000000
orl %edx, %ecx
movl %ecx, 0xc(%rax)
movq 0x20(%rbp), %rax
movl 0xc(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x0, %ecx
movl %ecx, 0xc(%rax)
movq 0x20(%rbp), %rax
movw 0x10(%rax), %cx
andw $0xbfff, %cx            # imm = 0xBFFF
orw $0x4000, %cx            # imm = 0x4000
movw %cx, 0x10(%rax)
movq 0x20(%rbp), %rax
movb $0x1, 0x12(%rax)
movq 0x20(%rbp), %rax
movw 0x10(%rax), %cx
andw $0x7fff, %cx            # imm = 0x7FFF
orw $0x8000, %cx            # imm = 0x8000
movw %cx, 0x10(%rax)
movq -0x80(%rbp), %rax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xa0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)