// File: /workspace/github_cpp_makefile_star2_O3/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 0x204dcb
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 0x204ce7
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 0x204cdb
leaq (%r15,%rdx,4), %rdx
movl 0x18(%rdx), %edx
addq %rdx, %r13
cmpl $-0x1, %eax
je 0x204ce9
cmpl %r12d, %eax
jae 0x204cb1
jmp 0x204ce9
movl %ecx, %ebp
testq %r8, %r8
je 0x204d0b
movq 0x18(%r9), %rdi
movq %r15, %rsi
movl %ebp, %edx
movq %r8, %rbx
movq %r9, %r13
callq 0x204a98
movq %r13, %r9
movq %rbx, %r8
movq %rax, %r13
cmpl %r12d, %ebp
jne 0x204d1c
movl $0x1, (%r14)
jmp 0x204db9
jbe 0x204dea
movl %r12d, %eax
movl %eax, %r14d
movl %eax, %eax
leaq (%rax,%rax,8), %rbx
movl 0x1c(%r15,%rbx,4), %eax
cmpl $-0x1, %eax
je 0x204d3c
cmpl %ebp, %eax
jbe 0x204d25
testq %r8, %r8
movq %r9, (%rsp)
je 0x204d62
movq 0x18(%r9), %rdi
movq %r15, %rsi
movl %r12d, %edx
movl %r14d, %ecx
movq %r8, %r12
callq 0x204a98
movq %r12, %r8
addq %rax, %r13
jmp 0x204d8a
cmpl %r12d, %r14d
je 0x204d8a
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 0x204d8a
cmpl %r12d, %eax
jne 0x204d6a
cmpl %r14d, %ebp
jbe 0x204e09
xorl %r14d, %r14d
testq %r13, %r13
cmovgq %r13, %r14
movl %ebp, %eax
leaq (%rax,%rax,8), %rax
leaq (%r15,%rax,4), %rsi
leaq (%r15,%rbx,4), %rdx
movq (%rsp), %rdi
movq %r8, %rcx
callq 0x1ff427
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 0x4239d(%rip), %rdi     # 0x24716f
leaq 0x40830(%rip), %rsi     # 0x245609
leaq 0x423c1(%rip), %rcx     # 0x2471a1
movl $0x1840, %edx           # imm = 0x1840
callq 0x2110
leaq 0x41497(%rip), %rdi     # 0x246288
leaq 0x40811(%rip), %rsi     # 0x245609
leaq 0x423a2(%rip), %rcx     # 0x2471a1
movl $0x1853, %edx           # imm = 0x1853
callq 0x2110
leaq 0x41478(%rip), %rdi     # 0x246288
leaq 0x407f2(%rip), %rsi     # 0x245609
leaq 0x42383(%rip), %rcx     # 0x2471a1
movl $0x185e, %edx           # imm = 0x185E
callq 0x2110