// File: /workspace/github_cpp_makefile_star2_O1/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, %r15
movl $0x1, %edi
movl $0x30, %esi
callq 0x2120
movq %rax, %rbx
movq %r14, 0x8(%rax)
movq %r15, (%rax)
movl 0x14(%r14), %ebp
andl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
leaq 0x1(%rbp), %r12
movq %r12, 0x20(%rax)
movl $0x4, %esi
movq %r12, %rdi
callq 0x2120
movq %rax, %r14
movq %rax, 0x10(%rbx)
movq $0x0, 0x28(%rbx)
movq (%r15), %rax
testq %rax, %rax
je 0xd8cc1
movq 0x10(%r15), %rdx
movq 0x28(%rbx), %rcx
xorl %esi, %esi
leaq (%rsi,%rsi,4), %r8
movl 0x10(%rdx,%r8,8), %edi
testq %rdi, %rdi
je 0xd8cb2
leaq (%rdx,%r8,8), %r8
cmpl $0x0, 0x10(%r8)
je 0xd8cb2
movq 0x18(%r8), %r9
xorl %r10d, %r10d
movq (%r9,%r10,8), %r11
shrq $0x21, %r11
incl (%r14,%r11,4)
incq %r10
movl 0x10(%r8), %r11d
cmpq %r11, %r10
jb 0xd8c9a
addq %rdi, %rcx
incq %rsi
cmpq %rax, %rsi
jne 0xd8c7a
movq %rcx, 0x28(%rbx)
xorl %eax, %eax
xorl %ecx, %ecx
movl (%r14,%rcx,4), %edx
movl %eax, (%r14,%rcx,4)
addq %rdx, %rax
incq %rcx
cmpq %rcx, %r12
jne 0xd8cc5
movq 0x28(%rbx), %r13
shlq $0x3, %r13
movq %r13, %rdi
callq 0x2280
movq %rax, %r12
movq %rax, 0x18(%rbx)
movq %rax, %rdi
movl $0xff, %esi
movq %r13, %rdx
callq 0x20e0
testl %ebp, %ebp
je 0xd8d29
xorl %eax, %eax
movl (%r14,%rax,4), %ecx
movl 0x4(%r14,%rax,4), %edx
cmpl %ecx, %edx
je 0xd8d21
subl %ecx, %edx
leaq (%r12,%rcx,8), %rcx
movq $0x0, -0x8(%rcx,%rdx,8)
incq %rax
cmpq %rax, %rbp
jne 0xd8d05
movq (%r15), %rax
testq %rax, %rax
je 0xd8dae
movq 0x10(%r15), %rcx
xorl %edx, %edx
leaq (%rdx,%rdx,4), %rdi
movl 0x10(%rcx,%rdi,8), %esi
testq %rsi, %rsi
je 0xd8da6
leaq (%rcx,%rdi,8), %rdi
movq 0x18(%rdi), %rdi
movq %rdx, %r8
shlq $0x20, %r8
xorl %r9d, %r9d
movq (%rdi,%r9,8), %r10
shrq $0x21, %r10
movl (%r14,%r10,4), %r11d
movl 0x4(%r14,%r10,4), %r10d
subl %r11d, %r10d
je 0xd8d9e
leaq (%r12,%r11,8), %r11
leaq -0x1(%r10), %r13
movq -0x8(%r11,%r10,8), %r15
cmpq %r13, %r15
jne 0xd8d8b
movq %r9, %r15
orq %r8, %r15
movq %r15, -0x8(%r11,%r10,8)
jmp 0xd8d9e
movq %r9, %r13
orq %r8, %r13
leaq 0x1(%r15), %rbp
movq %rbp, -0x8(%r11,%r10,8)
movq %r13, (%r11,%r15,8)
incq %r9
cmpq %r9, %rsi
jne 0xd8d56
incq %rdx
cmpq %rax, %rdx
jne 0xd8d37
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq