// File: 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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x334706
movq -0x28(%rbp), %rcx
movb $0x1, %al
cmpq -0x20(%rbp), %rcx
movb %al, -0x59(%rbp)
jl 0x334726
xorl %eax, %eax
cmpq $0x0, -0x30(%rbp)
movb %al, -0x5a(%rbp)
jne 0x334720
movq -0x28(%rbp), %rax
cmpq -0x20(%rbp), %rax
setg %al
movb %al, -0x5a(%rbp)
movb -0x5a(%rbp), %al
movb %al, -0x59(%rbp)
movb -0x59(%rbp), %al
testb $0x1, %al
jne 0x33472f
jmp 0x334731
jmp 0x334750
leaq 0x63727(%rip), %rdi     # 0x397e5f
leaq 0x61a7a(%rip), %rsi     # 0x3961b9
movl $0x1840, %edx           # imm = 0x1840
leaq 0x63746(%rip), %rcx     # 0x397e91
callq 0x2130
movq -0x38(%rbp), %rax
movl $0x0, (%rax)
cmpq $0x0, -0x30(%rbp)
je 0x334771
movq -0x20(%rbp), %rax
movl %eax, -0x3c(%rbp)
movq -0x28(%rbp), %rax
movl %eax, -0x40(%rbp)
jmp 0x33477f
movq -0x28(%rbp), %rax
movl %eax, -0x3c(%rbp)
movq -0x20(%rbp), %rax
movl %eax, -0x40(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x44(%rbp)
movq $0x0, -0x58(%rbp)
xorl %eax, %eax
cmpl $-0x1, -0x3c(%rbp)
movb %al, -0x5b(%rbp)
je 0x3347aa
movl -0x3c(%rbp), %eax
cmpl -0x40(%rbp), %eax
setae %al
movb %al, -0x5b(%rbp)
movb -0x5b(%rbp), %al
testb $0x1, %al
jne 0x3347b3
jmp 0x334806
movl -0x3c(%rbp), %eax
movl %eax, -0x44(%rbp)
movq -0x18(%rbp), %rax
movl -0x3c(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
cmpl $-0x1, 0x14(%rax)
je 0x3347ee
movl -0x3c(%rbp), %eax
cmpl -0x40(%rbp), %eax
jbe 0x3347ee
movq -0x18(%rbp), %rax
movl -0x3c(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
addq -0x58(%rbp), %rax
movq %rax, -0x58(%rbp)
jmp 0x3347f0
movq -0x18(%rbp), %rax
movl -0x3c(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl 0x14(%rax), %eax
movl %eax, -0x3c(%rbp)
jmp 0x334793
cmpq $0x0, -0x30(%rbp)
je 0x334828
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
movl -0x44(%rbp), %edx
movl -0x50(%rbp), %ecx
callq 0x3343a0
movq %rax, -0x58(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x40(%rbp), %eax
jne 0x334847
movq -0x38(%rbp), %rax
movl $0x1, (%rax)
movq -0x58(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x3349b8
movl -0x44(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x40(%rbp), %eax
jbe 0x334857
jmp 0x334876
leaq 0x625da(%rip), %rdi     # 0x396e38
leaq 0x61954(%rip), %rsi     # 0x3961b9
movl $0x1853, %edx           # imm = 0x1853
leaq 0x63620(%rip), %rcx     # 0x397e91
callq 0x2130
movl -0x40(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x40(%rbp), %eax
movl %eax, -0x48(%rbp)
xorl %eax, %eax
cmpl $-0x1, -0x40(%rbp)
movb %al, -0x5c(%rbp)
je 0x334899
movl -0x40(%rbp), %eax
cmpl -0x3c(%rbp), %eax
setbe %al
movb %al, -0x5c(%rbp)
movb -0x5c(%rbp), %al
testb $0x1, %al
jne 0x3348a2
jmp 0x3348be
movl -0x40(%rbp), %eax
movl %eax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movl -0x40(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl 0x1c(%rax), %eax
movl %eax, -0x40(%rbp)
jmp 0x334882
cmpq $0x0, -0x30(%rbp)
jne 0x33491c
movl -0x48(%rbp), %eax
movl %eax, -0x40(%rbp)
xorl %eax, %eax
cmpl $-0x1, -0x40(%rbp)
movb %al, -0x5d(%rbp)
je 0x3348e2
movl -0x40(%rbp), %eax
cmpl -0x4c(%rbp), %eax
setne %al
movb %al, -0x5d(%rbp)
movb -0x5d(%rbp), %al
testb $0x1, %al
jne 0x3348eb
jmp 0x33491a
movq -0x18(%rbp), %rax
movl -0x40(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
addq -0x58(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rax
movl -0x40(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl 0x14(%rax), %eax
movl %eax, -0x40(%rbp)
jmp 0x3348cb
jmp 0x33493b
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
movl -0x4c(%rbp), %edx
movl -0x48(%rbp), %ecx
callq 0x3343a0
addq -0x58(%rbp), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jge 0x33494a
movq $0x0, -0x58(%rbp)
movl -0x48(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x40(%rbp), %eax
jbe 0x33495a
jmp 0x334979
leaq 0x624d7(%rip), %rdi     # 0x396e38
leaq 0x61851(%rip), %rsi     # 0x3961b9
movl $0x185e, %edx           # imm = 0x185E
leaq 0x6351d(%rip), %rcx     # 0x397e91
callq 0x2130
movq -0x58(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x3c(%rbp), %eax
imulq $0x24, %rax, %rax
addq %rax, %rsi
movq -0x18(%rbp), %rdx
movl -0x40(%rbp), %eax
imulq $0x24, %rax, %rax
addq %rax, %rdx
movq -0x30(%rbp), %rcx
callq 0x328b90
movq %rax, %rcx
movq -0x68(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)