// File: /workspace/github_cpp_makefile_star2_O3/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, %r14
movq %rdi, %r13
movl $0x1, %edi
movl $0x30, %esi
callq 0x2120
movq %rax, %rbx
movq %r14, 0x8(%rax)
movq %r13, (%rax)
movl 0x14(%r14), %r15d
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
leaq 0x1(%r15), %r12
movq %r12, 0x20(%rax)
movl $0x4, %esi
movq %r12, %rdi
callq 0x2120
movq %rax, %r14
movq %rax, 0x10(%rbx)
movq (%r13), %rbp
xorl %eax, %eax
testq %rbp, %rbp
movq %r13, (%rsp)
je 0xda16c
movq 0x10(%r13), %rcx
xorl %r13d, %r13d
xorl %edx, %edx
leaq (%rdx,%rdx,4), %rdi
movl 0x10(%rcx,%rdi,8), %esi
testq %rsi, %rsi
je 0xda157
leaq (%rcx,%rdi,8), %rdi
movq 0x18(%rdi), %r8
xorl %r9d, %r9d
movq (%r8,%r9,8), %r10
shrq $0x21, %r10
incl (%r14,%r10,4)
incq %r9
movl 0x10(%rdi), %r10d
cmpq %r10, %r9
jb 0xda13f
addq %rsi, %r13
incq %rdx
cmpq %rbp, %rdx
jne 0xda127
movq %r13, 0x28(%rbx)
shlq $0x3, %r13
jmp 0xda16f
xorl %r13d, %r13d
xorl %ecx, %ecx
movl (%r14,%rcx,4), %edx
addl %eax, %edx
movl %eax, (%r14,%rcx,4)
incq %rcx
movl %edx, %eax
cmpq %rcx, %r12
jne 0xda171
movq %r13, %rdi
callq 0x2280
movq %rax, %r12
movq %rax, 0x18(%rbx)
movq %rax, %rdi
movl $0xff, %esi
movq %r13, %rdx
callq 0x20e0
testl %r15d, %r15d
movq (%rsp), %rsi
je 0xda1d3
xorl %eax, %eax
movl (%r14,%rax,4), %ecx
movl 0x4(%r14,%rax,4), %edx
cmpl %ecx, %edx
je 0xda1cb
subl %ecx, %edx
leaq (%r12,%rcx,8), %rcx
movq $0x0, -0x8(%rcx,%rdx,8)
incq %rax
cmpq %rax, %r15
jne 0xda1af
testq %rbp, %rbp
je 0xda24e
movq 0x10(%rsi), %rax
xorl %ecx, %ecx
leaq (%rcx,%rcx,4), %rsi
movl 0x10(%rax,%rsi,8), %edx
testq %rdx, %rdx
je 0xda246
leaq (%rax,%rsi,8), %rsi
movq 0x18(%rsi), %rsi
movq %rcx, %rdi
shlq $0x20, %rdi
xorl %r8d, %r8d
movq (%rsi,%r8,8), %r10
shrq $0x21, %r10
movl (%r14,%r10,4), %r9d
movl 0x4(%r14,%r10,4), %r10d
subl %r9d, %r10d
je 0xda23e
leaq (%r12,%r9,8), %r11
leaq (%r11,%r10,8), %r9
addq $-0x8, %r9
decq %r10
movq (%r9), %r15
cmpq %r10, %r15
je 0xda235
leaq 0x1(%r15), %r10
movq %r10, (%r9)
leaq (%r11,%r15,8), %r9
movq %r8, %r10
orq %rdi, %r10
movq %r10, (%r9)
incq %r8
cmpq %r8, %rdx
jne 0xda1fd
incq %rcx
cmpq %rbp, %rcx
jne 0xda1de
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq