// File: /workspace/github_cpp_makefile_star2_O2/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 0x1b8f46
movq %r9, %r14
movq %r8, %rbx
movq %rsi, %r15
movq %rdi, %r9
andl $0x0, (%r14)
testq %r8, %r8
movl %edx, %ecx
cmovel %r12d, %ecx
cmovel %edx, %r12d
xorl %r13d, %r13d
movl %ecx, %eax
movl %ecx, %edx
movl %eax, %ebp
cmpl $-0x1, %edx
je 0x1b8e6b
movl %edx, %eax
cmpl %r12d, %edx
jb 0x1b8e6b
movl %eax, %edx
imulq $0x24, %rdx, %rsi
movl 0x14(%r15,%rsi), %edx
cmpl $-0x1, %edx
sete %dil
cmpl %r12d, %eax
setbe %r8b
orb %dil, %r8b
movl %eax, %ebp
jne 0x1b8e34
addq %r15, %rsi
movl 0x18(%rsi), %esi
addq %rsi, %r13
jmp 0x1b8e32
testq %rbx, %rbx
je 0x1b8e87
movq 0x18(%r9), %rdi
movq %r15, %rsi
movl %ebp, %edx
movq %r9, %r13
callq 0x1b8c59
movq %r13, %r9
movq %rax, %r13
cmpl %r12d, %ebp
jne 0x1b8e95
movl $0x1, (%r14)
jmp 0x1b8f12
jbe 0x1b8f65
movl %r12d, %ecx
movl %r12d, %r14d
cmpl $-0x1, %ecx
je 0x1b8ebc
movl %ecx, %eax
cmpl %ebp, %ecx
ja 0x1b8ebc
movl %eax, %ecx
imulq $0x24, %rcx, %rcx
movl 0x1c(%r15,%rcx), %ecx
movl %eax, %r14d
jmp 0x1b8ea1
testq %rbx, %rbx
movq %r9, (%rsp)
je 0x1b8f24
movq 0x18(%r9), %rdi
movq %r15, %rsi
movl %r12d, %edx
movl %r14d, %ecx
callq 0x1b8c59
addq %rax, %r13
cmpl %r14d, %ebp
jbe 0x1b8f84
xorl %r12d, %r12d
testq %r13, %r13
cmovgq %r13, %r12
movl %ebp, %eax
imulq $0x24, %rax, %rsi
addq %r15, %rsi
movl %r14d, %eax
imulq $0x24, %rax, %rdx
addq %r15, %rdx
movq (%rsp), %rdi
movq %rbx, %rcx
callq 0x1b3351
movq %rax, %r13
addq %r12, %r13
movq %r13, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r14d, %eax
cmpl $-0x1, %eax
je 0x1b8eda
cmpl %r12d, %eax
je 0x1b8eda
movl %eax, %eax
imulq $0x24, %rax, %rcx
movl 0x14(%r15,%rcx), %eax
movl 0x18(%r15,%rcx), %ecx
addq %rcx, %r13
jmp 0x1b8f27
leaq 0x401e1(%rip), %rdi     # 0x1f912e
leaq 0x3e585(%rip), %rsi     # 0x1f74d9
leaq 0x40205(%rip), %rcx     # 0x1f9160
movl $0x1840, %edx           # imm = 0x1840
callq 0x2110
leaq 0x3f1ec(%rip), %rdi     # 0x1f8158
leaq 0x3e566(%rip), %rsi     # 0x1f74d9
leaq 0x401e6(%rip), %rcx     # 0x1f9160
movl $0x1853, %edx           # imm = 0x1853
callq 0x2110
leaq 0x3f1cd(%rip), %rdi     # 0x1f8158
leaq 0x3e547(%rip), %rsi     # 0x1f74d9
leaq 0x401c7(%rip), %rcx     # 0x1f9160
movl $0x185e, %edx           # imm = 0x185E
callq 0x2110