// File: /workspace/github_cpp_makefile_star2_O1/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 0x1dd0e2
testq %rax, %rax
jne 0x1dd1ff
movq (%rdi), %r14
movq 0x68(%r14), %rax
movslq %edx, %rcx
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %r15
movq 0x10(%rax,%r15), %rcx
leaq 0x10(%rsp), %rbx
movq %rcx, 0x10(%rbx)
movq (%rax,%r15), %rcx
movq %rcx, (%rbx)
movq 0x8(%rax,%r15), %rax
movq %rax, 0x8(%rbx)
movq 0x38(%rdi), %rax
movq 0x28(%rax), %rcx
movq (%rcx,%rsi,8), %rcx
movl %ecx, %esi
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %rdi
shlq $0x4, %rdi
addq 0x10(%rax), %rdi
movq 0x48418(%rip), %xmm0    # 0x2254d0
movq %rbx, %rdx
callq 0x1cfeb6
movq 0x10(%rbx), %rax
movq 0x68(%r14), %rcx
movq %rax, 0x10(%rcx,%r15)
movq (%rbx), %rax
movq %rax, (%rcx,%r15)
movq 0x8(%rbx), %rax
movq %rax, 0x8(%rcx,%r15)
jmp 0x1dd35c
movq 0x38(%rdi), %r8
movq 0x28(%r8), %rax
movq (%rax,%rsi,8), %rdx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rdx, %rcx
andq %rax, %rcx
je 0x1dd35c
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %rdx
shlq $0x4, %rdx
addq 0x10(%r8), %rdx
xorl %esi, %esi
leaq 0xad640(%rip), %r8      # 0x28a758
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
leaq (%rsi,%rsi,2), %r10
shlq $0x4, %r10
movl 0x8(%rdx,%r10), %ebx
movl 0x14(%rdx,%r10), %r11d
cmpl %ebx, %r11d
jb 0x1dd1ee
movq 0x38(%rdi), %r15
movq 0x28(%r15), %r14
movq (%r14,%r11,8), %r11
movq %r11, %r14
andq %rax, %r14
je 0x1dd3d5
addq %rdx, %r10
movq 0x10(%r15), %r15
shrq $0x20, %r11
leaq (%r11,%r11,2), %r11
shlq $0x4, %r11
addq %r15, %r11
addq $0x28, %r11
cmpl %ebx, -0x14(%r11)
je 0x1dd17f
addq $0x30, %r11
decq %r14
jne 0x1dd16b
jmp 0x1dd3d5
testb $0x3f, 0x28(%r10)
je 0x1dd18c
testb $0x3f, (%r11)
jne 0x1dd1cf
movl 0x4(%r10), %r14d
subl (%r10), %r14d
movq 0x268(%r8), %rbx
cmpq %r14, %rbx
jae 0x1dd1c6
movl 0x10(%r10), %r14d
subl 0xc(%r10), %r14d
cmpq %r14, %rbx
jae 0x1dd1c6
movl -0x24(%r11), %r14d
subl -0x28(%r11), %r14d
cmpq %r14, %rbx
jae 0x1dd1c6
movl -0x18(%r11), %r14d
subl -0x1c(%r11), %r14d
cmpq %r14, %rbx
jb 0x1dd1cf
orb $-0x80, (%r11)
orb $-0x80, 0x28(%r10)
movb (%r11), %bl
movb 0x28(%r10), %bpl
xorb %bl, %bpl
jns 0x1dd1ee
andb $0x7f, %bl
movb %bl, (%r11)
andb $0x7f, 0x28(%r10)
movl %r9d, -0x10(%r11)
movl %r9d, 0x18(%r10)
incq %rsi
cmpq %rcx, %rsi
jne 0x1dd11e
jmp 0x1dd35c
movq 0x38(%rdi), %rax
movq 0x10(%rax), %r15
movq 0x28(%rax), %rax
movq (%rax,%rsi,8), %rax
movq %rax, %rcx
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x4, %rcx
leaq (%r15,%rcx), %r14
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
andq %rax, %r13
movq %rcx, 0x8(%rsp)
je 0x1dd2c4
xorl %ebp, %ebp
movq %r14, %rax
xorl %ecx, %ecx
cmpl $-0x1, 0x18(%rax)
je 0x1dd2b2
cmpq %rbp, %rcx
je 0x1dd2af
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups 0x20(%rax), %xmm2
movaps %xmm2, 0x30(%rsp)
movaps %xmm1, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
leaq (,%rbp,2), %rdx
addq %rbp, %rdx
shlq $0x4, %rdx
movups (%r14,%rdx), %xmm0
movups 0x10(%r14,%rdx), %xmm1
movups 0x20(%r14,%rdx), %xmm2
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
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 %rcx
addq $0x30, %rax
cmpq %rcx, %r13
jne 0x1dd23d
jmp 0x1dd2c6
xorl %ebp, %ebp
leaq (,%rbp,2), %r12
addq %rbp, %r12
shlq $0x4, %r12
leaq (%r14,%r12), %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x194dc3
leaq (,%r13,2), %rsi
addq %r13, %rsi
shlq $0x4, %rsi
addq %r14, %rsi
movq %rbx, %rdi
callq 0x194dc3
movq %r13, %rax
subq %rbp, %rax
je 0x1dd35c
addq 0x8(%rsp), %r12
leaq (%r15,%r12), %rcx
addq $0x28, %rcx
movq %r13, %rdx
orb $-0x80, (%rcx)
decq %rdx
addq $0x30, %rcx
cmpq %rdx, %rbp
jne 0x1dd316
cmpq %rbp, %r13
jne 0x1dd36b
xorl %ecx, %ecx
cmpq %rax, %rcx
jae 0x1dd35c
leaq (%rcx,%rcx,2), %rdx
shlq $0x4, %rdx
addq %rdx, %r12
addq %r12, %r15
pcmpeqd %xmm0, %xmm0
incq %rcx
movdqu %xmm0, (%r15)
movq $-0x1, 0x10(%r15)
addq $0x30, %r15
cmpq %rax, %rcx
jb 0x1dd343
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq -0x2c(%rbx), %rdx
xorl %ecx, %ecx
movq %rbx, %rsi
movq %rax, %rdi
testq %rcx, %rcx
je 0x1dd38d
leaq (%rcx,%rcx,2), %r8
shlq $0x4, %r8
movl (%rdx,%r8), %r9d
cmpl (%rsi), %r9d
jae 0x1dd3c4
leaq (%rcx,%rcx,2), %r8
incq %rcx
shlq $0x4, %r8
movdqu (%rsi), %xmm0
movups 0x10(%rsi), %xmm1
movups 0x20(%rsi), %xmm2
movups %xmm2, 0x20(%rbx,%r8)
movups %xmm1, 0x10(%rbx,%r8)
movdqu %xmm0, (%rbx,%r8)
addq $0x30, %rsi
decq %rdi
jne 0x1dd377
jmp 0x1dd32c
movl 0x4(%rsi), %r10d
cmpl %r9d, %r10d
jbe 0x1dd3b6
addq %rdx, %r8
movl %r10d, (%r8)
jmp 0x1dd3b6
leaq 0x5bba7(%rip), %rdi     # 0x238f83
leaq 0x565a8(%rip), %rsi     # 0x23398b
leaq 0x5bba1(%rip), %rcx     # 0x238f8b
movl $0x44ae, %edx           # imm = 0x44AE
callq 0x2110