// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Overlaps.cpp
// Function: gen_dedup_idx_t(ma_ug_t*, asg_t*)
dedup_idx_t *gen_dedup_idx_t(ma_ug_t *ug, asg_t *rg)
{
    // fprintf(stderr, "[M::%s] Start\n", __func__);
    dedup_idx_t *p = NULL; CALLOC(p, 1);
    p->rg = rg; p->ug = ug; p->ridx_n = rg->n_seq + 1;
    uint64_t k, m, l, z, *a, a_n; ma_utg_t *u;

    CALLOC(p->ridx, p->ridx_n); 
    for (k = p->ra_n = 0; k < ug->u.n; k++) {
        u = &(ug->u.a[k]); p->ra_n += u->n; 
        if(!(u->n)) continue;
        for (z = 0; z < u->n; z++) p->ridx[u->a[z]>>33]++;
    }
    for (k = l = 0; k < p->ridx_n; k++) {
		m = p->ridx[k]; p->ridx[k] = l; l += m;
	}


    MALLOC(p->ra, p->ra_n); memset(p->ra, -1, sizeof((*(p->ra)))*p->ra_n);
    for (k = 1; k < p->ridx_n; k++) {
		a = p->ra + p->ridx[k-1];
		a_n = p->ridx[k] - p->ridx[k-1];
		if(a_n) a[a_n-1] = 0;
	}

    for (k = 0; k < ug->u.n; k++) {
        u = &(ug->u.a[k]); 
        if(!(u->n)) continue;
        for (z = 0; z < u->n; z++) {
            a = p->ra + p->ridx[u->a[z]>>33];
            a_n = p->ridx[(u->a[z]>>33)+1] - p->ridx[u->a[z]>>33];
            if(a_n) {
				if(a[a_n-1] == a_n-1) a[a_n-1] = (k<<32)|z;
				else a[a[a_n-1]++] = (k<<32)|z;
			}
        }
    }
    // fprintf(stderr, "[M::%s] End\n", __func__);
    return p;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r15
movq %rdi, %rbx
pushq $0x1
popq %rdi
pushq $0x30
popq %rsi
callq 0x2120
movq %rax, %r13
movq %r15, 0x8(%rax)
movq %rbx, (%rax)
movl 0x14(%r15), %r14d
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
leaq 0x1(%r14), %r12
movq %r12, 0x20(%rax)
pushq $0x4
popq %rsi
movq %r12, %rdi
callq 0x2120
movq %rax, %r15
movq %r13, (%rsp)
movq %rax, 0x10(%r13)
movq (%rbx), %rbp
xorl %r13d, %r13d
xorl %eax, %eax
movq (%rsp), %rdi
cmpq %rbp, %rax
je 0x9cdd0
movq 0x10(%rbx), %rcx
imulq $0x28, %rax, %rsi
movl 0x10(%rcx,%rsi), %edx
addq %rdx, %r13
movq %r13, 0x28(%rdi)
testq %rdx, %rdx
je 0x9cdcb
addq %rsi, %rcx
xorl %esi, %esi
movl %edx, %edx
cmpq %rdx, %rsi
jae 0x9cdcb
movq 0x18(%rcx), %rdx
movq (%rdx,%rsi,8), %rdx
shrq $0x21, %rdx
incl (%r15,%rdx,4)
incq %rsi
movl 0x10(%rcx), %edx
jmp 0x9cdac
incq %rax
jmp 0x9cd8a
xorl %eax, %eax
xorl %ecx, %ecx
cmpq %rax, %r12
je 0x9cdea
movl (%r15,%rax,4), %edx
addl %ecx, %edx
movl %ecx, (%r15,%rax,4)
incq %rax
movl %edx, %ecx
jmp 0x9cdd4
shlq $0x3, %r13
movq %r13, %rdi
callq 0x2280
movq %rax, %r12
movq (%rsp), %rax
movq %r12, 0x18(%rax)
movq %r12, %rdi
movl $0xff, %esi
movq %r13, %rdx
callq 0x20e0
xorl %eax, %eax
cmpq %rax, %r14
je 0x9ce36
movl (%r15,%rax,4), %ecx
movl 0x4(%r15,%rax,4), %edx
cmpl %ecx, %edx
je 0x9ce31
subl %ecx, %edx
leaq (%r12,%rcx,8), %rcx
andq $0x0, -0x8(%rcx,%rdx,8)
incq %rax
jmp 0x9ce13
xorl %eax, %eax
cmpq %rbp, %rax
je 0x9ceae
movq 0x10(%rbx), %rdx
imulq $0x28, %rax, %rsi
movl 0x10(%rdx,%rsi), %ecx
testq %rcx, %rcx
je 0x9cea9
addq %rsi, %rdx
movq 0x18(%rdx), %rdx
movq %rax, %rsi
shlq $0x20, %rsi
xorl %edi, %edi
cmpq %rdi, %rcx
je 0x9cea9
movq (%rdx,%rdi,8), %r9
shrq $0x21, %r9
movl (%r15,%r9,4), %r8d
movl 0x4(%r15,%r9,4), %r9d
subl %r8d, %r9d
je 0x9cea4
leaq (%r12,%r8,8), %r10
leaq (%r10,%r9,8), %r8
addq $-0x8, %r8
decq %r9
movq (%r8), %r11
cmpq %r9, %r11
je 0x9ce9b
leaq 0x1(%r11), %r9
movq %r9, (%r8)
leaq (%r10,%r11,8), %r8
movq %rdi, %r9
orq %rsi, %r9
movq %r9, (%r8)
incq %rdi
jmp 0x9ce5e
incq %rax
jmp 0x9ce38
movq (%rsp), %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq