// File: chhylp123[P]hifiasm/gfa_ut.cpp
// Function: normlize_gdis_exact(ma_ug_t*, uc_block_t*, unsigned int, unsigned int, long)
int64_t normlize_gdis_exact(ma_ug_t *ug, uc_block_t *a, uint32_t i, uint32_t k, int64_t is_i2k_forward)
{
    assert(i > k);
    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;
    }
    
    if(is_i2k_forward) {
        l += (int64_t)(ug->g->seq[a[li].hid].len);
        l -= (int64_t)(ug->g->seq[a[bi].hid].len);
    }
    i = li;
    if(i == k) return l;
    assert(i > k); pk = k;
    for (lk = k; k != (uint32_t)-1 && k <= i; k = a[k].aidx) lk = k;
    for (k = lk; k != (uint32_t)-1 && k != pk; k = a[k].pidx) l += a[k].pdis;
    // assert(k == pk);
    if(is_i2k_forward) {
        l += (int64_t)(ug->g->seq[a[pk].hid].len);
        l -= (int64_t)(ug->g->seq[a[lk].hid].len);
    }
    if(l < 0) l = 0;
    k = lk;
    assert(i > k);
    return l + normlize_gdis(ug, &(a[i]), &(a[k]), is_i2k_forward);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x20(%rbp), %eax
jbe 0x328d04
jmp 0x328d23
leaq 0x6e12d(%rip), %rdi     # 0x396e38
leaq 0x6d4a7(%rip), %rsi     # 0x3961b9
movl $0x114a, %edx           # imm = 0x114A
leaq 0x6e120(%rip), %rcx     # 0x396e3e
callq 0x2130
movl -0x1c(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movq $0x0, -0x40(%rbp)
xorl %eax, %eax
cmpl $-0x1, -0x1c(%rbp)
movb %al, -0x41(%rbp)
je 0x328d4e
movl -0x1c(%rbp), %eax
cmpl -0x20(%rbp), %eax
setae %al
movb %al, -0x41(%rbp)
movb -0x41(%rbp), %al
testb $0x1, %al
jne 0x328d57
jmp 0x328daa
movl -0x1c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movq -0x18(%rbp), %rax
movl -0x1c(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
cmpl $-0x1, 0x14(%rax)
je 0x328d92
movl -0x1c(%rbp), %eax
cmpl -0x20(%rbp), %eax
jbe 0x328d92
movq -0x18(%rbp), %rax
movl -0x1c(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x328d94
movq -0x18(%rbp), %rax
movl -0x1c(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl 0x14(%rax), %eax
movl %eax, -0x1c(%rbp)
jmp 0x328d37
cmpq $0x0, -0x28(%rbp)
je 0x328e12
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movq -0x18(%rbp), %rcx
movl -0x2c(%rbp), %edx
imulq $0x24, %rdx, %rdx
addq %rdx, %rcx
movl (%rcx), %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movq -0x18(%rbp), %rcx
movl -0x38(%rbp), %edx
imulq $0x24, %rdx, %rdx
addq %rdx, %rcx
movl (%rcx), %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %ecx
movq -0x40(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x40(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x20(%rbp), %eax
jne 0x328e2d
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x328fd8
movl -0x1c(%rbp), %eax
cmpl -0x20(%rbp), %eax
jbe 0x328e37
jmp 0x328e56
leaq 0x6dffa(%rip), %rdi     # 0x396e38
leaq 0x6d374(%rip), %rsi     # 0x3961b9
movl $0x1157, %edx           # imm = 0x1157
leaq 0x6dfed(%rip), %rcx     # 0x396e3e
callq 0x2130
movl -0x20(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x30(%rbp)
xorl %eax, %eax
cmpl $-0x1, -0x20(%rbp)
movb %al, -0x42(%rbp)
je 0x328e79
movl -0x20(%rbp), %eax
cmpl -0x1c(%rbp), %eax
setbe %al
movb %al, -0x42(%rbp)
movb -0x42(%rbp), %al
testb $0x1, %al
jne 0x328e82
jmp 0x328e9e
movl -0x20(%rbp), %eax
movl %eax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movl -0x20(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl 0x1c(%rax), %eax
movl %eax, -0x20(%rbp)
jmp 0x328e62
movl -0x30(%rbp), %eax
movl %eax, -0x20(%rbp)
xorl %eax, %eax
cmpl $-0x1, -0x20(%rbp)
movb %al, -0x43(%rbp)
je 0x328ebb
movl -0x20(%rbp), %eax
cmpl -0x34(%rbp), %eax
setne %al
movb %al, -0x43(%rbp)
movb -0x43(%rbp), %al
testb $0x1, %al
jne 0x328ec4
jmp 0x328ef3
movq -0x18(%rbp), %rax
movl -0x20(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movl -0x20(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl 0x14(%rax), %eax
movl %eax, -0x20(%rbp)
jmp 0x328ea4
cmpq $0x0, -0x28(%rbp)
je 0x328f5b
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movq -0x18(%rbp), %rcx
movl -0x34(%rbp), %edx
imulq $0x24, %rdx, %rdx
addq %rdx, %rcx
movl (%rcx), %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movq -0x18(%rbp), %rcx
movl -0x30(%rbp), %edx
imulq $0x24, %rdx, %rdx
addq %rdx, %rcx
movl (%rcx), %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %ecx
movq -0x40(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jge 0x328f6a
movq $0x0, -0x40(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0x20(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x20(%rbp), %eax
jbe 0x328f7a
jmp 0x328f99
leaq 0x6deb7(%rip), %rdi     # 0x396e38
leaq 0x6d231(%rip), %rsi     # 0x3961b9
movl $0x1161, %edx           # imm = 0x1161
leaq 0x6deaa(%rip), %rcx     # 0x396e3e
callq 0x2130
movq -0x40(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %eax
imulq $0x24, %rax, %rax
addq %rax, %rsi
movq -0x18(%rbp), %rdx
movl -0x20(%rbp), %eax
imulq $0x24, %rax, %rax
addq %rax, %rdx
movq -0x28(%rbp), %rcx
callq 0x328b90
movq %rax, %rcx
movq -0x50(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)