// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/inter.cpp
// Function: worker_for_ctg_trans_order(void*, long, int)
static void worker_for_ctg_trans_order(void *data, long i, int tid)
{
	ctdat_t *c = (ctdat_t*)data; utepdat_t *s = c->s; asg64_v b;
	u_trans_t *a = NULL, *r_a = NULL, t; uint64_t n, r_n, k, z, m;

	if(c->mm == 0) {
		copy_asg_arr(b, (s->sps[tid]));
		rm_dup_aln(u_trans_a(*(c->ta), i), u_trans_n(*(c->ta), i), &b, 0.25);
		copy_asg_arr((s->sps[tid]), b); 
	} else if(c->mm == 1) {
			a = u_trans_a(*(c->ta), i); n = u_trans_n(*(c->ta), i);
			for (k = 0; k < n; k++) {
				if(a[k].tn < a[k].qn) continue;
				r_a = u_trans_a(*(c->ta), a[k].tn); r_n = u_trans_n(*(c->ta), a[k].tn);
				for(z = 0; (z < r_n) && (r_a[z].tn != a[k].qn); z++);
				assert(z < r_n);
				// if(a[k].del || r_a[z].del) {
				// 	a[k].del = r_a[z].del = 1;
				// }
				///discard too short overlaps
				if((!a[k].f) || (!r_a[z].f)) {
					if((a[k].qe - a[k].qs <= asm_opt.self_scaf_min) || (a[k].te - a[k].ts <= asm_opt.self_scaf_min)) {
						a[k].del = r_a[z].del = 1;
					} else if((r_a[z].qe - r_a[z].qs <= asm_opt.self_scaf_min) || (r_a[z].te - r_a[z].ts <= asm_opt.self_scaf_min)) {
						a[k].del = r_a[z].del = 1;
					}
				}

				if(a[k].del != r_a[z].del) {
					a[k].del = r_a[z].del = 0;
					a[k].occ = r_a[z].occ = (uint32_t)-1;
				}
			}
	} else {
		a = u_trans_a(*(c->ta), i); n = u_trans_n(*(c->ta), i);
		for (k = m = 0; k < n; k++) {
			if((a[k].occ != (uint32_t)-1)) {
				if(m != k) {t = a[k]; a[k] = a[m]; a[m] = t;}
				m++;
			}
		}
		radix_sort_u_trans_qs0(a, a + m);
		radix_sort_u_trans_qs0(a + m, a + n);
		a = a + m; n = n - m;
		if(n) {//sort and merge unreliable regions
			for (k = 0; k < n; k++) a[k].del = 1; 
			for (k = m = 0; k < n; k++) {
				if((m > 0) && (a[m-1].qe >= a[k].qs)) {
					if(a[k].qe > a[m-1].qe) a[m-1].qe = a[k].qe;
				} else {
					a[m++] = a[k];
				}
			}

			for(k = m; k < n; k++) {///not useful anymore
				a[k].qn = a[k].qs = a[k].qe = (uint32_t)-1;
				a[k].tn = a[k].ts = a[k].te = (uint32_t)-1;
			}
		}
	}
	
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq 0x40(%rdi), %rax
cmpq $0x1, %rax
je 0x19c68b
testq %rax, %rax
jne 0x19c789
movq (%rdi), %r14
movq 0x68(%r14), %rax
movslq %edx, %rcx
imulq $0x18, %rcx, %r15
movq 0x10(%rax,%r15), %rcx
leaq 0x10(%rsp), %rbx
movq %rcx, 0x10(%rbx)
movups (%rax,%r15), %xmm0
movaps %xmm0, (%rbx)
movq 0x38(%rdi), %rax
movq 0x28(%rax), %rcx
movq (%rcx,%rsi,8), %rcx
movl %ecx, %esi
shrq $0x20, %rcx
imulq $0x30, %rcx, %rdi
addq 0x10(%rax), %rdi
movsd 0x46eb9(%rip), %xmm0    # 0x1e3520
movq %rbx, %rdx
callq 0x18cd86
movq 0x10(%rbx), %rax
movq 0x68(%r14), %rcx
movq %rax, 0x10(%rcx,%r15)
movdqa (%rbx), %xmm0
movdqu %xmm0, (%rcx,%r15)
jmp 0x19c853
movq 0x38(%rdi), %rdx
movq 0x28(%rdx), %rax
movq (%rax,%rsi,8), %rcx
movl %ecx, %eax
shrq $0x20, %rcx
imulq $0x30, %rcx, %rcx
addq 0x10(%rdx), %rcx
xorl %edx, %edx
leaq 0xb70aa(%rip), %rsi     # 0x253758
cmpq %rax, %rdx
je 0x19c853
imulq $0x30, %rdx, %r8
movl 0x8(%rcx,%r8), %r10d
movl 0x14(%rcx,%r8), %r9d
cmpl %r10d, %r9d
jb 0x19c781
addq %rcx, %r8
movq 0x38(%rdi), %r11
movq 0x10(%r11), %rbx
movq 0x28(%r11), %r11
movq (%r11,%r9,8), %r9
movl %r9d, %r11d
shrq $0x20, %r9
imulq $0x30, %r9, %r9
addq %rbx, %r9
addq $0x28, %r9
subq $0x1, %r11
jb 0x19c908
cmpl %r10d, -0x14(%r9)
je 0x19c709
addq $0x30, %r9
jmp 0x19c6f3
movb 0x28(%r8), %r10b
testb $0x3f, %r10b
je 0x19c719
testb $0x3f, (%r9)
jne 0x19c763
movl 0x4(%r8), %ebx
subl (%r8), %ebx
movq 0x268(%rsi), %r11
cmpq %rbx, %r11
jae 0x19c753
movl 0x10(%r8), %ebx
subl 0xc(%r8), %ebx
cmpq %rbx, %r11
jae 0x19c753
movl -0x24(%r9), %ebx
subl -0x28(%r9), %ebx
cmpq %rbx, %r11
jae 0x19c753
movl -0x18(%r9), %ebx
subl -0x1c(%r9), %ebx
cmpq %rbx, %r11
jb 0x19c763
orb $-0x80, (%r9)
movb 0x28(%r8), %r10b
orb $-0x80, %r10b
movb %r10b, 0x28(%r8)
movb (%r9), %r11b
xorb %r11b, %r10b
jns 0x19c781
andb $0x7f, %r11b
movb %r11b, (%r9)
andb $0x7f, 0x28(%r8)
orl $-0x1, -0x10(%r9)
orl $-0x1, 0x18(%r8)
incq %rdx
jmp 0x19c6ae
movq 0x38(%rdi), %rax
movq 0x10(%rax), %r15
movq 0x28(%rax), %rax
movq (%rax,%rsi,8), %rax
movl %eax, %r12d
shrq $0x20, %rax
imulq $0x30, %rax, %rax
movq %rax, 0x8(%rsp)
leaq (%r15,%rax), %r14
xorl %eax, %eax
movq %r14, %rcx
xorl %ebp, %ebp
cmpq %rax, %r12
je 0x19c82c
cmpl $-0x1, 0x18(%rcx)
je 0x19c823
cmpq %rbp, %rax
je 0x19c820
movups (%rcx), %xmm0
movups 0x10(%rcx), %xmm1
movups 0x20(%rcx), %xmm2
movaps %xmm2, 0x30(%rsp)
movaps %xmm1, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
imulq $0x30, %rbp, %rdx
movups (%r14,%rdx), %xmm0
movups 0x10(%r14,%rdx), %xmm1
movups 0x20(%r14,%rdx), %xmm2
movups %xmm2, 0x20(%rcx)
movups %xmm1, 0x10(%rcx)
movups %xmm0, (%rcx)
movdqa 0x10(%rsp), %xmm0
movaps 0x20(%rsp), %xmm1
movaps 0x30(%rsp), %xmm2
movups %xmm2, 0x20(%r14,%rdx)
movups %xmm1, 0x10(%r14,%rdx)
movdqu %xmm0, (%r14,%rdx)
incq %rbp
incq %rax
addq $0x30, %rcx
jmp 0x19c7b4
imulq $0x30, %rbp, %r13
leaq (%r14,%r13), %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x156924
imulq $0x30, %r12, %rsi
addq %r14, %rsi
movq %rbx, %rdi
callq 0x156924
subq %rbp, %r12
jne 0x19c862
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addq 0x8(%rsp), %r15
leaq (%r15,%r13), %rax
addq $0x28, %rax
movq %r12, %rcx
subq $0x1, %rcx
jb 0x19c881
orb $-0x80, (%rax)
addq $0x30, %rax
jmp 0x19c872
leaq -0x2c(%rbx), %rcx
xorl %eax, %eax
movq %rbx, %rdx
movq %r12, %rsi
subq $0x1, %rsi
jb 0x19c8de
testq %rax, %rax
je 0x19c8a5
imulq $0x30, %rax, %rdi
movl (%rcx,%rdi), %r8d
cmpl (%rdx), %r8d
jae 0x19c8cd
imulq $0x30, %rax, %rdi
incq %rax
movdqu (%rdx), %xmm0
movups 0x10(%rdx), %xmm1
movups 0x20(%rdx), %xmm2
movups %xmm2, 0x20(%rbx,%rdi)
movups %xmm1, 0x10(%rbx,%rdi)
movdqu %xmm0, (%rbx,%rdi)
addq $0x30, %rdx
jmp 0x19c88d
movl 0x4(%rdx), %r9d
cmpl %r8d, %r9d
jbe 0x19c8c7
addq %rcx, %rdi
movl %r9d, (%rdi)
jmp 0x19c8c7
imulq $0x30, %rax, %rcx
addq %rcx, %r13
addq %r13, %r15
pcmpeqd %xmm0, %xmm0
cmpq %r12, %rax
jae 0x19c853
incq %rax
movdqu %xmm0, (%r15)
orq $-0x1, 0x10(%r15)
addq $0x30, %r15
jmp 0x19c8ec
leaq 0x5a80c(%rip), %rdi     # 0x1f711b
leaq 0x5520d(%rip), %rsi     # 0x1f1b23
leaq 0x5a806(%rip), %rcx     # 0x1f7123
movl $0x44ae, %edx           # imm = 0x44AE
callq 0x2110