// File: chhylp123[P]hifiasm/Overlaps.cpp
// Function: extract_sub_overlaps(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, kv_u_trans_hit_t*, unsigned int)
void extract_sub_overlaps(uint32_t i_tScur, uint32_t i_tEcur, uint32_t i_tSpre, uint32_t i_tEpre,
uint32_t tn, kv_u_trans_hit_t* ktb, uint32_t bn)
{
    uint32_t i, ovlp, found, beg, end, offS, offE;
    u_trans_hit_t *q = NULL, x;
    for (i = found = 0; i < bn; i++)
    {
        q = &(ktb->a[i]);///for q, already know [qScur, qEcur), [qSpre, qEpre), [tScur, tEcur)

        ovlp = ((MIN(i_tEcur, q->tEcur) > MAX(i_tScur, q->tScur))?
                                        MIN(i_tEcur, q->tEcur) - MAX(i_tScur, q->tScur):0);
        if(found == 1 && ovlp == 0) break;
        if(ovlp > 0) found = 1;
        if(ovlp == 0) continue;

        
        beg = MAX(i_tScur, q->tScur); end = MIN(i_tEcur, q->tEcur);
        offS = beg - q->tScur; offE = q->tEcur - end;
        x.tScur = q->tScur + offS; 
        x.tEcur = q->tEcur - offE;
        //x.qScur = q->qScur + offS; 
        x.qScur = q->qScur + get_offset_adjust(offS, q->tEcur-q->tScur, q->qEcur-q->qScur);        
        ///x.qEcur = q->qEcur - offE;
        x.qScur = q->qEcur - get_offset_adjust(offE, q->tEcur-q->tScur, q->qEcur-q->qScur);  

        x.qn = q->qn;
        offS = beg - q->tScur; offE = q->tEcur - end;
        if((x.qn&1) == 0)
        {
            // x.qSpre = q->qSpre + offS; 
            x.qSpre = q->qSpre + get_offset_adjust(offS, q->tEcur-q->tScur, q->qEpre-q->qSpre);  
            // x.qEpre = q->qEpre - offE;
            x.qEpre = q->qEpre - get_offset_adjust(offE, q->tEcur-q->tScur, q->qEpre-q->qSpre);
        }
        else
        {
            // x.qSpre = q->qSpre + offE; 
            x.qSpre = q->qSpre + get_offset_adjust(offE, q->tEcur-q->tScur, q->qEpre-q->qSpre);
            // x.qEpre = q->qEpre - offS;
            x.qEpre = q->qEpre - get_offset_adjust(offS, q->tEcur-q->tScur, q->qEpre-q->qSpre);
        }

        x.tn = tn; 
        offS = beg - i_tScur; offE = i_tEcur - end;
        if((x.tn&1) == 0)
        {
            // x.tSpre = i_tSpre + offS; 
            x.tSpre = i_tSpre +  get_offset_adjust(offS, i_tEcur-i_tScur, i_tEpre-i_tSpre); 
            // x.tEpre = i_tEpre - offE;
            x.tEpre = i_tEpre - get_offset_adjust(offE, i_tEcur-i_tScur, i_tEpre-i_tSpre); 
        }
        else
        {
            // x.tSpre = i_tSpre + offE; 
            x.tSpre = i_tSpre + get_offset_adjust(offE, i_tEcur-i_tScur, i_tEpre-i_tSpre); 
            // x.tEpre = i_tEpre - offS;
            x.tEpre = i_tEpre - get_offset_adjust(offS, i_tEcur-i_tScur, i_tEpre-i_tSpre);
        }
        
        kv_push(u_trans_hit_t, *ktb, x);

        // if(x.tSpre >= x.tEpre || x.qSpre >= x.qEpre)
        // {
        //     fprintf(stderr, "\n*********x.qn: %u, x.tn: %u\n", x.qn, x.tn);
        //     fprintf(stderr, "x.qSpre: %u, x.qEpre: %u, x.tSpre: %u, x.tEpre: %u\n", 
        //     x.qSpre, x.qEpre, x.tSpre, x.tEpre);
        //     fprintf(stderr, "q->qScur: %u, q->qEcur: %u, q->qSpre: %u, q->qEpre: %u\n", 
        //     q->qScur, q->qEcur, q->qSpre, q->qEpre);
        //     fprintf(stderr, "q->tScur: %u, q->tEcur: %u, q->tSpre: %u, q->tEpre: %u\n", 
        //     q->tScur, q->tEcur, q->tSpre, q->tEpre);
        //     fprintf(stderr, "i_tScur: %u, i_tEcur: %u, i_tSpre: %u, i_tEpre: %u\n", 
        //     i_tScur, i_tEcur, i_tSpre, i_tEpre);
        // }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movl 0x10(%rbp), %eax
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
movl %edx, -0xc(%rbp)
movl %ecx, -0x10(%rbp)
movl %r8d, -0x14(%rbp)
movq %r9, -0x20(%rbp)
movq $0x0, -0x48(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl 0x10(%rbp), %eax
jae 0xf88eb
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x24(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movl -0x8(%rbp), %eax
movq -0x48(%rbp), %rcx
cmpl 0x20(%rcx), %eax
ja 0xf846e
movl -0x8(%rbp), %eax
movl %eax, -0x74(%rbp)
jmp 0xf8478
movq -0x48(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x74(%rbp)
movl -0x74(%rbp), %eax
movl %eax, -0x78(%rbp)
movl -0x4(%rbp), %eax
movq -0x48(%rbp), %rcx
cmpl 0x1c(%rcx), %eax
jb 0xf8492
movl -0x4(%rbp), %eax
movl %eax, -0x7c(%rbp)
jmp 0xf849c
movq -0x48(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, -0x7c(%rbp)
movl -0x78(%rbp), %eax
movl -0x7c(%rbp), %ecx
cmpl %ecx, %eax
jbe 0xf8507
movl -0x8(%rbp), %eax
movq -0x48(%rbp), %rcx
cmpl 0x20(%rcx), %eax
ja 0xf84ba
movl -0x8(%rbp), %eax
movl %eax, -0x80(%rbp)
jmp 0xf84c4
movq -0x48(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x80(%rbp)
movl -0x80(%rbp), %eax
movl %eax, -0x84(%rbp)
movl -0x4(%rbp), %eax
movq -0x48(%rbp), %rcx
cmpl 0x1c(%rcx), %eax
jb 0xf84e4
movl -0x4(%rbp), %eax
movl %eax, -0x88(%rbp)
jmp 0xf84f1
movq -0x48(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, -0x88(%rbp)
movl -0x84(%rbp), %eax
movl -0x88(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x8c(%rbp)
jmp 0xf8511
xorl %eax, %eax
movl %eax, -0x8c(%rbp)
jmp 0xf8511
movl -0x8c(%rbp), %eax
movl %eax, -0x28(%rbp)
cmpl $0x1, -0x2c(%rbp)
jne 0xf852b
cmpl $0x0, -0x28(%rbp)
jne 0xf852b
jmp 0xf88eb
cmpl $0x0, -0x28(%rbp)
jbe 0xf8538
movl $0x1, -0x2c(%rbp)
cmpl $0x0, -0x28(%rbp)
jne 0xf8543
jmp 0xf88dd
movl -0x4(%rbp), %eax
movq -0x48(%rbp), %rcx
cmpl 0x1c(%rcx), %eax
jb 0xf855a
movl -0x4(%rbp), %eax
movl %eax, -0x90(%rbp)
jmp 0xf8567
movq -0x48(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, -0x90(%rbp)
movl -0x90(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x8(%rbp), %eax
movq -0x48(%rbp), %rcx
cmpl 0x20(%rcx), %eax
ja 0xf8587
movl -0x8(%rbp), %eax
movl %eax, -0x94(%rbp)
jmp 0xf8594
movq -0x48(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x94(%rbp)
movl -0x94(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x30(%rbp), %eax
movq -0x48(%rbp), %rcx
subl 0x1c(%rcx), %eax
movl %eax, -0x38(%rbp)
movq -0x48(%rbp), %rax
movl 0x20(%rax), %eax
subl -0x34(%rbp), %eax
movl %eax, -0x3c(%rbp)
movq -0x48(%rbp), %rax
movl 0x1c(%rax), %eax
addl -0x38(%rbp), %eax
movl %eax, -0x54(%rbp)
movq -0x48(%rbp), %rax
movl 0x20(%rax), %eax
subl -0x3c(%rbp), %eax
movl %eax, -0x50(%rbp)
movq -0x48(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x9c(%rbp)
movl -0x38(%rbp), %edi
movq -0x48(%rbp), %rax
movl 0x20(%rax), %esi
movq -0x48(%rbp), %rax
subl 0x1c(%rax), %esi
movq -0x48(%rbp), %rax
movl 0xc(%rax), %edx
movq -0x48(%rbp), %rax
subl 0x8(%rax), %edx
callq 0xc14d0
movl %eax, %ecx
movl -0x9c(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x68(%rbp)
movq -0x48(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x98(%rbp)
movl -0x3c(%rbp), %edi
movq -0x48(%rbp), %rax
movl 0x20(%rax), %esi
movq -0x48(%rbp), %rax
subl 0x1c(%rax), %esi
movq -0x48(%rbp), %rax
movl 0xc(%rax), %edx
movq -0x48(%rbp), %rax
subl 0x8(%rax), %edx
callq 0xc14d0
movl %eax, %ecx
movl -0x98(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x68(%rbp)
movq -0x48(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x60(%rbp)
movl -0x30(%rbp), %eax
movq -0x48(%rbp), %rcx
subl 0x1c(%rcx), %eax
movl %eax, -0x38(%rbp)
movq -0x48(%rbp), %rax
movl 0x20(%rax), %eax
subl -0x34(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x60(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0xf86f7
movq -0x48(%rbp), %rax
movl (%rax), %eax
movl %eax, -0xa4(%rbp)
movl -0x38(%rbp), %edi
movq -0x48(%rbp), %rax
movl 0x20(%rax), %esi
movq -0x48(%rbp), %rax
subl 0x1c(%rax), %esi
movq -0x48(%rbp), %rax
movl 0x4(%rax), %edx
movq -0x48(%rbp), %rax
subl (%rax), %edx
callq 0xc14d0
movl %eax, %ecx
movl -0xa4(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x70(%rbp)
movq -0x48(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0xa0(%rbp)
movl -0x3c(%rbp), %edi
movq -0x48(%rbp), %rax
movl 0x20(%rax), %esi
movq -0x48(%rbp), %rax
subl 0x1c(%rax), %esi
movq -0x48(%rbp), %rax
movl 0x4(%rax), %edx
movq -0x48(%rbp), %rax
subl (%rax), %edx
callq 0xc14d0
movl %eax, %ecx
movl -0xa0(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x6c(%rbp)
jmp 0xf8770
movq -0x48(%rbp), %rax
movl (%rax), %eax
movl %eax, -0xac(%rbp)
movl -0x3c(%rbp), %edi
movq -0x48(%rbp), %rax
movl 0x20(%rax), %esi
movq -0x48(%rbp), %rax
subl 0x1c(%rax), %esi
movq -0x48(%rbp), %rax
movl 0x4(%rax), %edx
movq -0x48(%rbp), %rax
subl (%rax), %edx
callq 0xc14d0
movl %eax, %ecx
movl -0xac(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x70(%rbp)
movq -0x48(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0xa8(%rbp)
movl -0x38(%rbp), %edi
movq -0x48(%rbp), %rax
movl 0x20(%rax), %esi
movq -0x48(%rbp), %rax
subl 0x1c(%rax), %esi
movq -0x48(%rbp), %rax
movl 0x4(%rax), %edx
movq -0x48(%rbp), %rax
subl (%rax), %edx
callq 0xc14d0
movl %eax, %ecx
movl -0xa8(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x6c(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x30(%rbp), %eax
subl -0x4(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x8(%rbp), %eax
subl -0x34(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x4c(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0xf87e9
movl -0xc(%rbp), %eax
movl %eax, -0xb4(%rbp)
movl -0x38(%rbp), %edi
movl -0x8(%rbp), %esi
subl -0x4(%rbp), %esi
movl -0x10(%rbp), %edx
subl -0xc(%rbp), %edx
callq 0xc14d0
movl %eax, %ecx
movl -0xb4(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x5c(%rbp)
movl -0x10(%rbp), %eax
movl %eax, -0xb0(%rbp)
movl -0x3c(%rbp), %edi
movl -0x8(%rbp), %esi
subl -0x4(%rbp), %esi
movl -0x10(%rbp), %edx
subl -0xc(%rbp), %edx
callq 0xc14d0
movl %eax, %ecx
movl -0xb0(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x58(%rbp)
jmp 0xf883d
movl -0xc(%rbp), %eax
movl %eax, -0xbc(%rbp)
movl -0x3c(%rbp), %edi
movl -0x8(%rbp), %esi
subl -0x4(%rbp), %esi
movl -0x10(%rbp), %edx
subl -0xc(%rbp), %edx
callq 0xc14d0
movl %eax, %ecx
movl -0xbc(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x5c(%rbp)
movl -0x10(%rbp), %eax
movl %eax, -0xb8(%rbp)
movl -0x38(%rbp), %edi
movl -0x8(%rbp), %esi
subl -0x4(%rbp), %esi
movl -0x10(%rbp), %edx
subl -0xc(%rbp), %edx
callq 0xc14d0
movl %eax, %ecx
movl -0xb8(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x58(%rbp)
jmp 0xf883f
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x20(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0xf88ad
movq -0x20(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0xf886f
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0xc8(%rbp)
jmp 0xf887d
movl $0x2, %eax
movq %rax, -0xc8(%rbp)
jmp 0xf887d
movq -0xc8(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x20(%rbp), %rax
imulq $0x28, 0x8(%rax), %rsi
callq 0x2360
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x20(%rbp), %rcx
movq (%rcx), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, (%rcx)
imulq $0x28, %rax, %rax
addq %rax, %rdi
leaq -0x70(%rbp), %rsi
movl $0x28, %edx
callq 0x2180
jmp 0xf88dd
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xf8438
addq $0xd0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)