// File: chhylp123[P]hifiasm/Overlaps.cpp
// Function: clean_u_trans_t_idx_adv(kv_u_trans_t*, ma_ug_t*, asg_t*)
void clean_u_trans_t_idx_adv(kv_u_trans_t *ta, ma_ug_t *ug, asg_t *read_g)
{
    u_trans_clean_t sl; uint64_t k, i, l, occ; ha_mzl_t *tz;
    ha_mzl_v srt_a; kv_u_trans_t *bl; u_trans_t *z;
    memset(&sl, 0, sizeof(sl)); kv_init(srt_a);
    
    kt_u_trans_t_idx(ta, ug->g->n_seq);
    sl.n_thread = asm_opt.thread_num; sl.ug = ug; sl.rg = read_g; sl.ta = ta;
    CALLOC(sl.res, sl.n_thread); 
    sl.ov_cutoff = 3; sl.small_ov_rate = 0.8;
    // dbg_prt_utg_trans(ta, ug, "pre");
    kt_for(sl.n_thread, worker_for_trans_clean, &sl, sl.ta->idx.n);

    for (i = srt_a.n = occ = 0; i < sl.n_thread; i++) {
		bl = &(sl.res[i]); 
		if(!(bl->n)) continue;
		for (k = 1, l = 0; k <= bl->n; k++) {
			if(k == bl->n || bl->a[k].qn != bl->a[l].qn) {
				if(k > l) {
					kv_pushp(ha_mzl_t, srt_a, &tz);
					tz->x = bl->a[l].qn; tz->x <<= 32; tz->x |= i;
					tz->rid = l>>32; tz->pos = (uint32_t)l;
					occ += (k - l);
				}
				l = k;
			}
		}
	}
    // fprintf(stderr, "[M::%s::] occ::%lu \n", __func__, occ);
    assert(srt_a.n <= sl.ug->u.n); 
	radix_sort_ha_mzl_t_srt1(srt_a.a, srt_a.a + srt_a.n);
    occ <<= 1; ta->n = 0; kv_resize(u_trans_t, *ta, occ); 
    for (i = 0; i < srt_a.n; i++) {
		tz = &(srt_a.a[i]);
		bl = &(sl.res[(uint32_t)(tz->x)]);
		k = tz->rid; k <<= 32; k += tz->pos;
		assert(bl->a[k].qn == (tz->x>>32));
		for (; (k < bl->n) && (bl->a[k].qn == (tz->x>>32)); k++) {
			if(bl->a[k].qn == bl->a[k].tn) continue;
			kv_pushp(u_trans_t, *ta, &z); 
            (*z) = bl->a[k]; if(z->f == RC_3) z->f = RC_2;

            kv_pushp(u_trans_t, *ta, &z); 
            (*z) = bl->a[k]; if(z->f == RC_3) z->f = RC_2;
            z->qn = bl->a[k].tn; z->qs = bl->a[k].ts; z->qe = bl->a[k].te;
            z->tn = bl->a[k].qn; z->ts = bl->a[k].qs; z->te = bl->a[k].qe;
		}
	}

    for (k = 0; k < sl.n_thread; k++) free(sl.res[k].a); 
    free(sl.res); kv_destroy(srt_a);
    kt_u_trans_t_idx(ta, ug->g->n_seq);
    // dbg_prt_utg_trans(ta, ug, "after");
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
leaq -0x70(%rbp), %rdi
xorl %esi, %esi
movl $0x58, %edx
callq 0x2100
movl $0x0, -0xa4(%rbp)
movl $0x0, -0xa8(%rbp)
movq $0x0, -0xa0(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movl 0x14(%rax), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
callq 0x104540
leaq 0x2c0b31(%rip), %rax    # 0x3c47f8
movslq 0x7c(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rdi
movl $0x30, %esi
callq 0x2140
movq %rax, -0x60(%rbp)
movq $0x3, -0x48(%rbp)
movsd 0x27e527(%rip), %xmm0   # 0x382230
movsd %xmm0, -0x40(%rbp)
movq -0x50(%rbp), %rax
movl %eax, %edi
movq -0x58(%rbp), %rax
movq 0x18(%rax), %rcx
leaq 0x9fd(%rip), %rsi       # 0x104720
leaq -0x70(%rbp), %rdx
callq 0x16d710
movq $0x0, -0x90(%rbp)
movl $0x0, -0xa8(%rbp)
movq $0x0, -0x80(%rbp)
movq -0x80(%rbp), %rax
cmpq -0x50(%rbp), %rax
jae 0x103f77
movq -0x60(%rbp), %rax
imulq $0x30, -0x80(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x103d7c
jmp 0x103f66
movq $0x1, -0x78(%rbp)
movq $0x0, -0x88(%rbp)
movq -0x78(%rbp), %rax
movq -0xb0(%rbp), %rcx
cmpq (%rcx), %rax
ja 0x103f64
movq -0x78(%rbp), %rax
movq -0xb0(%rbp), %rcx
cmpq (%rcx), %rax
je 0x103de8
movq -0xb0(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x78(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movq -0xb0(%rbp), %rcx
movq 0x10(%rcx), %rcx
imulq $0x30, -0x88(%rbp), %rdx
addq %rdx, %rcx
cmpl 0x8(%rcx), %eax
je 0x103f51
movq -0x78(%rbp), %rax
cmpq -0x88(%rbp), %rax
jbe 0x103f46
jmp 0x103dfb
movl -0xa8(%rbp), %eax
cmpl -0xa4(%rbp), %eax
jne 0x103e58
cmpl $0x0, -0xa4(%rbp)
je 0x103e22
movl -0xa4(%rbp), %eax
shll %eax
movl %eax, -0xbc(%rbp)
jmp 0x103e2f
movl $0x2, %eax
movl %eax, -0xbc(%rbp)
jmp 0x103e2f
movl -0xbc(%rbp), %eax
movl %eax, -0xa4(%rbp)
movq -0xa0(%rbp), %rdi
movl -0xa4(%rbp), %eax
imulq $0x18, %rax, %rsi
callq 0x2360
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
movl -0xa8(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0xa8(%rbp)
movl %ecx, %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x98(%rbp)
movq -0xb0(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x88(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, %ecx
movq -0x98(%rbp), %rax
movq %rcx, (%rax)
movq -0x98(%rbp), %rax
movq (%rax), %rcx
shlq $0x20, %rcx
movq %rcx, (%rax)
movq -0x80(%rbp), %rcx
movq -0x98(%rbp), %rax
orq (%rax), %rcx
movq %rcx, (%rax)
movq -0x88(%rbp), %rdx
shrq $0x20, %rdx
movq -0x98(%rbp), %rax
movq 0x8(%rax), %rcx
andq $0x7fffffff, %rdx       # imm = 0x7FFFFFFF
andq $-0x80000000, %rcx      # imm = 0x80000000
orq %rdx, %rcx
movq %rcx, 0x8(%rax)
movq -0x88(%rbp), %rax
movl %eax, %eax
movl %eax, %edx
movq -0x98(%rbp), %rax
movq 0x8(%rax), %rcx
movabsq $0xffffffff, %rsi       # imm = 0xFFFFFFFF
andq %rsi, %rdx
shlq $0x20, %rdx
movabsq $0xffffffff, %rsi       # imm = 0xFFFFFFFF
andq %rsi, %rcx
orq %rdx, %rcx
movq %rcx, 0x8(%rax)
movq -0x78(%rbp), %rax
subq -0x88(%rbp), %rax
addq -0x90(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x88(%rbp)
jmp 0x103f53
movq -0x78(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x78(%rbp)
jmp 0x103d8f
jmp 0x103f66
movq -0x80(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
jmp 0x103d49
movl -0xa8(%rbp), %eax
movq -0x70(%rbp), %rcx
cmpq (%rcx), %rax
ja 0x103f88
jmp 0x103fa7
leaq 0x2837ae(%rip), %rdi    # 0x38773d
leaq 0x282927(%rip), %rsi    # 0x3868bd
movl $0x3c35, %edx           # imm = 0x3C35
leaq 0x2837b1(%rip), %rcx    # 0x387753
callq 0x2130
movq -0xa0(%rbp), %rdi
movq -0xa0(%rbp), %rsi
movl -0xa8(%rbp), %eax
imulq $0x18, %rax, %rax
addq %rax, %rsi
callq 0xcaeb0
movq -0x90(%rbp), %rax
shlq %rax
movq %rax, -0x90(%rbp)
movq -0x8(%rbp), %rax
movq $0x0, (%rax)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
cmpq -0x90(%rbp), %rax
jae 0x1040bf
movq -0x90(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rcx
shrq %rcx
movq -0x8(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rcx
shrq $0x2, %rcx
movq -0x8(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rcx
shrq $0x4, %rcx
movq -0x8(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rcx
shrq $0x8, %rcx
movq -0x8(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rcx
shrq $0x10, %rcx
movq -0x8(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x8(%rbp), %rax
imulq $0x30, 0x8(%rax), %rsi
callq 0x2360
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x1040c1
movq $0x0, -0x80(%rbp)
movq -0x80(%rbp), %rax
movl -0xa8(%rbp), %ecx
cmpq %rcx, %rax
jae 0x1044c4
movq -0xa0(%rbp), %rax
imulq $0x18, -0x80(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x98(%rbp)
movq -0x60(%rbp), %rax
movq -0x98(%rbp), %rcx
movq (%rcx), %rcx
movl %ecx, %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0xb0(%rbp)
movq -0x98(%rbp), %rax
movq 0x8(%rax), %rax
andq $0x7fffffff, %rax       # imm = 0x7FFFFFFF
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
shlq $0x20, %rax
movq %rax, -0x78(%rbp)
movq -0x98(%rbp), %rax
movq 0x8(%rax), %rax
shrq $0x20, %rax
addq -0x78(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0xb0(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x78(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movq -0x98(%rbp), %rcx
movq (%rcx), %rcx
shrq $0x20, %rcx
cmpq %rcx, %rax
jne 0x104173
jmp 0x104192
leaq 0x28361a(%rip), %rdi    # 0x387794
leaq 0x28273c(%rip), %rsi    # 0x3868bd
movl $0x3c3c, %edx           # imm = 0x3C3C
leaq 0x2835c6(%rip), %rcx    # 0x387753
callq 0x2130
jmp 0x104194
movq -0x78(%rbp), %rcx
movq -0xb0(%rbp), %rdx
xorl %eax, %eax
cmpq (%rdx), %rcx
movb %al, -0xbd(%rbp)
jae 0x1041dc
movq -0xb0(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x78(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movq -0x98(%rbp), %rcx
movq (%rcx), %rcx
shrq $0x20, %rcx
cmpq %rcx, %rax
sete %al
movb %al, -0xbd(%rbp)
movb -0xbd(%rbp), %al
testb $0x1, %al
jne 0x1041eb
jmp 0x1044b1
movq -0xb0(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x78(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movq -0xb0(%rbp), %rcx
movq 0x10(%rcx), %rcx
imulq $0x30, -0x78(%rbp), %rdx
addq %rdx, %rcx
cmpl 0x14(%rcx), %eax
jne 0x10421e
jmp 0x1044a0
jmp 0x104220
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x10428e
movq -0x8(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x104250
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0xc8(%rbp)
jmp 0x10425e
movl $0x2, %eax
movq %rax, -0xc8(%rbp)
jmp 0x10425e
movq -0xc8(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x8(%rbp), %rax
imulq $0x30, 0x8(%rax), %rsi
callq 0x2360
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rbp), %rdx
movq (%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, (%rdx)
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0xb8(%rbp)
movq -0xb0(%rbp), %rax
movq 0x10(%rax), %rsi
imulq $0x30, -0x78(%rbp), %rax
addq %rax, %rsi
movq -0xb8(%rbp), %rdi
movl $0x30, %edx
callq 0x2180
movq -0xb8(%rbp), %rax
movb 0x28(%rax), %al
andb $0x3f, %al
movzbl %al, %eax
cmpl $0x3, %eax
jne 0x104300
movq -0xb8(%rbp), %rax
movb 0x28(%rax), %cl
andb $-0x40, %cl
orb $0x2, %cl
movb %cl, 0x28(%rax)
jmp 0x104302
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x104370
movq -0x8(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x104332
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0xd0(%rbp)
jmp 0x104340
movl $0x2, %eax
movq %rax, -0xd0(%rbp)
jmp 0x104340
movq -0xd0(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x8(%rbp), %rax
imulq $0x30, 0x8(%rax), %rsi
callq 0x2360
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rbp), %rdx
movq (%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, (%rdx)
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0xb8(%rbp)
movq -0xb0(%rbp), %rax
movq 0x10(%rax), %rsi
imulq $0x30, -0x78(%rbp), %rax
addq %rax, %rsi
movq -0xb8(%rbp), %rdi
movl $0x30, %edx
callq 0x2180
movq -0xb8(%rbp), %rax
movb 0x28(%rax), %al
andb $0x3f, %al
movzbl %al, %eax
cmpl $0x3, %eax
jne 0x1043e2
movq -0xb8(%rbp), %rax
movb 0x28(%rax), %cl
andb $-0x40, %cl
orb $0x2, %cl
movb %cl, 0x28(%rax)
movq -0xb0(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x78(%rbp), %rcx
addq %rcx, %rax
movl 0x14(%rax), %ecx
movq -0xb8(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0xb0(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x78(%rbp), %rcx
addq %rcx, %rax
movl 0xc(%rax), %ecx
movq -0xb8(%rbp), %rax
movl %ecx, (%rax)
movq -0xb0(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x78(%rbp), %rcx
addq %rcx, %rax
movl 0x10(%rax), %ecx
movq -0xb8(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0xb0(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x78(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %ecx
movq -0xb8(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0xb0(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x78(%rbp), %rcx
addq %rcx, %rax
movl (%rax), %ecx
movq -0xb8(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0xb0(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x78(%rbp), %rcx
addq %rcx, %rax
movl 0x4(%rax), %ecx
movq -0xb8(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x78(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x78(%rbp)
jmp 0x104194
jmp 0x1044b3
movq -0x80(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
jmp 0x1040c9
movq $0x0, -0x78(%rbp)
movq -0x78(%rbp), %rax
cmpq -0x50(%rbp), %rax
jae 0x1044f9
movq -0x60(%rbp), %rax
imulq $0x30, -0x78(%rbp), %rcx
addq %rcx, %rax
movq 0x10(%rax), %rdi
callq 0x2210
movq -0x78(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x78(%rbp)
jmp 0x1044cc
movq -0x60(%rbp), %rdi
callq 0x2210
movq -0xa0(%rbp), %rdi
callq 0x2210
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movl 0x14(%rax), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
callq 0x104540
addq $0xd0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)