// File: chhylp123[P]hifiasm/inter.cpp
// Function: update_gen_r_contain(void*, long, int)
static void update_gen_r_contain(void *data, long i, int tid) // callback for kt_for()
{
	r_contain_aux *s = (r_contain_aux *)data;
	ma_hit_t_alloc *src = s->src; ma_hit_t *t; int32_t r; asg_arc_t x;
	uint64_t *a = s->cr->interval.a + s->cr->idx[i], a_n = s->cr->idx[i+1] - s->cr->idx[i], k, dp, l, z, qn, tn;
	uint64_t is_el = s->is_el, is_del = s->is_del, min_ovlp = s->min_ovlp, max_hang = s->max_hang, qs, qe, cs, ce, sum;
	int64_t ii; asg_t *rg = s->rg; uint64_t *b, b_n, ti;
	// if(a_n == 0 || rg->seq[i].del) return;
	if(s->is_src_cc) {
		for (z = 0; z < src[i].length; z++) {
			t = &(src[i].buffer[z]); t->cc = 0;
			if(a_n == 0 || rg->seq[i].del) continue;
			qn = Get_qn((*t)); tn = Get_tn((*t));
			if(qn > tn) continue;
			if(is_el && (!(t->el))) continue;
			if(is_del && (!(t->del))) continue;
			if((Get_qe((*t)) - Get_qs((*t))) < min_ovlp) continue;
			if((Get_te((*t)) - Get_ts((*t))) < min_ovlp) continue;
			if(rg->seq[tn].del) continue;
			b = s->cr->interval.a + s->cr->idx[tn]; b_n = s->cr->idx[tn+1] - s->cr->idx[tn];
			if(b_n == 0) continue;
			r = ma_hit2arc(t, Get_READ_LENGTH(R_INF, qn), Get_READ_LENGTH(R_INF, tn), max_hang, asm_opt.max_hang_rate, min_ovlp, &x);
			if(r < 0) continue;	
			qs = Get_qs((*t)); qe = Get_qe((*t));
			for (k = 0; k < a_n; k += 2) {
				cs = a[k]>>33; ce = a[k+1]>>33; assert(rg->seq[(uint32_t)(a[k])].del);
				if(qs<=cs+128 && qe+128>=ce) { ///128 is the offset for indel
					for (ti = 0; ti < b_n; ti+=2) {
						if((uint32_t)(b[ti]) == (uint32_t)(a[k])) {
							sum = t->cc; sum += (ce - cs);
							if(sum > 0x3fffffffU) sum = 0x3fffffffU;
							t->cc = sum;
							break;
						}
					}
				}
			}
		}
	} else {
		radix_sort_gfa64(a, a + a_n);
		for (k = 0, dp = 0; k < a_n; ++k) {
			///if a[j] is qe
			if ((a[k]>>32)&1) --dp;
			else ++dp;
			l = a[k]>>33; l <<= 32; l += dp;
			a[k] = l;
		}
		for (z = 0; z < src[i].length; z++) {
			t = &(src[i].buffer[z]); 
			qn = Get_qn((*t)); tn = Get_tn((*t));
			if(qn > tn) continue;
			if(t->cc == 0) continue;
			ii = get_specific_overlap(&(src[tn]), tn, qn);
			src[tn].buffer[ii].cc = t->cc;
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
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 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rax
movq -0x20(%rbp), %rcx
movq (%rcx), %rcx
movq (%rcx), %rcx
movq -0x10(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq -0x10(%rbp), %rcx
movl 0x4(%rax,%rcx,4), %eax
movq -0x20(%rbp), %rcx
movq (%rcx), %rcx
movq (%rcx), %rcx
movq -0x10(%rbp), %rdx
subl (%rcx,%rdx,4), %eax
movl %eax, %eax
movq %rax, -0x60(%rbp)
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x98(%rbp)
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0xa0(%rbp)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0xa8(%rbp)
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0xb0(%rbp)
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0xe8(%rbp)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x30(%rax)
je 0x2faa59
movq $0x0, -0x80(%rbp)
movq -0x80(%rbp), %rax
movq -0x28(%rbp), %rcx
imulq $0x18, -0x10(%rbp), %rdx
addq %rdx, %rcx
movl 0xc(%rcx), %ecx
cmpq %rcx, %rax
jae 0x2faa54
movq -0x28(%rbp), %rax
imulq $0x18, -0x10(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
imulq $0x28, -0x80(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rcx
andq $-0x40000000, %rcx      # imm = 0xC0000000
orq $0x0, %rcx
movq %rcx, 0x18(%rax)
cmpq $0x0, -0x60(%rbp)
je 0x2fa6cb
movq -0xe8(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x10(%rbp), %rcx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x2fa6d0
jmp 0x2faa43
movq -0x30(%rbp), %rax
movq (%rax), %rax
shrq $0x20, %rax
movl %eax, %eax
movq %rax, -0x88(%rbp)
movq -0x30(%rbp), %rax
movl 0xc(%rax), %eax
movq %rax, -0x90(%rbp)
movq -0x88(%rbp), %rax
cmpq -0x90(%rbp), %rax
jbe 0x2fa707
jmp 0x2faa43
cmpq $0x0, -0x98(%rbp)
je 0x2fa720
movq -0x30(%rbp), %rax
cmpb $0x0, 0x20(%rax)
jne 0x2fa720
jmp 0x2faa43
cmpq $0x0, -0xa0(%rbp)
je 0x2fa740
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
shrq $0x3f, %rax
cmpl $0x0, %eax
jne 0x2fa740
jmp 0x2faa43
movq -0x30(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x30(%rbp), %rcx
movq (%rcx), %rcx
subl %ecx, %eax
movl %eax, %eax
cmpq -0xa8(%rbp), %rax
jae 0x2fa760
jmp 0x2faa43
movq -0x30(%rbp), %rax
movl 0x14(%rax), %eax
movq -0x30(%rbp), %rcx
subl 0x10(%rcx), %eax
movl %eax, %eax
cmpq -0xa8(%rbp), %rax
jae 0x2fa77e
jmp 0x2faa43
movq -0xe8(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x90(%rbp), %rcx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x2fa7a0
jmp 0x2faa43
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rax
movq -0x20(%rbp), %rcx
movq (%rcx), %rcx
movq (%rcx), %rcx
movq -0x90(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0xf0(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq -0x90(%rbp), %rcx
movl 0x4(%rax,%rcx,4), %eax
movq -0x20(%rbp), %rcx
movq (%rcx), %rcx
movq (%rcx), %rcx
movq -0x90(%rbp), %rdx
subl (%rcx,%rdx,4), %eax
movl %eax, %eax
movq %rax, -0xf8(%rbp)
cmpq $0x0, -0xf8(%rbp)
jne 0x2fa80e
jmp 0x2faa43
movq -0x30(%rbp), %rdi
leaq 0xcaab7(%rip), %rax     # 0x3c52d0
movq 0x18(%rax), %rax
movq -0x88(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %esi
leaq 0xcaa9f(%rip), %rax     # 0x3c52d0
movq 0x18(%rax), %rax
movq -0x90(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %edx
movq -0xb0(%rbp), %rax
movl %eax, %ecx
leaq 0xc9fa6(%rip), %rax     # 0x3c47f8
movss 0x158(%rax), %xmm0
movq -0xa8(%rbp), %rax
movl %eax, %r8d
leaq -0x50(%rbp), %r9
callq 0x287f40
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jge 0x2fa87b
jmp 0x2faa43
movq -0x30(%rbp), %rax
movq (%rax), %rax
movl %eax, %eax
movq %rax, -0xb8(%rbp)
movq -0x30(%rbp), %rax
movl 0x8(%rax), %eax
movq %rax, -0xc0(%rbp)
movq $0x0, -0x68(%rbp)
movq -0x68(%rbp), %rax
cmpq -0x60(%rbp), %rax
jae 0x2faa41
movq -0x58(%rbp), %rax
movq -0x68(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x21, %rax
movq %rax, -0xc8(%rbp)
movq -0x58(%rbp), %rax
movq -0x68(%rbp), %rcx
movq 0x8(%rax,%rcx,8), %rax
shrq $0x21, %rax
movq %rax, -0xd0(%rbp)
movq -0xe8(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x58(%rbp), %rcx
movq -0x68(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x2fa904
jmp 0x2fa923
leaq 0x9b467(%rip), %rdi     # 0x395d72
leaq 0x95f1d(%rip), %rsi     # 0x39082f
movl $0x5252, %edx           # imm = 0x5252
leaq 0x9b472(%rip), %rcx     # 0x395d90
callq 0x2130
movq -0xb8(%rbp), %rax
movq -0xc8(%rbp), %rcx
addq $0x80, %rcx
cmpq %rcx, %rax
ja 0x2faa2e
movq -0xc0(%rbp), %rax
addq $0x80, %rax
cmpq -0xd0(%rbp), %rax
jb 0x2faa2e
movq $0x0, -0x100(%rbp)
movq -0x100(%rbp), %rax
cmpq -0xf8(%rbp), %rax
jae 0x2faa2c
movq -0xf0(%rbp), %rax
movq -0x100(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x58(%rbp), %rcx
movq -0x68(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
cmpl %ecx, %eax
jne 0x2faa13
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
andq $0x3fffffff, %rax       # imm = 0x3FFFFFFF
movl %eax, %eax
movq %rax, -0xd8(%rbp)
movq -0xd0(%rbp), %rax
subq -0xc8(%rbp), %rax
addq -0xd8(%rbp), %rax
movq %rax, -0xd8(%rbp)
cmpq $0x3fffffff, -0xd8(%rbp) # imm = 0x3FFFFFFF
jbe 0x2fa9e7
movq $0x3fffffff, -0xd8(%rbp) # imm = 0x3FFFFFFF
movq -0xd8(%rbp), %rax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, %ecx
movl %ecx, %edx
movq 0x18(%rax), %rcx
andq $0x3fffffff, %rdx       # imm = 0x3FFFFFFF
andq $-0x40000000, %rcx      # imm = 0xC0000000
orq %rdx, %rcx
movq %rcx, 0x18(%rax)
jmp 0x2faa2c
jmp 0x2faa15
movq -0x100(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x100(%rbp)
jmp 0x2fa966
jmp 0x2faa2e
jmp 0x2faa30
movq -0x68(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x68(%rbp)
jmp 0x2fa8a1
jmp 0x2faa43
movq -0x80(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
jmp 0x2fa65c
jmp 0x2fac25
movq -0x58(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x60(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x27a9b0
movq $0x0, -0x68(%rbp)
movq $0x0, -0x70(%rbp)
movq -0x68(%rbp), %rax
cmpq -0x60(%rbp), %rax
jae 0x2fab10
movq -0x58(%rbp), %rax
movq -0x68(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
andq $0x1, %rax
cmpq $0x0, %rax
je 0x2faab7
movq -0x70(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0x2faac3
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
movq -0x58(%rbp), %rax
movq -0x68(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x21, %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
shlq $0x20, %rax
movq %rax, -0x78(%rbp)
movq -0x70(%rbp), %rax
addq -0x78(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rdx
movq -0x58(%rbp), %rax
movq -0x68(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
jmp 0x2faa81
movq $0x0, -0x80(%rbp)
movq -0x80(%rbp), %rax
movq -0x28(%rbp), %rcx
imulq $0x18, -0x10(%rbp), %rdx
addq %rdx, %rcx
movl 0xc(%rcx), %ecx
cmpq %rcx, %rax
jae 0x2fac23
movq -0x28(%rbp), %rax
imulq $0x18, -0x10(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
imulq $0x28, -0x80(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rax
shrq $0x20, %rax
movl %eax, %eax
movq %rax, -0x88(%rbp)
movq -0x30(%rbp), %rax
movl 0xc(%rax), %eax
movq %rax, -0x90(%rbp)
movq -0x88(%rbp), %rax
cmpq -0x90(%rbp), %rax
jbe 0x2fab86
jmp 0x2fac12
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
andq $0x3fffffff, %rax       # imm = 0x3FFFFFFF
cmpl $0x0, %eax
jne 0x2fab9b
jmp 0x2fac12
movq -0x28(%rbp), %rdi
imulq $0x18, -0x90(%rbp), %rax
addq %rax, %rdi
movq -0x90(%rbp), %rax
movl %eax, %esi
movq -0x88(%rbp), %rax
movl %eax, %edx
callq 0xce1b0
movq %rax, -0xe0(%rbp)
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
andq $0x3fffffff, %rax       # imm = 0x3FFFFFFF
movl %eax, %ecx
movq -0x28(%rbp), %rax
imulq $0x18, -0x90(%rbp), %rdx
addq %rdx, %rax
movq (%rax), %rax
imulq $0x28, -0xe0(%rbp), %rdx
addq %rdx, %rax
movl %ecx, %ecx
movl %ecx, %edx
movq 0x18(%rax), %rcx
andq $0x3fffffff, %rdx       # imm = 0x3FFFFFFF
andq $-0x40000000, %rcx      # imm = 0xC0000000
orq %rdx, %rcx
movq %rcx, 0x18(%rax)
movq -0x80(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
jmp 0x2fab18
jmp 0x2fac25
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
nop