// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: cal_integer_match_dis(ma_ug_t*, uc_block_t*, long, long, long, unsigned int*)
uint64_t cal_integer_match_dis(ma_ug_t *ug, uc_block_t *a, int64_t k_0, int64_t k_1, int64_t is_rev, uint32_t *is_g_connect)
{
    uint32_t i, k;
    assert((is_rev && k_1 < k_0) || ((!is_rev) && k_1 > k_0)); (*is_g_connect) = 0;
    if(is_rev) {
        i = k_0; k = k_1;
    } else {
        i = k_1; k = k_0;
    }
    // fprintf(stderr, "k_0::%ld, k_1::%ld\n", k_0, k_1);
    uint32_t li, lk, pk, bi = i; int64_t l;
    for (li = i, l = 0; i != (uint32_t)-1 && i >= k; i = a[i].pidx) {
        li = i; if(a[i].pidx != (uint32_t)-1 && i > k) l += a[i].pdis;
    }
    // fprintf(stderr, "+bi::%u, li::%u, i::%u, l::%ld\n", bi, li, i, l);
    if(is_rev) l = cal_forward_dis(ug->g, a, li, bi);
    // fprintf(stderr, "++bi::%u, li::%u, i::%u, l::%ld\n", bi, li, i, l);
    if(li == k) {///direct path
        (*is_g_connect) = 1;    
        return l;
    }
    i = li;
    assert(i > k); pk = k;
    for (lk = k; k != (uint32_t)-1 && k <= i; k = a[k].aidx) lk = k;
    // fprintf(stderr, "-pk::%u, lk::%u, k::%u\n", pk, lk, k);
    if(!is_rev) {
        for (k = lk; k != (uint32_t)-1 && k != pk; k = a[k].pidx) l += a[k].pdis;
    } else {
        l += cal_forward_dis(ug->g, a, pk, lk);
    }
    // fprintf(stderr, "--pk::%u, lk::%u, k::%u, l::%ld\n", pk, lk, k, l);
    if(l < 0) l = 0;
    k = lk;
    assert(i > k);
    return l + normlize_gdis(ug, &(a[i]), &(a[k]), is_rev);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %r12
xorl %eax, %eax
xorl %ecx, %ecx
cmpq %rdx, %r12
setl %al
setg %cl
testq %r8, %r8
cmovel %ecx, %eax
testb %al, %al
je 0x1f97c2
movq %r9, %r14
movq %rsi, %r15
movq %rdi, %r9
testq %r8, %r8
movl %edx, %ecx
cmovel %r12d, %ecx
movl $0x0, (%r14)
cmovel %edx, %r12d
cmpl $-0x1, %ecx
sete %al
cmpl %r12d, %ecx
setb %dl
xorl %r13d, %r13d
orb %al, %dl
jne 0x1f96ce
movl %ecx, %eax
movl %eax, %ebp
movl %eax, %eax
leaq (%rax,%rax,8), %rdx
movl 0x14(%r15,%rdx,4), %eax
cmpl $-0x1, %eax
sete %sil
cmpl %r12d, %ebp
setbe %dil
orb %sil, %dil
jne 0x1f96c2
leaq (%r15,%rdx,4), %rdx
movl 0x18(%rdx), %edx
addq %rdx, %r13
cmpl $-0x1, %eax
je 0x1f96d0
cmpl %r12d, %eax
jae 0x1f9698
jmp 0x1f96d0
movl %ecx, %ebp
testq %r8, %r8
je 0x1f96f2
movq 0x18(%r9), %rdi
movq %r15, %rsi
movl %ebp, %edx
movq %r8, %rbx
movq %r9, %r13
callq 0x1f947f
movq %r13, %r9
movq %rbx, %r8
movq %rax, %r13
cmpl %r12d, %ebp
jne 0x1f9703
movl $0x1, (%r14)
jmp 0x1f97b0
jbe 0x1f97e1
movl %r12d, %eax
movl %eax, %r14d
movl %eax, %ebx
leaq (%rbx,%rbx,8), %rax
movl 0x1c(%r15,%rax,4), %eax
cmpl $-0x1, %eax
je 0x1f9723
cmpl %ebp, %eax
jbe 0x1f970c
testq %r8, %r8
movq %r9, (%rsp)
je 0x1f9749
movq 0x18(%r9), %rdi
movq %r15, %rsi
movl %r12d, %edx
movl %r14d, %ecx
movq %r8, %r12
callq 0x1f947f
movq %r12, %r8
addq %rax, %r13
jmp 0x1f977d
cmpl $-0x1, %r14d
sete %al
cmpl %r12d, %r14d
sete %cl
orb %al, %cl
jne 0x1f977d
movl %r14d, %eax
movq %r13, %rcx
movl %eax, %eax
leaq (%rax,%rax,8), %rdx
movl 0x14(%r15,%rdx,4), %eax
movl 0x18(%r15,%rdx,4), %r13d
addq %rcx, %r13
cmpl $-0x1, %eax
je 0x1f977d
cmpl %r12d, %eax
jne 0x1f975d
cmpl %r14d, %ebp
jbe 0x1f9800
xorl %r14d, %r14d
testq %r13, %r13
cmovgq %r13, %r14
movl %ebp, %eax
leaq (%rax,%rax,8), %rax
leaq (%r15,%rax,4), %rsi
leaq (%rbx,%rbx,8), %rax
leaq (%r15,%rax,4), %rdx
movq (%rsp), %rdi
movq %r8, %rcx
callq 0x1f3f03
movq %rax, %r13
addq %r14, %r13
movq %r13, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x416c2(%rip), %rdi     # 0x23ae8b
leaq 0x3fb55(%rip), %rsi     # 0x239325
leaq 0x416e6(%rip), %rcx     # 0x23aebd
movl $0x1840, %edx           # imm = 0x1840
callq 0x2110
leaq 0x407bc(%rip), %rdi     # 0x239fa4
leaq 0x3fb36(%rip), %rsi     # 0x239325
leaq 0x416c7(%rip), %rcx     # 0x23aebd
movl $0x1853, %edx           # imm = 0x1853
callq 0x2110
leaq 0x4079d(%rip), %rdi     # 0x239fa4
leaq 0x3fb17(%rip), %rsi     # 0x239325
leaq 0x416a8(%rip), %rcx     # 0x23aebd
movl $0x185e, %edx           # imm = 0x185E
callq 0x2110