// File: /workspace/github_cpp_makefile_star2_O3/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 $0x48, %rsp
movq %r8, 0x40(%rsp)
movq %rsi, %rbx
testq %rdx, %rdx
sete %al
testq %rcx, %rcx
sete %sil
orb %al, %sil
jne 0x742d5
movq %rdi, %r15
movq 0x8(%rbx), %r12
leaq (%rcx,%rdx), %rax
movq %r12, %r13
movq %rax, 0x38(%rsp)
subq %rax, %r13
movl %r12d, %r14d
subl %ecx, %r14d
movq %r13, %rbp
addq %rdx, %r13
leal (%r12,%r13), %eax
cmpq %rax, 0x10(%rbx)
jae 0x73d67
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 (%rbx), %rdi
leaq (%rax,%rax,8), %rax
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax), %rsi
incq %rsi
callq 0x2370
movq %rax, (%rbx)
cmpl %r13d, %ebp
setae %al
cmpl %r12d, %r14d
setae %cl
movb $0x1, %dl
orb %al, %cl
movq %r12, 0x10(%rsp)
jne 0x74136
movq %r13, 0x28(%rsp)
movl %r13d, %eax
movq %rax, 0x30(%rsp)
movl $0x0, 0x20(%rsp)
movl %r14d, %esi
movq %rbp, %rdi
movq (%rbx), %rax
movq %rdi, 0x18(%rsp)
movl %edi, %r12d
leaq (%r12,%r12,8), %rcx
leaq (%rcx,%rcx,2), %r14
leaq (%r14,%r12), %r13
movl 0xc(%rax,%r13), %edi
movl %esi, 0xc(%rsp)
movl %esi, %ecx
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rbp
addq %rcx, %rbp
movl 0xc(%rax,%rbp), %ecx
movl %edi, 0x24(%rsp)
cmpl %ecx, %edi
jae 0x73e4d
movq 0x8(%rbx), %rcx
cmpq 0x10(%rbx), %rcx
jne 0x73e0e
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rdx
movq %rdx, 0x10(%rbx)
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rsi
addq %rdx, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, (%rbx)
movq 0x8(%rbx), %rcx
movq 0x10(%rsp), %rbp
addq %r12, %r14
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), %rdi
incl %edi
movl 0xc(%rsp), %esi
jmp 0x7411e
jbe 0x73ec1
movq 0x8(%rbx), %rcx
cmpq 0x10(%rbx), %rcx
jne 0x73e87
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rdx
movq %rdx, 0x10(%rbx)
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rsi
addq %rdx, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, (%rbx)
movq 0x8(%rbx), %rcx
movl 0xc(%rsp), %esi
movq 0x18(%rsp), %rdi
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%rbx)
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
movups (%rax,%rbp), %xmm0
movups 0xc(%rax,%rbp), %xmm1
movups %xmm1, 0xc(%rax,%rdx)
movups %xmm0, (%rax,%rdx)
incl %esi
movq 0x10(%rsp), %rbp
jmp 0x7411e
movq 0x18(%rsp), %rax
movl %eax, %r14d
cmpl 0x28(%rsp), %eax
movq 0x10(%rsp), %rbp
jae 0x73f63
movq 0x30(%rsp), %r14
movq (%rbx), %rax
movl 0x24(%rsp), %ecx
cmpl %ecx, 0xc(%rax,%r13)
jne 0x73f60
movq 0x8(%rbx), %rcx
cmpq 0x10(%rbx), %rcx
jne 0x73f23
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rdx
movq %rdx, 0x10(%rbx)
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rsi
addq %rdx, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, (%rbx)
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 %r12
addq $0x1c, %r13
cmpq %r12, %r14
jne 0x73edd
movq 0x28(%rsp), %rax
movl %eax, %r14d
jmp 0x73f63
movl %r12d, %r14d
movl 0xc(%rsp), %esi
cmpl %ebp, %esi
jae 0x7411b
movq (%rbx), %rax
movl %esi, 0xc(%rsp)
movl %esi, %ecx
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %r12
addq %rcx, %r12
movl 0x24(%rsp), %ecx
cmpl %ecx, 0xc(%rax,%r12)
jne 0x7412e
movq 0x18(%rsp), %rdi
cmpl %r14d, %edi
jae 0x74093
leal 0x1(%rdi), %r13d
movq (%rbx), %rcx
movl %edi, %eax
cmpl %r14d, %r13d
jae 0x74038
movl %r13d, %edx
leaq (%rdx,%rdx,8), %rsi
leaq (%rsi,%rsi,2), %rsi
addq %rdx, %rsi
movl (%rcx,%rsi), %edx
leaq (%rax,%rax,8), %r8
leaq (%r8,%r8,2), %r8
addq %rax, %r8
cmpl (%rcx,%r8), %edx
jne 0x74038
addq %rcx, %rsi
addq %rcx, %r8
movl 0xc(%rsi), %r9d
cmpl 0xc(%r8), %r9d
jne 0x74038
movl 0x18(%rsi), %esi
movl 0x18(%r8), %r8d
movl %r8d, %r9d
xorl %esi, %r9d
js 0x74038
movl $0x3fffffff, %r9d       # imm = 0x3FFFFFFF
andq %r9, %rsi
andq %r9, %r8
leal 0x1(%r8), %r9d
cmpl %r9d, %esi
jne 0x74038
movq 0x40(%rsp), %r9
movq (%r9), %r9
leaq (%rdx,%rdx,2), %rdx
movq 0x8(%r9,%rdx,8), %r10
cmpq %r8, %r10
jbe 0x74038
cmpq %rsi, %r10
jbe 0x74038
leaq (%r9,%rdx,8), %rdx
movq (%rdx), %r9
shlq $0x5, %r8
movb 0x1c(%r9,%r8), %dl
testb $0x20, %dl
jne 0x7406e
movl %edi, %ebp
leaq (%rax,%rax,8), %rdx
leaq (%rdx,%rdx,2), %rsi
addq %rax, %rsi
addq %rcx, %rsi
movl %r13d, %edx
subl %edi, %edx
addq %r12, %rcx
movq %r15, %rdi
movsd 0x1bd60d(%rip), %xmm0   # 0x231668
callq 0x73841
movl %r13d, %edi
testq %rax, %rax
je 0x73f97
jmp 0x74097
shlq $0x5, %rsi
movb 0x1c(%r9,%rsi), %sil
andb $0x1f, %dl
andb $0x3f, %sil
xorb $0x21, %sil
orb %dl, %sil
je 0x7408a
movl %edi, %r13d
movl %r13d, %ebp
leal 0x1(%rbp), %r13d
jmp 0x7403a
movl %edi, %ebp
jmp 0x7409f
movl $0x1, 0x20(%rsp)
cmpl %r14d, %ebp
movq 0x10(%rsp), %rbp
jb 0x7410b
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
cmpq 0x10(%rbx), %rcx
jne 0x740e4
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rdx
movq %rdx, 0x10(%rbx)
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rsi
addq %rdx, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, (%rbx)
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 0xc(%rsp), %esi
incl %esi
cmpl %ebp, %esi
jne 0x73f6f
jmp 0x7413b
movl %r14d, %edi
cmpl 0x28(%rsp), %edi
jae 0x74140
cmpl %ebp, %esi
jb 0x73d9d
jmp 0x74140
movl %r14d, %edi
jmp 0x73e44
movq %rbp, %rdi
jmp 0x74150
movl %r14d, %edi
movl %ebp, %esi
movl %esi, %r14d
cmpl $0x0, 0x20(%rsp)
sete %dl
movq 0x28(%rsp), %r13
movb %dl, 0xc(%rsp)
cmpl %r13d, %edi
jae 0x741d8
movl %edi, %r15d
movl %r13d, %r12d
leaq (%r15,%r15,8), %rax
leaq (%rax,%rax,2), %r13
addq %r15, %r13
movl $0x2, %ebp
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
cmpq 0x10(%rbx), %rcx
jne 0x741a5
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
cmoveq %rbp, %rdx
movq %rdx, 0x10(%rbx)
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rsi
addq %rdx, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, (%rbx)
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 0x7416f
movq 0x10(%rsp), %rbp
cmpl %ebp, %r14d
jae 0x74266
movl %r14d, %eax
movl %ebp, %r15d
leaq (%rax,%rax,8), %rcx
leaq (%rcx,%rcx,2), %r12
addq %rax, %r12
subq %rax, %r15
movl $0x2, %r13d
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
cmpq 0x10(%rbx), %rcx
jne 0x74236
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
cmoveq %r13, %rdx
movq %rdx, 0x10(%rbx)
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rsi
addq %rdx, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, (%rbx)
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 0x74200
cmpb $0x0, 0xc(%rsp)
je 0x74275
movl %ebp, %eax
movq %rax, 0x8(%rbx)
jmp 0x742d5
movq 0x8(%rbx), %rax
movl %ebp, %edx
cmpq %rdx, %rax
jbe 0x742d5
movq %rdx, %rcx
subq 0x38(%rsp), %rcx
movq %rcx, 0x8(%rbx)
cmpl %eax, %ebp
jae 0x742d5
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 0x742a0
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq