// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: dis_check_integer_aln_t(all_ul_t*, ul_str_idx_t*, ma_ug_t*, integer_aln_t*, integer_aln_t*, unsigned int, unsigned int, unsigned int, double, long)
uint32_t dis_check_integer_aln_t(all_ul_t *ul_idx, ul_str_idx_t *str_idx, ma_ug_t *ug, integer_aln_t *li, integer_aln_t *lk, 
uint32_t qid, uint32_t tid, uint32_t is_rev, double diff_rate, int64_t hard_thres)
{
    assert(((uint32_t)li->tn_rev_qk) >= ((uint32_t)lk->tn_rev_qk));
    if(((uint32_t)li->tn_rev_qk) == ((uint32_t)lk->tn_rev_qk)) return 0;
    if(li->tk <= lk->tk) return 0;
    ul_str_t *q = &(str_idx->str.a[qid]), *t = &(str_idx->str.a[tid]);
    uc_block_t *iq, *it, *kq, *kt; int64_t qlen, tlen, mm, dd, i_qk, k_qk, i_tk, k_tk;
    i_qk = ((uint32_t)li->tn_rev_qk); k_qk = ((uint32_t)lk->tn_rev_qk);
    if(!is_rev) {
        i_tk = li->tk; k_tk = lk->tk;
    } else {
        i_tk = t->cn - lk->tk - 1; k_tk = t->cn - li->tk - 1;
    }
    iq = &(ul_idx->a[qid].bb.a[(q->a[i_qk]>>32)]);
    it = &(ul_idx->a[tid].bb.a[(t->a[i_tk]>>32)]);

    kq = &(ul_idx->a[qid].bb.a[(q->a[k_qk]>>32)]); 
    kt = &(ul_idx->a[tid].bb.a[(t->a[k_tk]>>32)]);
    qlen = normlize_gdis(ug, iq, kq, 0); tlen = normlize_gdis(ug, it, kt, is_rev);
    if(qlen < tlen) {
        mm = qlen; dd = tlen - qlen;
    } else {
        mm = tlen; dd = qlen - tlen;
    }

    // if(tid == 3074) {
    //     fprintf(stderr, "\n+++[M::%s::] qlen::%ld, tlen::%ld, iq->hid::%u, kq->hid::%u, (q->a[i_qk]>>32)::%lu, (q->a[k_qk]>>32)::%lu, (t->a[i_tk]>>32)::%lu, (t->a[k_tk]>>32)::%lu\n", 
    //     __func__, qlen, tlen, iq->hid, kq->hid, 
    //     (q->a[i_qk]>>32), (q->a[k_qk]>>32), (t->a[i_tk]>>32), (t->a[k_tk]>>32));
    // }

    if(dd <= (mm*diff_rate) || dd < hard_thres) return 1;
    
    qlen = normlize_gdis_exact(ug, ul_idx->a[qid].bb.a, (q->a[i_qk]>>32), (q->a[k_qk]>>32), 0);
    tlen = normlize_gdis_exact(ug, ul_idx->a[tid].bb.a, (t->a[i_tk]>>32), (t->a[k_tk]>>32), is_rev);
    if(qlen < tlen) {
        mm = qlen; dd = tlen - qlen;
    } else {
        mm = tlen; dd = qlen - tlen;
    }

    if(dd <= (mm*diff_rate) || dd < hard_thres) return 1;

    // if(tid == 3074) {
    //     fprintf(stderr, "---[M::%s::] qlen::%ld, tlen::%ld, iq->hid::%u, kq->hid::%u\n", 
    //     __func__, qlen, tlen, iq->hid, kq->hid);
    // }
    

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq 0x10(%rcx), %r11
movq 0x10(%r8), %r10
cmpl %r10d, %r11d
jb 0x1f434b
xorl %eax, %eax
cmpl %r10d, %r11d
je 0x1f433c
movq %rdx, %r15
movl (%rcx), %edx
movl (%r8), %r8d
cmpl %r8d, %edx
jbe 0x1f433c
movl %r11d, %ecx
movl %r10d, %eax
movq 0x40(%rsi), %rsi
movl %r9d, %r9d
movl 0x70(%rsp), %r13d
movq %r13, %rbx
shlq $0x5, %rbx
addq %rsi, %rbx
cmpl $0x0, 0x78(%rsp)
movsd %xmm0, (%rsp)
je 0x1f41b9
movl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
andl 0x18(%rbx), %r10d
notl %r8d
addl %r10d, %r8d
notl %edx
movl %edx, %r11d
addl %r10d, %r11d
movl %r8d, %edx
movl %r11d, %r8d
movl %r8d, %r10d
movl %edx, %r11d
movq %rdi, 0x28(%rsp)
movq 0x48(%rdi), %rdx
imulq $0x58, %r9, %r8
movq 0x30(%rdx,%r8), %r14
shlq $0x5, %r9
movq 0x10(%rsi,%r9), %r8
movq (%r8,%rcx,8), %r12
shrq $0x20, %r12
leaq (%r12,%r12,8), %rcx
leaq (%r14,%rcx,4), %rsi
imulq $0x58, %r13, %rcx
movq %rcx, 0x8(%rsp)
movq 0x30(%rdx,%rcx), %rcx
movq 0x10(%rbx), %rdi
movq %r11, 0x18(%rsp)
movl 0x4(%rdi,%r11,8), %edx
leaq (%rdx,%rdx,8), %rdx
leaq (%rcx,%rdx,4), %rbp
movq (%r8,%rax,8), %r13
shrq $0x20, %r13
leaq (,%r13,8), %rax
addq %r13, %rax
movq %r14, 0x10(%rsp)
leaq (%r14,%rax,4), %rdx
movq %r10, 0x20(%rsp)
movl 0x4(%rdi,%r10,8), %eax
leaq (%rax,%rax,8), %rax
leaq (%rcx,%rax,4), %r14
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x1f3f03
movq %r15, %rdi
movq %rax, %r15
movl 0x78(%rsp), %ecx
movq %rdi, 0x30(%rsp)
movq %rbp, %rsi
movq %r14, %rdx
callq 0x1f3f03
movq %rax, %rcx
movq %r15, %rax
subq %rcx, %rax
cmovlq %r15, %rcx
movq %rax, %rdx
negq %rdx
cmovsq %rax, %rdx
movl $0x1, %eax
movq 0x80(%rsp), %rbp
cmpq %rbp, %rdx
jl 0x1f433c
cvtsi2sd %rdx, %xmm0
cvtsi2sd %rcx, %xmm1
movsd (%rsp), %xmm2
mulsd %xmm2, %xmm1
ucomisd %xmm0, %xmm1
movq 0x30(%rsp), %r15
movq 0x28(%rsp), %r14
jae 0x1f433c
movq %r15, %rdi
movq 0x10(%rsp), %rsi
movl %r12d, %edx
movl %r13d, %ecx
xorl %r8d, %r8d
callq 0x1f3f8d
movq %r14, %rcx
movq %rax, %r14
movq 0x48(%rcx), %rax
movq 0x8(%rsp), %rcx
movq 0x30(%rax,%rcx), %rsi
movq 0x10(%rbx), %rax
movq 0x18(%rsp), %rcx
movl 0x4(%rax,%rcx,8), %edx
movq 0x20(%rsp), %rcx
movl 0x4(%rax,%rcx,8), %ecx
movq %r15, %rdi
movl 0x78(%rsp), %r8d
callq 0x1f3f8d
movq %r14, %rcx
subq %rax, %rcx
cmovlq %r14, %rax
movq %rcx, %rdx
negq %rdx
cmovsq %rcx, %rdx
xorps %xmm0, %xmm0
cvtsi2sd %rdx, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
mulsd (%rsp), %xmm1
ucomisd %xmm0, %xmm1
setae %al
cmpq %rbp, %rdx
setl %cl
orb %al, %cl
movzbl %cl, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x45caa(%rip), %rdi     # 0x239ffc
leaq 0x44fcc(%rip), %rsi     # 0x239325
leaq 0x45cd3(%rip), %rcx     # 0x23a033
movl $0x1168, %edx           # imm = 0x1168
callq 0x2110