// File: /workspace/github_cpp_makefile_star2_O1/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
cmpl $-0x1, %edx
sete %al
cmpl %ecx, %edx
sete %r8b
orb %al, %r8b
jne 0x1f955d
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
xorl %r8d, %r8d
movl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
movl %edx, %eax
leaq (%rax,%rax,8), %rax
leaq (%rsi,%rax,4), %rdx
movl (%rdx), %r11d
movl 0x20(%rdx), %eax
shrl $0x5, %eax
andl $0x1, %eax
leal (%rax,%r11,2), %eax
cmpl $-0x1, %r10d
je 0x1f9548
movq 0x28(%rdi), %rbx
movl %r10d, %r14d
movq (%rbx,%r14,8), %r14
testl %r14d, %r14d
je 0x1f9518
movq 0x8(%rdi), %rbx
movq %r14, %r15
shrq $0x20, %r15
movl %r14d, %r12d
leaq (%r15,%r15,2), %r14
leaq (%rbx,%r14,8), %r15
addq $0xc, %r15
shlq $0x3, %r12
leaq (%r12,%r12,2), %r13
xorl %r12d, %r12d
cmpl $0x0, (%r15,%r12)
js 0x1f950f
cmpl %eax, -0x4(%r15,%r12)
je 0x1f953d
addq $0x18, %r12
cmpq %r12, %r13
jne 0x1f9501
movq 0x20(%rdi), %rbx
shrl %r10d
movl (%rbx,%r10,8), %r10d
andl %r9d, %r10d
addl 0x18(%rdx), %r10d
andl $0x7fffffff, %r11d      # imm = 0x7FFFFFFF
movl (%rbx,%r11,8), %r11d
andl %r9d, %r11d
subl %r11d, %r10d
jmp 0x1f9545
leaq (%rbx,%r14,8), %r10
movl (%r12,%r10), %r10d
addq %r10, %r8
movl 0x1c(%rdx), %edx
cmpl $-0x1, %edx
je 0x1f9565
movl %eax, %r10d
cmpl %ecx, %edx
jne 0x1f94ac
jmp 0x1f9565
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
xorl %r8d, %r8d
cmpl %ecx, %edx
jne 0x1f961e
cmpl $-0x1, %eax
je 0x1f960b
movl %edx, %ecx
leaq (%rcx,%rcx,8), %rdx
movl (%rsi,%rdx,4), %ecx
movq 0x28(%rdi), %r9
movl %eax, %r10d
movq (%r9,%r10,8), %r11
testl %r11d, %r11d
je 0x1f95dc
movl 0x20(%rsi,%rdx,4), %r9d
shrl $0x5, %r9d
andl $0x1, %r9d
leal (%r9,%rcx,2), %r10d
movq 0x8(%rdi), %r9
movq %r11, %rbx
shrq $0x20, %rbx
movl %r11d, %r14d
leaq (%rbx,%rbx,2), %r11
leaq (%r9,%r11,8), %rbx
addq $0xc, %rbx
shlq $0x3, %r14
leaq (%r14,%r14,2), %r15
xorl %r14d, %r14d
cmpl $0x0, (%rbx,%r14)
js 0x1f95d3
cmpl %r10d, -0x4(%rbx,%r14)
je 0x1f9600
addq $0x18, %r14
cmpq %r14, %r15
jne 0x1f95c5
leaq (%rsi,%rdx,4), %rdx
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 0x1f9608
leaq (%r9,%r11,8), %rax
movl (%r14,%rax), %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 0x4181b(%rip), %rdi     # 0x23ae40
leaq 0x3fcf9(%rip), %rsi     # 0x239325
leaq 0x41814(%rip), %rcx     # 0x23ae47
movl $0x1828, %edx           # imm = 0x1828
callq 0x2110