// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/inter.cpp
// Function: qry_bub_sc(ul_idx_t const*, ma_ug_t*, scaf_res_t*, bubble_type*, unsigned long, unsigned long, unsigned long, ul_vec_t*, unsigned int, kv_ul_ov_t*)
uint64_t qry_bub_sc(const ul_idx_t *uref, ma_ug_t *gfa, scaf_res_t *ref_sc, bubble_type *bub, uint64_t bid, uint64_t qsidx, uint64_t qeidx, ul_vec_t *qstr, uint32_t avoid_id, kv_ul_ov_t *res)
{
	// fprintf(stderr, "qsidx::%lu(utg%.6u%c), qeidx::%lu(utg%.6u%c)\n", qsidx, (qstr->bb.a[qsidx].hid)+1, "lc"[gfa->u.a[qstr->bb.a[qsidx].hid].circ], qeidx, (qstr->bb.a[qeidx].hid)+1, "lc"[gfa->u.a[qstr->bb.a[qeidx].hid].circ]);
	uint32_t beg, sink, v, w, z, si, ei, qrev = (uint32_t)-1, qv, qw, trev, nn = 0, tn;
	get_bubbles(bub, bid, &beg, &sink, NULL, NULL, NULL);
	if((beg == ((uint32_t)-1)) || (sink == ((uint32_t)-1))) return 0;
	utg_rid_dt *a; uint64_t a_n, i, k; ul_vec_t *q; ul_ov_t p;
	qv = qstr->bb.a[qsidx].hid; qv <<= 1; qv |= ((uint32_t)qstr->bb.a[qsidx].rev);
	qw = qstr->bb.a[qeidx].hid; qw <<= 1; qw |= ((uint32_t)qstr->bb.a[qeidx].rev);
	if((qv == beg) && (qw == (sink^1))) qrev = 0;
	if((qv == sink) && (qw == (beg^1))) qrev = 1;
	assert(qrev != (uint32_t)-1);
	memset(&p, 0, sizeof(p));

	v = beg; w = sink^1; trev = 0;
	a = get_r_ug_region(uref->r_ug, &a_n, v>>1);
	// fprintf(stderr, "+a_n::%lu\n", a_n);
	for (i = 0; i < a_n; i++) {
		// fprintf(stderr, "+(0)i::%lu\n", i);
		if((a[i].u&1) != (v&1)) continue;
		if((a[i].u>>1) == avoid_id) continue;
		q = &(ref_sc->a[a[i].u>>1]); si = ei = a[i].off; 
		assert((q->bb.a[si].hid == (v>>1)) && (q->bb.a[si].rev == (v&1)));
		// fprintf(stderr, "+(1)i::%lu\n", i);
		for (k = tn = 0; k < q->bb.n; k++) tn += q->bb.a[k].te - q->bb.a[k].ts;
		for (k = si + 1; (k < tn) && (q->bb.a[k].aidx == q->bb.a[si].aidx); k++) {
			z = (((uint32_t)q->bb.a[k].hid)<<1)|((uint32_t)q->bb.a[k].rev);
			if(z == w) {ei = k; break;}
			if(bub->index[z>>1] != bid) break;
		}
		
		if(ei > si) {////found a bubble
			// fprintf(stderr, "+(2)i::%lu, si::%u, ei::%u, ref_id::%u\nn", i, si, ei, a[i].u>>1);
			p.qn = q->bb.a[si].aidx; p.qs = qsidx; p.qe = qeidx; 
        	p.tn = a[i].u>>1; p.ts = si; p.te = ei; 
        	p.rev = (qrev == trev?0:1); 
			kv_push(ul_ov_t, *res, p);
			nn++;
		}
	}


	v = sink; w = beg^1; trev = 1;
	a = get_r_ug_region(uref->r_ug, &a_n, v>>1);
	// fprintf(stderr, "-a_n::%lu\n", a_n);
	for (i = 0; i < a_n; i++) {
		if((a[i].u&1) != (v&1)) continue;
		if((a[i].u>>1) == avoid_id) continue;
		q = &(ref_sc->a[a[i].u>>1]); si = ei = a[i].off; 
		assert((q->bb.a[si].hid == (v>>1)) && (q->bb.a[si].rev == (v&1)));
		for (k = tn = 0; k < q->bb.n; k++) tn += q->bb.a[k].te - q->bb.a[k].ts;
		for (k = si + 1; (k < tn) && (q->bb.a[k].aidx == q->bb.a[si].aidx); k++) {
			z = (((uint32_t)q->bb.a[k].hid)<<1)|((uint32_t)q->bb.a[k].rev);
			if(z == w) {ei = k; break;}
			if(bub->index[z>>1] != bid) break;
		}

		if(ei > si) {////found a bubble
			// fprintf(stderr, "-(2)i::%lu, si::%u, ei::%u, ref_id::%u\nn", i, si, ei, a[i].u>>1);
			p.qn = q->bb.a[si].aidx; p.qs = qsidx; p.qe = qeidx; 
        	p.tn = a[i].u>>1; p.ts = si; p.te = ei; 
        	p.rev = (qrev == trev?0:1); 
			kv_push(ul_ov_t, *res, p);
			nn++;
		}
	}
	
	return nn;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %r9, %r14
movq %r8, %rsi
movq %rdx, 0x58(%rsp)
movq %rdi, %r15
movq $0x0, (%rsp)
xorl %ebp, %ebp
leaq 0x54(%rsp), %r13
leaq 0x50(%rsp), %rbx
movq %rcx, 0x60(%rsp)
movq %rcx, %rdi
movq %r8, 0x38(%rsp)
movq %r13, %rdx
movq %rbx, %rcx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x13812e
movl (%r13), %r12d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, %r12
sete %al
movl (%rbx), %r8d
cmpl $-0x1, %r8d
sete %cl
orb %al, %cl
jne 0x1cd7fc
movq 0xb8(%rsp), %rax
movq 0xb0(%rsp), %rsi
movq 0x30(%rax), %rax
leaq (%r14,%r14,8), %rcx
movl (%rax,%rcx,4), %edx
movl 0x20(%rax,%rcx,4), %ecx
shrl $0x5, %ecx
andl $0x1, %ecx
leal (%rcx,%rdx,2), %edx
leaq (%rsi,%rsi,8), %rcx
movl (%rax,%rcx,4), %esi
movl 0x20(%rax,%rcx,4), %eax
shrl $0x5, %eax
andl $0x1, %eax
leal (%rax,%rsi,2), %esi
movl %edx, %ecx
xorl %r12d, %ecx
movl %esi, %edi
xorl %r8d, %edi
xorl $0x1, %edi
xorl %eax, %eax
orl %ecx, %edi
setne %cl
xorl %r8d, %edx
xorl %r12d, %esi
xorl $0x1, %esi
orl %edx, %esi
setne 0x8(%rsp)
movq %r14, %r10
je 0x1cd335
testb %cl, %cl
jne 0x1cd84c
movq 0x28(%r15), %rdi
movl %r12d, %r9d
shrl %r9d
movq (%rdi), %rsi
movl (%rsi,%r9,4), %edx
movq %r9, 0x30(%rsp)
movl 0x4(%rsi,%r9,4), %esi
movq $0x0, 0x10(%rsp)
movl %esi, %r9d
subl %edx, %r9d
movq 0x38(%rsp), %r11
movq %r15, 0x70(%rsp)
movl %r8d, 0x40(%rsp)
jne 0x1cd375
xorl %r8d, %r8d
jmp 0x1cd381
leaq (%rdx,%rdx,2), %r8
shlq $0x2, %r8
addq 0x18(%rdi), %r8
movq 0xc8(%rsp), %r13
movl 0xc0(%rsp), %ebp
movl $0x0, %edi
movq %rdi, 0x28(%rsp)
cmpl %edx, %esi
je 0x1cd5b3
andl $0x1, %r12d
movb %cl, %al
shll $0x1f, %eax
cmpb $0x0, 0x8(%rsp)
movl $0x80000000, %ecx       # imm = 0x80000000
cmovnel %eax, %ecx
movl %ecx, 0xc(%rsp)
cmpl $0x1, %r9d
adcl $0x0, %r9d
movq $0x0, 0x28(%rsp)
xorl %r14d, %r14d
movq $0x0, 0x10(%rsp)
movq %r9, 0x20(%rsp)
movq %r8, 0x18(%rsp)
leaq (%r14,%r14,2), %rax
movl (%r8,%rax,4), %r15d
movl %r15d, %ecx
andl $0x1, %ecx
cmpl %r12d, %ecx
jne 0x1cd5a7
shrl %r15d
cmpl %ebp, %r15d
je 0x1cd5a7
leaq (%r8,%rax,4), %rax
movq 0x58(%rsp), %rcx
movq (%rcx), %rdx
movl 0x4(%rax), %ebx
imulq $0x58, %r15, %rsi
movq 0x30(%rdx,%rsi), %rax
leaq (%rbx,%rbx,8), %rcx
movq 0x30(%rsp), %rdi
cmpl %edi, (%rax,%rcx,4)
jne 0x1cd80e
leaq (%rax,%rcx,4), %rdi
btl $0x5, 0x20(%rdi)
movl %r12d, %edi
sbbl $0x0, %edi
jne 0x1cd80e
addq %rsi, %rdx
addq $0x20, %rdx
movq (%rdx), %rsi
testq %rsi, %rsi
je 0x1cd46a
leaq 0x10(%rax), %rdi
xorl %edx, %edx
addl (%rdi), %edx
subl -0x4(%rdi), %edx
addq $0x24, %rdi
decq %rsi
jne 0x1cd45a
jmp 0x1cd46c
xorl %edx, %edx
leal 0x1(%rbx), %esi
movl %ebx, %ebp
cmpl %edx, %esi
jae 0x1cd4d9
movl %edx, %edx
movl %esi, %ebp
movl 0x1c(%rax,%rcx,4), %esi
leaq (,%rbp,8), %rdi
addq %rbp, %rdi
leaq (%rax,%rdi,4), %rdi
addq $0x20, %rdi
cmpl %esi, -0x4(%rdi)
jne 0x1cd4d7
movl -0x20(%rdi), %r8d
movl (%rdi), %r9d
shrl $0x5, %r9d
andl $0x1, %r9d
leal (%r9,%r8,2), %r9d
xorl 0x40(%rsp), %r9d
cmpl $0x1, %r9d
je 0x1cd4d9
movq 0x60(%rsp), %r9
movq (%r9), %r9
andl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
movl (%r9,%r8,4), %r8d
cmpq %r11, %r8
jne 0x1cd4d7
incq %rbp
addq $0x24, %rdi
cmpq %rdx, %rbp
jb 0x1cd490
movl %ebx, %ebp
cmpl %ebx, %ebp
jbe 0x1cd596
movl 0x1c(%rax,%rcx,4), %edi
movq 0x10(%r13), %rax
cmpq %rax, 0x8(%r13)
jne 0x1cd536
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x10(%r13)
movl %edi, 0x4c(%rsp)
movq (%r13), %rdi
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rsi
addq %rcx, %rsi
movq %r10, %r13
callq 0x2370
movl 0x4c(%rsp), %edi
movq 0x38(%rsp), %r11
movq %r13, %r10
movq 0xc8(%rsp), %r13
movq %rax, (%r13)
movq 0x28(%rsp), %rsi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
orl 0xc(%rsp), %esi
movq (%r13), %rax
movq 0x8(%r13), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r13)
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
movl %edi, (%rax,%rdx)
movl %r10d, 0x4(%rax,%rdx)
movq 0xb0(%rsp), %rcx
movl %ecx, 0x8(%rax,%rdx)
movl %r15d, 0xc(%rax,%rdx)
movl %ebx, 0x10(%rax,%rdx)
movl %ebp, 0x14(%rax,%rdx)
movq %rsi, 0x28(%rsp)
movl %esi, 0x18(%rax,%rdx)
movq 0x10(%rsp), %rax
incl %eax
movq %rax, 0x10(%rsp)
movl 0xc0(%rsp), %ebp
movq 0x20(%rsp), %r9
movq 0x18(%rsp), %r8
incq %r14
cmpq %r9, %r14
jne 0x1cd3e3
movl 0x50(%rsp), %r8d
movq 0x70(%rsp), %rax
movq 0x28(%rax), %rdx
movl %r8d, %esi
shrl %esi
movq (%rdx), %rcx
movl (%rcx,%rsi,4), %eax
movq %rsi, 0x40(%rsp)
movl 0x4(%rcx,%rsi,4), %ecx
movl %ecx, %esi
subl %eax, %esi
jne 0x1cd5df
xorl %edi, %edi
jmp 0x1cd5eb
leaq (%rax,%rax,2), %rdi
shlq $0x2, %rdi
addq 0x18(%rdx), %rdi
cmpl %eax, %ecx
je 0x1cd7f8
movl 0x54(%rsp), %r13d
andl $0x1, %r8d
xorl %eax, %eax
movb 0x8(%rsp), %cl
movb %cl, %al
shll $0x1f, %eax
movl %eax, 0xc(%rsp)
cmpl $0x1, %esi
adcl $0x0, %esi
xorl %r14d, %r14d
movl %r8d, 0x30(%rsp)
movq %rsi, 0x20(%rsp)
movq %rdi, 0x18(%rsp)
movq %r10, 0x68(%rsp)
leaq (%r14,%r14,2), %rax
movl (%rdi,%rax,4), %r15d
movl %r15d, %ecx
andl $0x1, %ecx
cmpl %r8d, %ecx
jne 0x1cd7ec
shrl %r15d
cmpl %ebp, %r15d
je 0x1cd7ec
leaq (%rdi,%rax,4), %rax
movq 0x58(%rsp), %rcx
movq (%rcx), %rdx
movl 0x4(%rax), %ebx
imulq $0x58, %r15, %rsi
movq 0x30(%rdx,%rsi), %rax
leaq (%rbx,%rbx,8), %rcx
movq 0x40(%rsp), %rdi
cmpl %edi, (%rax,%rcx,4)
jne 0x1cd82d
leaq (%rax,%rcx,4), %rdi
btl $0x5, 0x20(%rdi)
movl %r8d, %edi
sbbl $0x0, %edi
jne 0x1cd82d
addq %rsi, %rdx
addq $0x20, %rdx
movq (%rdx), %rsi
testq %rsi, %rsi
je 0x1cd6af
leaq 0x10(%rax), %rdi
xorl %edx, %edx
addl (%rdi), %edx
subl -0x4(%rdi), %edx
addq $0x24, %rdi
decq %rsi
jne 0x1cd69f
jmp 0x1cd6b1
xorl %edx, %edx
leal 0x1(%rbx), %esi
movl %ebx, %r12d
cmpl %edx, %esi
jae 0x1cd718
movl %edx, %edx
movl %esi, %r12d
movl 0x1c(%rax,%rcx,4), %esi
leaq (%r12,%r12,8), %rdi
leaq (%rax,%rdi,4), %rdi
addq $0x20, %rdi
cmpl %esi, -0x4(%rdi)
jne 0x1cd715
movl -0x20(%rdi), %r8d
movl (%rdi), %r9d
shrl $0x5, %r9d
andl $0x1, %r9d
leal (%r9,%r8,2), %r9d
xorl %r13d, %r9d
cmpl $0x1, %r9d
je 0x1cd718
movq 0x60(%rsp), %r9
movq (%r9), %r9
andl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
movl (%r9,%r8,4), %r8d
cmpq %r11, %r8
jne 0x1cd715
incq %r12
addq $0x24, %rdi
cmpq %rdx, %r12
jb 0x1cd6d0
movl %ebx, %r12d
cmpl %ebx, %r12d
jbe 0x1cd7dd
movl 0x1c(%rax,%rcx,4), %edi
movq 0xc8(%rsp), %rbp
movq 0x10(%rbp), %rax
cmpq %rax, 0x8(%rbp)
jne 0x1cd775
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x10(%rbp)
movl %edi, 0x8(%rsp)
movq (%rbp), %rdi
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rsi
addq %rcx, %rsi
callq 0x2370
movl 0x8(%rsp), %edi
movq 0x38(%rsp), %r11
movq 0x68(%rsp), %r10
movq %rax, (%rbp)
movq 0x28(%rsp), %rsi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
orl 0xc(%rsp), %esi
movq (%rbp), %rax
movq 0x8(%rbp), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%rbp)
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
movl %edi, (%rax,%rdx)
movl %r10d, 0x4(%rax,%rdx)
movq 0xb0(%rsp), %rcx
movl %ecx, 0x8(%rax,%rdx)
movl %r15d, 0xc(%rax,%rdx)
movl %ebx, 0x10(%rax,%rdx)
movl %r12d, 0x14(%rax,%rdx)
movq %rsi, 0x28(%rsp)
movl %esi, 0x18(%rax,%rdx)
movq 0x10(%rsp), %rax
incl %eax
movq %rax, 0x10(%rsp)
movl 0xc0(%rsp), %ebp
movl 0x30(%rsp), %r8d
movq 0x20(%rsp), %rsi
movq 0x18(%rsp), %rdi
incq %r14
cmpq %rsi, %r14
jne 0x1cd628
movl 0x10(%rsp), %ebp
movq %rbp, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x69aac(%rip), %rdi     # 0x2372c1
leaq 0x6616f(%rip), %rsi     # 0x23398b
leaq 0x69a0e(%rip), %rcx     # 0x237231
movl $0x4108, %edx           # imm = 0x4108
callq 0x2110
leaq 0x69a8d(%rip), %rdi     # 0x2372c1
leaq 0x66150(%rip), %rsi     # 0x23398b
leaq 0x699ef(%rip), %rcx     # 0x237231
movl $0x4123, %edx           # imm = 0x4123
callq 0x2110
leaq 0x699c9(%rip), %rdi     # 0x23721c
leaq 0x66131(%rip), %rsi     # 0x23398b
leaq 0x699d0(%rip), %rcx     # 0x237231
movl $0x40fd, %edx           # imm = 0x40FD
callq 0x2110