// File: 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
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x40(%rax)
jne 0x3004a1
movq -0x28(%rbp), %rax
movq 0x68(%rax), %rax
movslq -0x14(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movq 0x68(%rax), %rax
movslq -0x14(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rax
movq 0x68(%rax), %rax
movslq -0x14(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x10(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x28(%rax), %rax
movq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
imulq $0x30, %rax, %rax
addq %rax, %rdi
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x28(%rax), %rax
movq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
movl %eax, %esi
leaq -0x40(%rbp), %rdx
movsd 0x81e09(%rip), %xmm0    # 0x382250
callq 0x2e4040
movq -0x30(%rbp), %rcx
movq -0x28(%rbp), %rax
movq 0x68(%rax), %rax
movslq -0x14(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x10(%rax)
movq -0x40(%rbp), %rcx
movq -0x28(%rbp), %rax
movq 0x68(%rax), %rax
movslq -0x14(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movq -0x38(%rbp), %rcx
movq -0x28(%rbp), %rax
movq 0x68(%rax), %rax
movslq -0x14(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
jmp 0x300c3d
movq -0x20(%rbp), %rax
cmpq $0x1, 0x40(%rax)
jne 0x300884
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x10(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x38(%rcx), %rcx
movq 0x28(%rcx), %rcx
movq -0x10(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x28(%rax), %rax
movq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
movq %rax, -0x88(%rbp)
movq $0x0, -0x98(%rbp)
movq -0x98(%rbp), %rax
cmpq -0x88(%rbp), %rax
jae 0x30087f
movq -0x48(%rbp), %rax
imulq $0x30, -0x98(%rbp), %rcx
addq %rcx, %rax
movl 0x14(%rax), %eax
movq -0x48(%rbp), %rcx
imulq $0x30, -0x98(%rbp), %rdx
addq %rdx, %rcx
cmpl 0x8(%rcx), %eax
jae 0x300546
jmp 0x300868
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x10(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x38(%rcx), %rcx
movq 0x28(%rcx), %rcx
movq -0x48(%rbp), %rdx
imulq $0x30, -0x98(%rbp), %rsi
addq %rsi, %rdx
movl 0x14(%rdx), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x28(%rax), %rax
movq -0x48(%rbp), %rcx
imulq $0x30, -0x98(%rbp), %rdx
addq %rdx, %rcx
movl 0x14(%rcx), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
movq %rax, -0x90(%rbp)
movq $0x0, -0xa0(%rbp)
movq -0xa0(%rbp), %rcx
xorl %eax, %eax
cmpq -0x90(%rbp), %rcx
movb %al, -0xa9(%rbp)
jae 0x3005fe
movq -0x50(%rbp), %rax
imulq $0x30, -0xa0(%rbp), %rcx
addq %rcx, %rax
movl 0x14(%rax), %eax
movq -0x48(%rbp), %rcx
imulq $0x30, -0x98(%rbp), %rdx
addq %rdx, %rcx
cmpl 0x8(%rcx), %eax
setne %al
movb %al, -0xa9(%rbp)
movb -0xa9(%rbp), %al
testb $0x1, %al
jne 0x30060a
jmp 0x300620
jmp 0x30060c
movq -0xa0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xa0(%rbp)
jmp 0x3005b9
movq -0xa0(%rbp), %rax
cmpq -0x90(%rbp), %rax
jae 0x300632
jmp 0x300651
leaq 0x957ee(%rip), %rdi     # 0x395e27
leaq 0x901ef(%rip), %rsi     # 0x39082f
movl $0x44ae, %edx           # imm = 0x44AE
leaq 0x957e3(%rip), %rcx     # 0x395e2f
callq 0x2130
movq -0x48(%rbp), %rax
imulq $0x30, -0x98(%rbp), %rcx
addq %rcx, %rax
movb 0x28(%rax), %al
andb $0x3f, %al
cmpb $0x0, %al
je 0x300685
movq -0x50(%rbp), %rax
imulq $0x30, -0xa0(%rbp), %rcx
addq %rcx, %rax
movb 0x28(%rax), %al
andb $0x3f, %al
cmpb $0x0, %al
jne 0x3007d0
movq -0x48(%rbp), %rax
imulq $0x30, -0x98(%rbp), %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movq -0x48(%rbp), %rcx
imulq $0x30, -0x98(%rbp), %rdx
addq %rdx, %rcx
subl (%rcx), %eax
movl %eax, %eax
leaq 0xc4147(%rip), %rcx     # 0x3c47f8
cmpq 0x268(%rcx), %rax
jbe 0x3006f0
movq -0x48(%rbp), %rax
imulq $0x30, -0x98(%rbp), %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
movq -0x48(%rbp), %rcx
imulq $0x30, -0x98(%rbp), %rdx
addq %rdx, %rcx
subl 0xc(%rcx), %eax
movl %eax, %eax
leaq 0xc4111(%rip), %rcx     # 0x3c47f8
cmpq 0x268(%rcx), %rax
ja 0x30072b
movq -0x50(%rbp), %rax
imulq $0x30, -0xa0(%rbp), %rcx
addq %rcx, %rax
movb 0x28(%rax), %cl
andb $0x7f, %cl
orb $-0x80, %cl
movb %cl, 0x28(%rax)
movq -0x48(%rbp), %rax
imulq $0x30, -0x98(%rbp), %rcx
addq %rcx, %rax
movb 0x28(%rax), %cl
andb $0x7f, %cl
orb $-0x80, %cl
movb %cl, 0x28(%rax)
jmp 0x3007ce
movq -0x50(%rbp), %rax
imulq $0x30, -0xa0(%rbp), %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movq -0x50(%rbp), %rcx
imulq $0x30, -0xa0(%rbp), %rdx
addq %rdx, %rcx
subl (%rcx), %eax
movl %eax, %eax
leaq 0xc40a1(%rip), %rcx     # 0x3c47f8
cmpq 0x268(%rcx), %rax
jbe 0x300796
movq -0x50(%rbp), %rax
imulq $0x30, -0xa0(%rbp), %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
movq -0x50(%rbp), %rcx
imulq $0x30, -0xa0(%rbp), %rdx
addq %rdx, %rcx
subl 0xc(%rcx), %eax
movl %eax, %eax
leaq 0xc406b(%rip), %rcx     # 0x3c47f8
cmpq 0x268(%rcx), %rax
ja 0x3007cc
movq -0x50(%rbp), %rax
imulq $0x30, -0xa0(%rbp), %rcx
addq %rcx, %rax
movb 0x28(%rax), %cl
andb $0x7f, %cl
orb $-0x80, %cl
movb %cl, 0x28(%rax)
movq -0x48(%rbp), %rax
imulq $0x30, -0x98(%rbp), %rcx
addq %rcx, %rax
movb 0x28(%rax), %cl
andb $0x7f, %cl
orb $-0x80, %cl
movb %cl, 0x28(%rax)
jmp 0x3007ce
jmp 0x3007d0
movq -0x48(%rbp), %rax
imulq $0x30, -0x98(%rbp), %rcx
addq %rcx, %rax
movb 0x28(%rax), %al
shrb $0x7, %al
movzbl %al, %eax
movq -0x50(%rbp), %rcx
imulq $0x30, -0xa0(%rbp), %rdx
addq %rdx, %rcx
movb 0x28(%rcx), %cl
shrb $0x7, %cl
movzbl %cl, %ecx
cmpl %ecx, %eax
je 0x300866
movq -0x50(%rbp), %rax
imulq $0x30, -0xa0(%rbp), %rcx
addq %rcx, %rax
movb 0x28(%rax), %cl
andb $0x7f, %cl
orb $0x0, %cl
movb %cl, 0x28(%rax)
movq -0x48(%rbp), %rax
imulq $0x30, -0x98(%rbp), %rcx
addq %rcx, %rax
movb 0x28(%rax), %cl
andb $0x7f, %cl
orb $0x0, %cl
movb %cl, 0x28(%rax)
movq -0x50(%rbp), %rax
imulq $0x30, -0xa0(%rbp), %rcx
addq %rcx, %rax
movl $0xffffffff, 0x18(%rax) # imm = 0xFFFFFFFF
movq -0x48(%rbp), %rax
imulq $0x30, -0x98(%rbp), %rcx
addq %rcx, %rax
movl $0xffffffff, 0x18(%rax) # imm = 0xFFFFFFFF
jmp 0x300868
movq -0x98(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x98(%rbp)
jmp 0x300507
jmp 0x300c3b
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x10(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x38(%rcx), %rcx
movq 0x28(%rcx), %rcx
movq -0x10(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x28(%rax), %rax
movq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
movq %rax, -0x88(%rbp)
movq $0x0, -0xa8(%rbp)
movq $0x0, -0x98(%rbp)
movq -0x98(%rbp), %rax
cmpq -0x88(%rbp), %rax
jae 0x3009b0
movq -0x48(%rbp), %rax
imulq $0x30, -0x98(%rbp), %rcx
addq %rcx, %rax
cmpl $-0x1, 0x18(%rax)
je 0x300997
movq -0xa8(%rbp), %rax
cmpq -0x98(%rbp), %rax
je 0x300985
movq -0x48(%rbp), %rsi
imulq $0x30, -0x98(%rbp), %rax
addq %rax, %rsi
leaq -0x80(%rbp), %rdi
movl $0x30, %edx
callq 0x2180
movq -0x48(%rbp), %rsi
imulq $0x30, -0xa8(%rbp), %rax
addq %rax, %rsi
movq -0x48(%rbp), %rdi
imulq $0x30, -0x98(%rbp), %rax
addq %rax, %rdi
movl $0x30, %edx
callq 0x2180
movq -0x48(%rbp), %rdi
imulq $0x30, -0xa8(%rbp), %rax
addq %rax, %rdi
leaq -0x80(%rbp), %rsi
movl $0x30, %edx
callq 0x2180
movq -0xa8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xa8(%rbp)
jmp 0x300999
movq -0x98(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x98(%rbp)
jmp 0x3008e6
movq -0x48(%rbp), %rdi
movq -0x48(%rbp), %rsi
imulq $0x30, -0xa8(%rbp), %rax
addq %rax, %rsi
callq 0x27a550
movq -0x48(%rbp), %rdi
imulq $0x30, -0xa8(%rbp), %rax
addq %rax, %rdi
movq -0x48(%rbp), %rsi
imulq $0x30, -0x88(%rbp), %rax
addq %rax, %rsi
callq 0x27a550
movq -0x48(%rbp), %rax
imulq $0x30, -0xa8(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x88(%rbp), %rax
subq -0xa8(%rbp), %rax
movq %rax, -0x88(%rbp)
cmpq $0x0, -0x88(%rbp)
je 0x300c39
movq $0x0, -0x98(%rbp)
movq -0x98(%rbp), %rax
cmpq -0x88(%rbp), %rax
jae 0x300a6b
movq -0x48(%rbp), %rax
imulq $0x30, -0x98(%rbp), %rcx
addq %rcx, %rax
movb 0x28(%rax), %cl
andb $0x7f, %cl
orb $-0x80, %cl
movb %cl, 0x28(%rax)
movq -0x98(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x98(%rbp)
jmp 0x300a2c
movq $0x0, -0xa8(%rbp)
movq $0x0, -0x98(%rbp)
movq -0x98(%rbp), %rax
cmpq -0x88(%rbp), %rax
jae 0x300b7b
cmpq $0x0, -0xa8(%rbp)
jbe 0x300b29
movq -0x48(%rbp), %rax
movq -0xa8(%rbp), %rcx
subq $0x1, %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movq -0x48(%rbp), %rcx
imulq $0x30, -0x98(%rbp), %rdx
addq %rdx, %rcx
cmpl (%rcx), %eax
jb 0x300b29
movq -0x48(%rbp), %rax
imulq $0x30, -0x98(%rbp), %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movq -0x48(%rbp), %rcx
movq -0xa8(%rbp), %rdx
subq $0x1, %rdx
imulq $0x30, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x4(%rcx), %eax
jbe 0x300b27
movq -0x48(%rbp), %rax
imulq $0x30, -0x98(%rbp), %rcx
addq %rcx, %rax
movl 0x4(%rax), %ecx
movq -0x48(%rbp), %rax
movq -0xa8(%rbp), %rdx
subq $0x1, %rdx
imulq $0x30, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x4(%rax)
jmp 0x300b62
movq -0x48(%rbp), %rsi
imulq $0x30, -0x98(%rbp), %rax
addq %rax, %rsi
movq -0x48(%rbp), %rdi
movq -0xa8(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0xa8(%rbp)
imulq $0x30, %rax, %rax
addq %rax, %rdi
movl $0x30, %edx
callq 0x2180
jmp 0x300b64
movq -0x98(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x98(%rbp)
jmp 0x300a81
movq -0xa8(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
cmpq -0x88(%rbp), %rax
jae 0x300c37
movq -0x48(%rbp), %rax
imulq $0x30, -0x98(%rbp), %rcx
addq %rcx, %rax
movl $0xffffffff, 0x4(%rax)  # imm = 0xFFFFFFFF
movq -0x48(%rbp), %rax
imulq $0x30, -0x98(%rbp), %rcx
addq %rcx, %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq -0x48(%rbp), %rax
imulq $0x30, -0x98(%rbp), %rcx
addq %rcx, %rax
movl $0xffffffff, 0x8(%rax)  # imm = 0xFFFFFFFF
movq -0x48(%rbp), %rax
imulq $0x30, -0x98(%rbp), %rcx
addq %rcx, %rax
movl $0xffffffff, 0x10(%rax) # imm = 0xFFFFFFFF
movq -0x48(%rbp), %rax
imulq $0x30, -0x98(%rbp), %rcx
addq %rcx, %rax
movl $0xffffffff, 0xc(%rax)  # imm = 0xFFFFFFFF
movq -0x48(%rbp), %rax
imulq $0x30, -0x98(%rbp), %rcx
addq %rcx, %rax
movl $0xffffffff, 0x14(%rax) # imm = 0xFFFFFFFF
movq -0x98(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x98(%rbp)
jmp 0x300b89
jmp 0x300c39
jmp 0x300c3b
jmp 0x300c3d
addq $0xb0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)