// File: chhylp123[P]hifiasm/gfa_ut.cpp
// Function: normlize_gdis(ma_ug_t*, uc_block_t*, uc_block_t*, long)
int64_t normlize_gdis(ma_ug_t *ug, uc_block_t *i, uc_block_t *k, int64_t is_i2k_forward)
{
    int64_t i_len, k_len;
    ///i > k
    // if(is_i2k_forward == 0){
    //     if(!i->rev) {
    //         i_len = i->qe + (ug->g->seq[i->hid].len - i->te);
    //     } else {
    //         i_len = i->qe + i->ts;
    //     }

    //     if(!k->rev) {
    //         k_len = k->qe + (ug->g->seq[k->hid].len - k->te);
    //     } else {
    //         k_len = k->qe + k->ts;
    //     }
    // } else {
    //     if(!i->rev) {
    //         i_len = (int64_t)i->qs - (int64_t)i->ts;
    //     } else {
    //         i_len = (int64_t)i->qs - (int64_t)(ug->g->seq[i->hid].len - i->te);
    //     }
    //     if(i_len < 0) i_len = 0;

    //     if(!k->rev) {
    //         k_len = (int64_t)k->qs - (int64_t)k->ts;
    //     } else {
    //         k_len = (int64_t)k->qs - (int64_t)(ug->g->seq[k->hid].len - k->te);
    //     }
    //     if(k_len < 0) k_len = 0;
    // }

    if(!i->rev) {
        i_len = i->qe + (ug->g->seq[i->hid].len - i->te);
    } else {
        i_len = i->qe + i->ts;
    }
    

    if(!k->rev) {
        k_len = k->qe + (ug->g->seq[k->hid].len - k->te);
    } else {
        k_len = k->qe + k->ts;
    }

    if(is_i2k_forward) {
        i_len -= ug->g->seq[i->hid].len;
        k_len -= ug->g->seq[k->hid].len;
    }
    

    if(i_len >= k_len) return i_len - k_len;
    // assert(i_len >= k_len);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x18(%rbp), %rax
movb 0x20(%rax), %al
shrb $0x5, %al
andb $0x1, %al
cmpb $0x0, %al
jne 0x328be7
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq 0x20(%rcx), %rcx
movq -0x18(%rbp), %rdx
movl (%rdx), %edx
movl (%rcx,%rdx,8), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movq -0x18(%rbp), %rdx
subl 0x10(%rdx), %ecx
addl %ecx, %eax
movl %eax, %eax
movq %rax, -0x30(%rbp)
jmp 0x328bfb
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x18(%rbp), %rcx
addl 0xc(%rcx), %eax
movl %eax, %eax
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rax
movb 0x20(%rax), %al
shrb $0x5, %al
andb $0x1, %al
cmpb $0x0, %al
jne 0x328c3e
movq -0x20(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq 0x20(%rcx), %rcx
movq -0x20(%rbp), %rdx
movl (%rdx), %edx
movl (%rcx,%rdx,8), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movq -0x20(%rbp), %rdx
subl 0x10(%rdx), %ecx
addl %ecx, %eax
movl %eax, %eax
movq %rax, -0x38(%rbp)
jmp 0x328c52
movq -0x20(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x20(%rbp), %rcx
addl 0xc(%rcx), %eax
movl %eax, %eax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x328cab
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movq -0x18(%rbp), %rcx
movl (%rcx), %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %ecx
movq -0x30(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movq -0x20(%rbp), %rcx
movl (%rcx), %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %ecx
movq -0x38(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x38(%rbp), %rax
jl 0x328cc3
movq -0x30(%rbp), %rax
subq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x328ccb
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
popq %rbp
retq
nopw %cs:(%rax,%rax)