// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Correct.cpp
// Function: dedup_src_shared1(ma_ug_t*, kv_ul_ov_t*, unsigned long, unsigned long, idx_emask_t*)
void dedup_src_shared1(ma_ug_t *ug, kv_ul_ov_t *res, uint64_t tocc, uint64_t qocc, idx_emask_t *mm)
{
    if((!tocc) || (!qocc)) return;
    uint32_t ti, qi, tn, qn, rn = res->n, id, ts, te, k, l, ff = 0;
    // qi = res->n - qocc; fi = 0; m = qi; qocc = 0;
    // while (qi < res->n && fi < flt_n) {
    //     if(res->a[qi].tn < (flt[fi]>>32)) {
    //         qi++;
    //     } else if((flt[fi]>>32) < res->a[qi].tn) {
    //         fi++;
    //     } else {///res->a[qi].tn == (flt[fi]>>32)
    //         res->a[m++] = res->a[qi]; qocc++; qi++; fi++;
    //     }
    // }
    // res->n = m;
    // if((!tocc) || (!qocc)) return;

    rn = res->n;
    ti = res->n - tocc - qocc; qi = res->n - qocc;//t first, and then q 
    tn = ti + tocc; qn = qi + qocc; kv_resize(ul_ov_t, *res, (rn+tn));///the buf size should be at least tn
    while (ti < tn && qi < qn) {
        if (res->a[ti].tn < res->a[qi].tn) {
            kv_push(ul_ov_t, *res, res->a[ti]); ti++; 
        } else if(res->a[qi].tn < res->a[ti].tn) {
            kv_push(ul_ov_t, *res, res->a[qi]); qi++; 
        } else {///ta[ti].tn == qa[qi].tn
            id = res->a[ti].tn; ts = ti;
            for (; ti < tn && res->a[ti].tn == id; ti++) {
                kv_push(ul_ov_t, *res, res->a[ti]);
            }
            te = ti;
            
            for (; qi < qn && res->a[qi].tn == id; qi++) {
                for (k = ts; k < te; k++) {
                    l = k; 
                    if(is_ul_ov_pe(res->a, te, k, (*mm))) k++;
                    if(is_cover_ul_ov_t(ug, 0.06, res->a+l, k+1-l, &(res->a[qi]))) {
                        ff = 1; break;
                    }
                }
                if(k >= te) kv_push(ul_ov_t, *res, res->a[qi]);
            }
        }
    }
    while (ti < tn) {
        kv_push(ul_ov_t, *res, res->a[ti]); ti++; 
    }
    while (qi < qn) {
        kv_push(ul_ov_t, *res, res->a[qi]); qi++; 
    }
    
    // fprintf(stderr, "[M::%s]\tff::%u\n", __func__, ff);
    if(!ff) {///nothing has been removed as duplication
        res->n = rn;
    } else if(res->n > rn) {
        l = res->n; res->n = rn - tocc - qocc;
        for (k = rn; k < l; k++) res->a[res->n++] = res->a[k];
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r8, 0x30(%rsp)
movq %rsi, %rbx
testq %rdx, %rdx
sete %al
testq %rcx, %rcx
sete %sil
orb %al, %sil
jne 0x74857
movq %rdi, %r15
movq 0x8(%rbx), %r14
leaq (%rcx,%rdx), %rax
movq %r14, %rsi
movq %rax, 0x28(%rsp)
subq %rax, %rsi
movl %r14d, %r12d
subl %ecx, %r12d
movq %rsi, %r13
addq %rdx, %r13
leal (%r14,%r13), %eax
cmpq %rax, 0x10(%rbx)
jae 0x742b1
decq %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
leaq 0x1(%rcx), %rax
movq %rax, 0x10(%rbx)
movq %rsi, %rbp
movq (%rbx), %rdi
leaq (%rax,%rax,8), %rax
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax), %rsi
incq %rsi
callq 0x2370
movq %rbp, %rsi
movq %rax, (%rbx)
cmpl %r13d, %esi
setae %al
cmpl %r14d, %r12d
setae %cl
movb $0x1, %dl
orb %al, %cl
movq %r14, 0x8(%rsp)
jne 0x746b9
movl $0x0, 0x20(%rsp)
movq %r13, 0x10(%rsp)
movq (%rbx), %rdi
movq %rsi, 0x18(%rsp)
movl %esi, %ebp
leaq (,%rbp,8), %rax
addq %rbp, %rax
leaq (%rax,%rax,2), %r14
movl %r12d, %eax
leaq (%r14,%rbp), %r12
movl 0xc(%rdi,%r12), %edx
movl %eax, 0x4(%rsp)
movl %eax, %eax
leaq (%rax,%rax,8), %rcx
leaq (%rcx,%rcx,2), %r13
addq %rax, %r13
movl 0xc(%rdi,%r13), %eax
movl %edx, 0x24(%rsp)
cmpl %eax, %edx
jae 0x74394
movq 0x10(%rbx), %rax
cmpq %rax, 0x8(%rbx)
jne 0x7434d
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x10(%rbx)
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rsi
addq %rcx, %rsi
callq 0x2370
movq %rax, (%rbx)
addq %rbp, %r14
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%rbx)
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
movups (%rax,%r14), %xmm0
movups 0xc(%rax,%r14), %xmm1
movups %xmm1, 0xc(%rax,%rdx)
movups %xmm0, (%rax,%rdx)
movq 0x18(%rsp), %rsi
incl %esi
movq 0x8(%rsp), %r14
movl 0x4(%rsp), %r12d
jmp 0x7469c
jbe 0x74411
movq 0x10(%rbx), %rax
cmpq %rax, 0x8(%rbx)
movq 0x8(%rsp), %r14
jne 0x743cc
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x10(%rbx)
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rsi
addq %rcx, %rsi
callq 0x2370
movq %rax, (%rbx)
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%rbx)
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
movups (%rax,%r13), %xmm0
movups 0xc(%rax,%r13), %xmm1
movups %xmm1, 0xc(%rax,%rdx)
movups %xmm0, (%rax,%rdx)
movl 0x4(%rsp), %r12d
incl %r12d
movq 0x10(%rsp), %r13
movq 0x18(%rsp), %rsi
jmp 0x746a1
movq 0x18(%rsp), %rax
movl %eax, %r13d
cmpl 0x10(%rsp), %eax
movq 0x8(%rsp), %r14
jae 0x744ab
movq 0x18(%rsp), %rax
movl %eax, %r13d
movq (%rbx), %rdi
movl 0x24(%rsp), %eax
cmpl %eax, 0xc(%rdi,%r12)
jne 0x744ab
movq 0x10(%rbx), %rax
cmpq %rax, 0x8(%rbx)
jne 0x7446f
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x10(%rbx)
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rsi
addq %rcx, %rsi
callq 0x2370
movq %rax, (%rbx)
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%rbx)
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
movups (%rax,%r12), %xmm0
movups 0xc(%rax,%r12), %xmm1
movups %xmm1, 0xc(%rax,%rdx)
movups %xmm0, (%rax,%rdx)
incl %r13d
addq $0x1c, %r12
cmpl 0x10(%rsp), %r13d
jb 0x74430
movl 0x4(%rsp), %r12d
cmpl %r14d, %r12d
jae 0x74699
movq 0x18(%rsp), %rdi
movq (%rbx), %rax
movl %r12d, 0x4(%rsp)
movl %r12d, %ecx
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %r12
addq %rcx, %r12
movl 0x24(%rsp), %ecx
cmpl %ecx, 0xc(%rax,%r12)
jne 0x746b1
cmpl %r13d, %edi
jae 0x7460f
leal 0x1(%rdi), %ecx
movl %edi, %eax
movl %edi, %r14d
cmpl %r13d, %ecx
jae 0x745ce
movq (%rbx), %r9
movl %ecx, %edx
leaq (%rdx,%rdx,8), %rsi
leaq (%rsi,%rsi,2), %rsi
addq %rdx, %rsi
movl (%r9,%rsi), %edx
leaq (%rax,%rax,8), %r8
leaq (%r8,%r8,2), %r10
addq %rax, %r10
movl (%r9,%r10), %r8d
movl %edi, %r14d
cmpl %r8d, %edx
jne 0x745ce
addq %r9, %rsi
addq %r9, %r10
movl 0xc(%rsi), %r9d
movl %edi, %r14d
cmpl 0xc(%r10), %r9d
jne 0x745ce
movl 0x18(%rsi), %esi
movl 0x18(%r10), %r9d
movl %r9d, %r10d
xorl %esi, %r10d
movl %edi, %r14d
js 0x745ce
movl $0x3fffffff, %r10d      # imm = 0x3FFFFFFF
andq %r10, %rsi
andq %r10, %r9
leal 0x1(%r9), %r10d
movl %edi, %r14d
cmpl %r10d, %esi
jne 0x745ce
movq 0x30(%rsp), %r10
movq (%r10), %r10
leaq (%r8,%r8,2), %r11
movl %edi, %r14d
cmpq %r9, 0x8(%r10,%r11,8)
jbe 0x745ce
leaq (%rdx,%rdx,2), %r8
movl %edi, %r14d
cmpq %rsi, 0x8(%r10,%r8,8)
jbe 0x745ce
leaq (%r10,%r11,8), %rdx
movq (%rdx), %rdx
shlq $0x5, %r9
movb 0x1c(%rdx,%r9), %dl
movl %edi, %r14d
testb $0x20, %dl
je 0x745ce
leaq (%r10,%r8,8), %r8
movq (%r8), %r8
shlq $0x5, %rsi
movb 0x1c(%r8,%rsi), %sil
andb $0x1f, %dl
andb $0x3f, %sil
xorb $0x21, %sil
orb %dl, %sil
je 0x745cb
movl %edi, %ecx
movl %ecx, %r14d
movq (%rbx), %rcx
leaq (%rax,%rax,8), %rdx
leaq (%rdx,%rdx,2), %rsi
addq %rax, %rsi
addq %rcx, %rsi
leal 0x1(%r14), %ebp
movl %ebp, %edx
subl %edi, %edx
addq %r12, %rcx
movq %r15, %rdi
movsd 0x1b0f73(%rip), %xmm0   # 0x225568
callq 0x73d3b
movl %ebp, %edi
testq %rax, %rax
je 0x744e3
movl $0x1, 0x20(%rsp)
jmp 0x74612
movl %edi, %r14d
cmpl %r13d, %r14d
movq 0x8(%rsp), %r14
movq 0x18(%rsp), %rdi
jb 0x74688
movq 0x10(%rbx), %rax
cmpq %rax, 0x8(%rbx)
jne 0x7465a
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x10(%rbx)
movq (%rbx), %rdi
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rsi
addq %rcx, %rsi
callq 0x2370
movq 0x18(%rsp), %rdi
movq %rax, (%rbx)
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%rbx)
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
movups (%rax,%r12), %xmm0
movups 0xc(%rax,%r12), %xmm1
movups %xmm1, 0xc(%rax,%rdx)
movups %xmm0, (%rax,%rdx)
movl 0x4(%rsp), %r12d
incl %r12d
cmpl %r14d, %r12d
jne 0x744be
movl %r13d, %esi
movq 0x10(%rsp), %r13
cmpl %r13d, %esi
jae 0x746be
cmpl %r14d, %r12d
jb 0x742d9
jmp 0x746be
movl %r13d, %esi
jmp 0x7438a
movl %r12d, %ebp
jmp 0x746c9
movl %r12d, %ebp
cmpl $0x0, 0x20(%rsp)
sete %dl
movb %dl, 0x4(%rsp)
cmpl %r13d, %esi
jae 0x74756
movl %esi, %r15d
movl %r13d, %r12d
leaq (%r15,%r15,8), %rax
leaq (%rax,%rax,2), %r13
addq %r15, %r13
movl $0x2, %r14d
movq 0x10(%rbx), %rax
cmpq %rax, 0x8(%rbx)
jne 0x7471c
leaq (%rax,%rax), %rcx
testq %rax, %rax
cmoveq %r14, %rcx
movq %rcx, 0x10(%rbx)
movq (%rbx), %rdi
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rsi
addq %rcx, %rsi
callq 0x2370
movq %rax, (%rbx)
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%rbx)
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
movups (%rax,%r13), %xmm0
movups 0xc(%rax,%r13), %xmm1
movups %xmm1, 0xc(%rax,%rdx)
movups %xmm0, (%rax,%rdx)
incq %r15
addq $0x1c, %r13
cmpq %r12, %r15
jb 0x746ed
cmpl 0x8(%rsp), %ebp
jae 0x747e1
movl %ebp, %eax
movl 0x8(%rsp), %r15d
leaq (%rax,%rax,8), %rcx
leaq (%rcx,%rcx,2), %r12
addq %rax, %r12
subq %rax, %r15
movl $0x2, %r14d
movq 0x10(%rbx), %rax
cmpq %rax, 0x8(%rbx)
jne 0x747aa
leaq (%rax,%rax), %rcx
testq %rax, %rax
cmoveq %r14, %rcx
movq %rcx, 0x10(%rbx)
movq (%rbx), %rdi
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rsi
addq %rcx, %rsi
callq 0x2370
movq %rax, (%rbx)
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%rbx)
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
movups (%rax,%r12), %xmm0
movups 0xc(%rax,%r12), %xmm1
movups %xmm1, 0xc(%rax,%rdx)
movups %xmm0, (%rax,%rdx)
addq $0x1c, %r12
decq %r15
jne 0x7477b
cmpb $0x0, 0x4(%rsp)
je 0x747f2
movl 0x8(%rsp), %eax
movq %rax, 0x8(%rbx)
jmp 0x74857
movq 0x8(%rbx), %rax
movq 0x8(%rsp), %rsi
movl %esi, %edx
cmpq %rdx, %rax
jbe 0x74857
movq %rdx, %rcx
subq 0x28(%rsp), %rcx
movq %rcx, 0x8(%rbx)
cmpl %eax, %esi
jae 0x74857
movl %eax, %eax
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rdx, %rcx
subq %rdx, %rax
movq (%rbx), %rdx
movq 0x8(%rbx), %rsi
leaq 0x1(%rsi), %rdi
movq %rdi, 0x8(%rbx)
leaq (%rsi,%rsi,8), %rdi
leaq (%rdi,%rdi,2), %rdi
addq %rsi, %rdi
movups (%rdx,%rcx), %xmm0
movups 0xc(%rdx,%rcx), %xmm1
movups %xmm1, 0xc(%rdx,%rdi)
movups %xmm0, (%rdx,%rdi)
addq $0x1c, %rcx
decq %rax
jne 0x74822
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq