// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: cal_forward_dis(asg_t*, uc_block_t*, unsigned int, unsigned int)
uint64_t cal_forward_dis(asg_t *g, uc_block_t *a, uint32_t s, uint32_t e)
{
    uint32_t i, v, w, nv, z; int64_t l; asg_arc_t *av;
    //fprintf(stderr, "\n[M::%s::] s::%u, e::%u\n", __func__, s, e);
    ///TODO: a[i].aidx might be < i; if s == e, then i <= e might be wrong, cannot pass the assert(li == e);
    for(i = s, l = 0, v = w = (uint32_t)-1; i != (uint32_t)-1 && i != e; i = a[i].aidx) {
        w = (((uint32_t)(a[i].hid))<<1)|((uint32_t)(a[i].rev));
        if(v != (uint32_t)-1) {
            av = asg_arc_a(g, v); nv = asg_arc_n(g, v); 
            for (z = 0; z < nv; z++) {
                if(av[z].del) continue;
                if(av[z].v == w) break;
            }
            if(z < nv) {//found
                l += (uint32_t)av[z].ul;
            } else {
                l += a[i].pdis + g->seq[v>>1].len - g->seq[w>>1].len;
            }
        }
        v = w; 
        // fprintf(stderr, "[M::%s::] i::%u, a[i].aidx::%u, a[i].qs::%u, a[i].qe::%u\n", __func__, i, a[i].aidx, a[i].qs, a[i].qe);
    }


    assert(i == e);
    w = (((uint32_t)(a[i].hid))<<1)|((uint32_t)(a[i].rev));
    if(v != (uint32_t)-1) {
        av = asg_arc_a(g, v); nv = asg_arc_n(g, v); 
        for (z = 0; z < nv; z++) {
            if(av[z].del) continue;
            if(av[z].v == w) break;
        }
        if(z < nv) {//found
            l += (uint32_t)av[z].ul;
        } else {
            l += a[i].pdis + g->seq[v>>1].len - g->seq[w>>1].len;
        }
    }
    v = w; 


    if(l < 0) l = 0;
    return l;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq $-0x1
popq %rax
xorl %r8d, %r8d
movl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
movl %eax, %ebx
cmpl $-0x1, %edx
je 0x1b8d1c
cmpl %ecx, %edx
je 0x1b8d1c
movl %edx, %edx
imulq $0x24, %rdx, %r10
leaq (%rsi,%r10), %rdx
movl (%rsi,%r10), %r11d
movl 0x20(%rsi,%r10), %r10d
shrl $0x5, %r10d
andl $0x1, %r10d
leal (%r10,%r11,2), %r10d
cmpl $-0x1, %eax
je 0x1b8d11
movq 0x8(%rdi), %r14
movq 0x28(%rdi), %r15
movq (%r15,%rbx,8), %rbx
movl %ebx, %r15d
shrq $0x20, %rbx
imulq $0x18, %r15, %r15
imulq $0x18, %rbx, %rbx
leaq (%r14,%rbx), %r13
addq $0xc, %r13
xorl %r12d, %r12d
cmpq %r12, %r15
je 0x1b8ce5
cmpl $0x0, (%r13,%r12)
js 0x1b8cdf
cmpl %r10d, -0x4(%r13,%r12)
je 0x1b8d07
addq $0x18, %r12
jmp 0x1b8ccb
movq 0x20(%rdi), %rbx
shrl %eax
movl (%rbx,%rax,8), %eax
andl %r9d, %eax
addl 0x18(%rdx), %eax
andl $0x7fffffff, %r11d      # imm = 0x7FFFFFFF
movl (%rbx,%r11,8), %r11d
andl %r9d, %r11d
subl %r11d, %eax
jmp 0x1b8d0e
addq %rbx, %r14
movl (%r12,%r14), %eax
addq %rax, %r8
movl 0x1c(%rdx), %edx
movl %r10d, %eax
jmp 0x1b8c6e
cmpl %ecx, %edx
jne 0x1b8dc6
cmpl $-0x1, %eax
je 0x1b8db3
movl %ecx, %ecx
imulq $0x24, %rcx, %r9
leaq (%rsi,%r9), %rdx
movl (%rsi,%r9), %ecx
movl 0x20(%rsi,%r9), %esi
shrl $0x5, %esi
andl $0x1, %esi
leal (%rsi,%rcx,2), %r9d
movq 0x8(%rdi), %rsi
movq 0x28(%rdi), %r10
movq (%r10,%rbx,8), %r10
movl %r10d, %r11d
shrq $0x20, %r10
imulq $0x18, %r11, %rbx
imulq $0x18, %r10, %r10
leaq (%r10,%rsi), %r14
addq $0xc, %r14
xorl %r11d, %r11d
cmpq %r11, %rbx
je 0x1b8d89
cmpl $0x0, (%r14,%r11)
js 0x1b8d83
cmpl %r9d, -0x4(%r14,%r11)
je 0x1b8da9
addq $0x18, %r11
jmp 0x1b8d70
movq 0x20(%rdi), %rsi
shrl %eax
movl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
movl (%rsi,%rax,8), %eax
andl %edi, %eax
addl 0x18(%rdx), %eax
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl (%rsi,%rcx,8), %edi
subl %edi, %eax
jmp 0x1b8db0
addq %rsi, %r10
movl (%r11,%r10), %eax
addq %rax, %r8
xorl %eax, %eax
testq %r8, %r8
cmovgq %r8, %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
leaq 0x40316(%rip), %rdi     # 0x1f90e3
leaq 0x3e705(%rip), %rsi     # 0x1f74d9
leaq 0x4030f(%rip), %rcx     # 0x1f90ea
movl $0x1828, %edx           # imm = 0x1828
callq 0x2110