// File: 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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movl $0x1, %edi
movl $0x30, %esi
callq 0x2140
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
addl $0x1, %eax
movslq %eax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rdi
movl $0x4, %esi
callq 0x2140
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rax
movq $0x0, 0x28(%rax)
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x1253a1
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x20(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, %ecx
movq -0x18(%rbp), %rax
addq 0x28(%rax), %rcx
movq %rcx, 0x28(%rax)
movq -0x50(%rbp), %rax
cmpl $0x0, 0x10(%rax)
jne 0x125343
jmp 0x125390
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x50(%rbp), %rcx
movl 0x10(%rcx), %ecx
cmpq %rcx, %rax
jae 0x12538e
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x50(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq -0x38(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x21, %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x12534b
jmp 0x125390
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x1252fd
movq $0x0, -0x30(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jae 0x125401
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x20(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq %rax, -0x28(%rbp)
movq -0x30(%rbp), %rax
movl %eax, %edx
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x20(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x28(%rbp), %rax
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x1253b1
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rdi
shlq $0x3, %rdi
callq 0x2270
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rdx
shlq $0x3, %rdx
movl $0xff, %esi
callq 0x2100
movq $0x1, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jae 0x1254cd
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x20(%rbp), %rdx
subq $0x1, %rdx
movl (%rcx,%rdx,4), %ecx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x20(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x18(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x20(%rbp), %rdx
subq $0x1, %rdx
subl (%rcx,%rdx,4), %eax
movl %eax, %eax
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x1254ba
movq -0x40(%rbp), %rax
movq -0x48(%rbp), %rcx
subq $0x1, %rcx
movq $0x0, (%rax,%rcx,8)
jmp 0x1254bc
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x125443
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x125635
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x20(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpl $0x0, 0x10(%rax)
jne 0x125509
jmp 0x125624
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x50(%rbp), %rcx
movl 0x10(%rcx), %ecx
cmpq %rcx, %rax
jae 0x125622
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x50(%rbp), %rdx
movq 0x18(%rdx), %rdx
movq -0x38(%rbp), %rsi
movq (%rdx,%rsi,8), %rdx
shrq $0x21, %rdx
movl (%rcx,%rdx,4), %ecx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x50(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq -0x38(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x21, %rcx
movl 0x4(%rax,%rcx,4), %eax
movq -0x18(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x50(%rbp), %rdx
movq 0x18(%rdx), %rdx
movq -0x38(%rbp), %rsi
movq (%rdx,%rsi,8), %rdx
shrq $0x21, %rdx
subl (%rcx,%rdx,4), %eax
movl %eax, %eax
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x12560f
movq -0x40(%rbp), %rax
movq -0x48(%rbp), %rcx
subq $0x1, %rcx
movq (%rax,%rcx,8), %rax
movq -0x48(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jne 0x1255de
movq -0x20(%rbp), %rdx
shlq $0x20, %rdx
orq -0x38(%rbp), %rdx
movq -0x40(%rbp), %rax
movq -0x48(%rbp), %rcx
subq $0x1, %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x12560d
movq -0x20(%rbp), %rdx
shlq $0x20, %rdx
orq -0x38(%rbp), %rdx
movq -0x40(%rbp), %rax
movq -0x40(%rbp), %rsi
movq -0x48(%rbp), %rdi
subq $0x1, %rdi
movq (%rsi,%rdi,8), %rcx
movq %rcx, %r8
addq $0x1, %r8
movq %r8, (%rsi,%rdi,8)
movq %rdx, (%rax,%rcx,8)
jmp 0x12560f
jmp 0x125611
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x125511
jmp 0x125624
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x1254d5
movq -0x18(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nop