// File: chhylp123[P]hifiasm/inter.cpp
// Function: push_emask_lst(mask_ul_ov_t*, overlap_region_alloc*, unsigned long, ma_ug_t*, unsigned long*, unsigned long, kv_emask_t*, unsigned long)
void push_emask_lst(mask_ul_ov_t *mk, overlap_region_alloc* ol, uint64_t minov, ma_ug_t *ug, uint64_t *a, uint64_t an, kv_emask_t *res, uint64_t is_pe)
{
	uint64_t i, l, sn, si, re, cn, skip_n; overlap_region *z; ul_ov_t p, *sa; 	
	uint64_t q0l, t0l, e0l, q1l, t1l, e1l; emask_t *m;
	if(is_pe) {
		for (i = 0; i < an; i++) {
			a[i] <<= 32; a[i] >>= 32;
		}
		radix_sort_gfa64(a, a+an);
		for (i = 1, l = si = 0; i <= an; i++) {
			if(i == an || (a[i]>>1) != (a[l]>>1)) {
				// k = (uint32_t)mk->idx.a[a[l]>>1];
				z = &(ol->list[(uint32_t)mk->idx.a[a[l]>>1]]);
				overlap_region2ul_ov_t(z, &p, ug->u.a[z->y_id].len);
				assert(i<=l+2); 
				assert((p.qe-p.qs) >= minov); 
				assert((p.te-p.ts) >= minov);
				assert(p.sec > 0);	
				sa = get_mask_interval(&p, &(mk->srt), &si, ug->u.a[p.qn].len, ug->u.a[p.tn].len, &sn, &skip_n);
				re = cal_exact_batch(z, sa, sn, ug->u.a[p.tn].len, &q0l, &t0l, &e0l, &q1l, &t1l, &e1l, ug);
				assert(re);
				cn = i - l;

				push_emask0(res, q0l, t0l, e0l, q1l, t1l, e1l, a[l]&1, ((i==(l+2))?1:0), minov, &p); l++;
				if(l < i) push_emask0(res, q0l, t0l, e0l, q1l, t1l, e1l, a[l]&1, ((i==(l+2))?1:0), minov, &p);
				// fprintf(stderr, "[M::%s]\tres->n::%u\tcn::%lu\n", __func__, (uint32_t)res->n, cn);
				full_lst_set(res->a+res->n-cn, cn, sa, sn, skip_n);	
				l = i;
			}
		}
	} else {
		for (i = 0; i < an; i++) {
			a[i] <<= 32; a[i] >>= 32;
			z = &(ol->list[(uint32_t)mk->idx.a[a[i]>>1]]);
			overlap_region2ul_ov_t(z, &p, ug->u.a[z->y_id].len);
			assert((p.qe-p.qs) >= minov); 
			assert((p.te-p.ts) >= minov);
			if(p.sec > 0) {
				sa = get_mask_interval(&p, &(mk->srt), &si, ug->u.a[p.qn].len, ug->u.a[p.tn].len, &sn, &skip_n);
				re = cal_exact_batch(z, sa, sn, ug->u.a[p.tn].len, &q0l, &t0l, &e0l, &q1l, &t1l, &e1l, ug);
				assert(re == 0);
			}

			m = &(res->a[res->n++]); memset(m, 0, sizeof((*m))); 
			m->dir = 2; m->pe = 0; m->tn = p.tn; m->rev = p.rev; m->full = 1; m->el = (uint32_t)-1; m->rn = (uint32_t)-1;
			m->qs = p.qs; m->qe = p.qe; m->ts = p.ts; m->te = p.te;
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0xf8, %rsp
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x20(%rbp)
movq %rsi, -0x28(%rbp)
movq %rdx, -0x30(%rbp)
movq %rcx, -0x38(%rbp)
movq %r8, -0x40(%rbp)
movq %r9, -0x48(%rbp)
cmpq $0x0, 0x18(%rbp)
je 0x2cbd99
movq $0x0, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x48(%rbp), %rax
jae 0x2cb953
movq -0x40(%rbp), %rax
movq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
shlq $0x20, %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x40(%rbp), %rax
movq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
shrq $0x20, %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x2cb913
movq -0x40(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x48(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x27a9b0
movq $0x1, -0x50(%rbp)
movq $0x0, -0x68(%rbp)
movq $0x0, -0x58(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x48(%rbp), %rax
ja 0x2cbd94
movq -0x50(%rbp), %rax
cmpq -0x48(%rbp), %rax
je 0x2cb9c2
movq -0x40(%rbp), %rax
movq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq %rax
movq -0x40(%rbp), %rcx
movq -0x58(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq %rcx
cmpq %rcx, %rax
je 0x2cbd81
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x40(%rbp), %rdx
movq -0x58(%rbp), %rsi
movq (%rdx,%rsi,8), %rdx
shrq %rdx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %ecx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x88(%rbp), %rcx
movl 0x10(%rcx), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %edx
leaq -0xa4(%rbp), %rsi
callq 0x30d310
movq -0x50(%rbp), %rax
movq -0x58(%rbp), %rcx
addq $0x2, %rcx
cmpq %rcx, %rax
ja 0x2cba41
jmp 0x2cba60
leaq 0xc717b(%rip), %rdi     # 0x392bc3
leaq 0xc4de0(%rip), %rsi     # 0x39082f
movl $0x2fab, %edx           # imm = 0x2FAB
leaq 0xc716f(%rip), %rcx     # 0x392bca
callq 0x2130
movl -0x9c(%rbp), %eax
subl -0xa0(%rbp), %eax
movl %eax, %eax
cmpq -0x30(%rbp), %rax
jb 0x2cba76
jmp 0x2cba95
leaq 0xc71cc(%rip), %rdi     # 0x392c49
leaq 0xc4dab(%rip), %rsi     # 0x39082f
movl $0x2fac, %edx           # imm = 0x2FAC
leaq 0xc713a(%rip), %rcx     # 0x392bca
callq 0x2130
movl -0x90(%rbp), %eax
subl -0x94(%rbp), %eax
movl %eax, %eax
cmpq -0x30(%rbp), %rax
jb 0x2cbaab
jmp 0x2cbaca
leaq 0xc71ac(%rip), %rdi     # 0x392c5e
leaq 0xc4d76(%rip), %rsi     # 0x39082f
movl $0x2fad, %edx           # imm = 0x2FAD
leaq 0xc7105(%rip), %rcx     # 0x392bca
callq 0x2130
movl -0x8c(%rbp), %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
cmpl $0x0, %eax
jle 0x2cbadc
jmp 0x2cbafb
leaq 0xc7190(%rip), %rdi     # 0x392c73
leaq 0xc4d45(%rip), %rsi     # 0x39082f
movl $0x2fae, %edx           # imm = 0x2FAE
leaq 0xc70d4(%rip), %rcx     # 0x392bca
callq 0x2130
movq -0x20(%rbp), %rsi
addq $0x18, %rsi
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movl -0xa4(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %ecx
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x98(%rbp), %edx
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %r8d
leaq -0xa4(%rbp), %rdi
leaq -0x68(%rbp), %rdx
leaq -0x60(%rbp), %r9
leaq -0x80(%rbp), %rax
movq %rax, (%rsp)
callq 0x2c8ce0
movq %rax, -0xb0(%rbp)
movq -0x88(%rbp), %rdi
movq -0xb0(%rbp), %rsi
movq -0x60(%rbp), %rdx
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x98(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %ecx
movq -0x38(%rbp), %rax
leaq -0xb8(%rbp), %r8
leaq -0xc0(%rbp), %r9
leaq -0xc8(%rbp), %r14
leaq -0xd0(%rbp), %rbx
leaq -0xd8(%rbp), %r11
leaq -0xe0(%rbp), %r10
movq %r14, (%rsp)
movq %rbx, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movq %rax, 0x20(%rsp)
callq 0x2c9500
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x70(%rbp)
je 0x2cbbf1
jmp 0x2cbc10
leaq 0xc7ff9(%rip), %rdi     # 0x393bf1
leaq 0xc4c30(%rip), %rsi     # 0x39082f
movl $0x2fb1, %edx           # imm = 0x2FB1
leaq 0xc6fbf(%rip), %rcx     # 0x392bca
callq 0x2130
movq -0x50(%rbp), %rax
subq -0x58(%rbp), %rax
movq %rax, -0x78(%rbp)
movq 0x10(%rbp), %rdi
movq -0xb8(%rbp), %rsi
movq -0xc0(%rbp), %rdx
movq -0xc8(%rbp), %rcx
movq -0xd0(%rbp), %r8
movq -0xd8(%rbp), %r9
movq -0xe0(%rbp), %r14
movq -0x40(%rbp), %rax
movq -0x58(%rbp), %r10
movq (%rax,%r10,8), %rbx
andq $0x1, %rbx
movq -0x50(%rbp), %r11
movq -0x58(%rbp), %r15
addq $0x2, %r15
xorl %eax, %eax
movl $0x1, %r10d
cmpq %r15, %r11
cmovel %r10d, %eax
movslq %eax, %r11
movq -0x30(%rbp), %r10
leaq -0xa4(%rbp), %rax
movq %r14, (%rsp)
movq %rbx, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movq %rax, 0x20(%rsp)
callq 0x2cb640
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpq -0x50(%rbp), %rax
jae 0x2cbd3e
movq 0x10(%rbp), %rdi
movq -0xb8(%rbp), %rsi
movq -0xc0(%rbp), %rdx
movq -0xc8(%rbp), %rcx
movq -0xd0(%rbp), %r8
movq -0xd8(%rbp), %r9
movq -0xe0(%rbp), %r14
movq -0x40(%rbp), %rax
movq -0x58(%rbp), %r10
movq (%rax,%r10,8), %rbx
andq $0x1, %rbx
movq -0x50(%rbp), %r11
movq -0x58(%rbp), %r15
addq $0x2, %r15
xorl %eax, %eax
movl $0x1, %r10d
cmpq %r15, %r11
cmovel %r10d, %eax
movslq %eax, %r11
movq -0x30(%rbp), %r10
leaq -0xa4(%rbp), %rax
movq %r14, (%rsp)
movq %rbx, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movq %rax, 0x20(%rsp)
callq 0x2cb640
movq 0x10(%rbp), %rax
movq (%rax), %rdi
movq 0x10(%rbp), %rax
movq 0x8(%rax), %rax
shlq $0x5, %rax
addq %rax, %rdi
xorl %eax, %eax
subq -0x78(%rbp), %rax
shlq $0x5, %rax
addq %rax, %rdi
movq -0x78(%rbp), %rsi
movq -0xb0(%rbp), %rdx
movq -0x60(%rbp), %rcx
movq -0x80(%rbp), %r8
callq 0x2cb1c0
movq -0x50(%rbp), %rax
movq %rax, -0x58(%rbp)
jmp 0x2cbd83
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x2cb983
jmp 0x2cc0ed
movq $0x0, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x48(%rbp), %rax
jae 0x2cc0eb
movq -0x40(%rbp), %rax
movq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
shlq $0x20, %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x40(%rbp), %rax
movq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
shrq $0x20, %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x40(%rbp), %rdx
movq -0x50(%rbp), %rsi
movq (%rdx,%rsi,8), %rdx
shrq %rdx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %ecx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x88(%rbp), %rcx
movl 0x10(%rcx), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %edx
leaq -0xa4(%rbp), %rsi
callq 0x30d310
movl -0x9c(%rbp), %eax
subl -0xa0(%rbp), %eax
movl %eax, %eax
cmpq -0x30(%rbp), %rax
jb 0x2cbe59
jmp 0x2cbe78
leaq 0xc6de9(%rip), %rdi     # 0x392c49
leaq 0xc49c8(%rip), %rsi     # 0x39082f
movl $0x2fc0, %edx           # imm = 0x2FC0
leaq 0xc6d57(%rip), %rcx     # 0x392bca
callq 0x2130
movl -0x90(%rbp), %eax
subl -0x94(%rbp), %eax
movl %eax, %eax
cmpq -0x30(%rbp), %rax
jb 0x2cbe8e
jmp 0x2cbead
leaq 0xc6dc9(%rip), %rdi     # 0x392c5e
leaq 0xc4993(%rip), %rsi     # 0x39082f
movl $0x2fc1, %edx           # imm = 0x2FC1
leaq 0xc6d22(%rip), %rcx     # 0x392bca
callq 0x2130
movl -0x8c(%rbp), %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
cmpl $0x0, %eax
jle 0x2cbfd8
movq -0x20(%rbp), %rsi
addq $0x18, %rsi
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movl -0xa4(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %ecx
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x98(%rbp), %edx
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %r8d
leaq -0xa4(%rbp), %rdi
leaq -0x68(%rbp), %rdx
leaq -0x60(%rbp), %r9
leaq -0x80(%rbp), %rax
movq %rax, (%rsp)
callq 0x2c8ce0
movq %rax, -0xb0(%rbp)
movq -0x88(%rbp), %rdi
movq -0xb0(%rbp), %rsi
movq -0x60(%rbp), %rdx
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x98(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %ecx
movq -0x38(%rbp), %rax
leaq -0xb8(%rbp), %r8
leaq -0xc0(%rbp), %r9
leaq -0xc8(%rbp), %r14
leaq -0xd0(%rbp), %rbx
leaq -0xd8(%rbp), %r11
leaq -0xe0(%rbp), %r10
movq %r14, (%rsp)
movq %rbx, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movq %rax, 0x20(%rsp)
callq 0x2c9500
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x70(%rbp)
jne 0x2cbfb7
jmp 0x2cbfd6
leaq 0xc6cbf(%rip), %rdi     # 0x392c7d
leaq 0xc486a(%rip), %rsi     # 0x39082f
movl $0x2fc5, %edx           # imm = 0x2FC5
leaq 0xc6bf9(%rip), %rcx     # 0x392bca
callq 0x2130
jmp 0x2cbfd8
movq 0x10(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rbp), %rdx
movq 0x8(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x8(%rdx)
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0xe8(%rbp)
movq -0xe8(%rbp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x2100
movq -0xe8(%rbp), %rax
movb 0x1c(%rax), %cl
andb $-0x20, %cl
orb $0x2, %cl
movb %cl, 0x1c(%rax)
movq -0xe8(%rbp), %rax
movb 0x1c(%rax), %cl
andb $-0x21, %cl
orb $0x0, %cl
movb %cl, 0x1c(%rax)
movl -0x98(%rbp), %ecx
movq -0xe8(%rbp), %rax
movl %ecx, (%rax)
movl -0x8c(%rbp), %eax
shrl $0x1f, %eax
movb %al, %dl
movq -0xe8(%rbp), %rax
movb 0x1c(%rax), %cl
andb $0x1, %dl
shlb $0x7, %dl
andb $0x7f, %cl
orb %dl, %cl
movb %cl, 0x1c(%rax)
movq -0xe8(%rbp), %rax
movb 0x1c(%rax), %cl
andb $-0x41, %cl
orb $0x40, %cl
movb %cl, 0x1c(%rax)
movq -0xe8(%rbp), %rax
movl $0xffffffff, 0x8(%rax)  # imm = 0xFFFFFFFF
movq -0xe8(%rbp), %rax
movl $0xffffffff, 0x4(%rax)  # imm = 0xFFFFFFFF
movl -0xa0(%rbp), %ecx
movq -0xe8(%rbp), %rax
movl %ecx, 0xc(%rax)
movl -0x9c(%rbp), %ecx
movq -0xe8(%rbp), %rax
movl %ecx, 0x10(%rax)
movl -0x94(%rbp), %ecx
movq -0xe8(%rbp), %rax
movl %ecx, 0x14(%rax)
movl -0x90(%rbp), %ecx
movq -0xe8(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x2cbda1
jmp 0x2cc0ed
addq $0xf8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax,%rax)