// File: /workspace/github_cpp_makefile_star2_O2/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 $0x88, %rsp
movq %r9, %r14
movq %r8, %rsi
movq %rdx, 0x48(%rsp)
movq %rdi, %r15
andq $0x0, (%rsp)
xorl %ebp, %ebp
leaq 0x74(%rsp), %rbx
leaq 0x70(%rsp), %r13
movq %rcx, 0x50(%rsp)
movq %rcx, %rdi
movq %r8, 0x58(%rsp)
movq %rbx, %rdx
movq %r13, %rcx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0xf6ab5
movl (%rbx), %r9d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, %r9
sete %al
movl (%r13), %r8d
cmpl $-0x1, %r8d
sete %cl
orb %al, %cl
jne 0x18ac81
movq 0xc8(%rsp), %rax
movq 0x30(%rax), %rax
imulq $0x24, %r14, %rcx
movl (%rax,%rcx), %edx
movl 0x20(%rax,%rcx), %ecx
shrl $0x5, %ecx
andl $0x1, %ecx
leal (%rcx,%rdx,2), %edx
imulq $0x24, 0xc0(%rsp), %rcx
movl (%rax,%rcx), %esi
movl 0x20(%rax,%rcx), %eax
shrl $0x5, %eax
andl $0x1, %eax
leal (%rax,%rsi,2), %esi
movl %edx, %ecx
xorl %r9d, %ecx
movl %esi, %edi
xorl %r8d, %edi
xorl $0x1, %edi
xorl %eax, %eax
orl %ecx, %edi
setne %cl
movl %r8d, 0x60(%rsp)
xorl %r8d, %edx
xorl %r9d, %esi
xorl $0x1, %esi
orl %edx, %esi
setne %bl
movq %r14, %r8
movq %r9, %r14
je 0x18a82f
testb %cl, %cl
jne 0x18acd4
movq 0x28(%r15), %rdx
movl %r14d, %r9d
shrl %r9d
movq (%rdx), %rdi
movl (%rdi,%r9,4), %esi
movq %r9, 0x38(%rsp)
movl 0x4(%rdi,%r9,4), %r13d
movq $0x0, 0x40(%rsp)
subl %esi, %r13d
movq 0x58(%rsp), %r9
movq 0x50(%rsp), %r10
movq 0x48(%rsp), %r11
movq %r15, 0x80(%rsp)
jne 0x18a873
xorl %esi, %esi
jmp 0x18a87b
imulq $0xc, %rsi, %rsi
addq 0x18(%rdx), %rsi
andl $0x1, %r14d
movb %cl, %al
shll $0x1f, %eax
movb %bl, 0x17(%rsp)
testb %bl, %bl
movl $0x80000000, %ecx       # imm = 0x80000000
cmovnel %eax, %ecx
movl %ecx, 0x6c(%rsp)
movl 0xd0(%rsp), %r15d
xorl %ebp, %ebp
movl $0x0, 0x2c(%rsp)
movq %r8, 0x78(%rsp)
movq %r14, 0x20(%rsp)
movq %r13, 0x18(%rsp)
movq %rsi, 0x30(%rsp)
cmpq %r13, %rbp
je 0x18aa6b
imulq $0xc, %rbp, %rax
movl (%rsi,%rax), %ebx
movl %ebx, %ecx
andl $0x1, %ecx
cmpl %r14d, %ecx
jne 0x18aa63
shrl %ebx
cmpl %r15d, %ebx
je 0x18aa63
addq %rsi, %rax
movq (%r11), %rsi
movl 0x4(%rax), %r12d
imulq $0x58, %rbx, %rax
movq 0x30(%rsi,%rax), %rcx
imulq $0x24, %r12, %rdx
movq 0x38(%rsp), %rdi
cmpl %edi, (%rcx,%rdx)
jne 0x18ac96
leaq (%rcx,%rdx), %rdi
btl $0x5, 0x20(%rdi)
movl %r14d, %edi
sbbl $0x0, %edi
jne 0x18ac96
addq %rsi, %rax
addq $0x20, %rax
movq (%rax), %rsi
leaq 0x10(%rcx), %rdi
xorl %eax, %eax
subq $0x1, %rsi
jb 0x18a940
addl (%rdi), %eax
subl -0x4(%rdi), %eax
addq $0x24, %rdi
jmp 0x18a92f
leal 0x1(%r12), %r13d
movl %eax, %eax
addq %rcx, %rdx
addq $0x1c, %rdx
imulq $0x24, %r13, %rsi
addq %rsi, %rcx
addq $0x20, %rcx
cmpq %rax, %r13
jae 0x18aa54
movl -0x4(%rcx), %r14d
cmpl (%rdx), %r14d
jne 0x18aa54
movl -0x20(%rcx), %esi
movl (%rcx), %edi
shrl $0x5, %edi
andl $0x1, %edi
leal (%rdi,%rsi,2), %edi
xorl 0x60(%rsp), %edi
cmpl $0x1, %edi
je 0x18a9a4
movq (%r10), %rdi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
movl (%rdi,%rsi,4), %esi
cmpq %r9, %rsi
jne 0x18aa54
incq %r13
addq $0x24, %rcx
jmp 0x18a959
cmpl %r13d, %r12d
jae 0x18aa54
movq 0xd8(%rsp), %r15
movq (%r15), %rax
movq 0x8(%r15), %rcx
cmpq 0x10(%r15), %rcx
jne 0x18a9fb
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rdx
movq %rdx, 0x10(%r15)
imulq $0x1c, %rdx, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x48(%rsp), %r11
movq 0x50(%rsp), %r10
movq 0x58(%rsp), %r9
movq 0x78(%rsp), %r8
movq %rax, (%r15)
movq 0x8(%r15), %rcx
movl 0x2c(%rsp), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
orl 0x6c(%rsp), %esi
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r15)
imulq $0x1c, %rcx, %rcx
movl %r14d, (%rax,%rcx)
movl %r8d, 0x4(%rax,%rcx)
movq 0xc0(%rsp), %rdx
movl %edx, 0x8(%rax,%rcx)
movl %ebx, 0xc(%rax,%rcx)
movl %r12d, 0x10(%rax,%rcx)
movl %r13d, 0x14(%rax,%rcx)
movl %esi, 0x2c(%rsp)
movl %esi, 0x18(%rax,%rcx)
movq 0x40(%rsp), %rax
incl %eax
movq %rax, 0x40(%rsp)
movl 0xd0(%rsp), %r15d
movq 0x20(%rsp), %r14
movq 0x18(%rsp), %r13
movq 0x30(%rsp), %rsi
incq %rbp
jmp 0x18a8bc
movl 0x70(%rsp), %r14d
movq 0x80(%rsp), %rax
movq 0x28(%rax), %rax
movl %r14d, %esi
shrl %esi
movq (%rax), %rdx
movl (%rdx,%rsi,4), %ecx
movq %rsi, 0x60(%rsp)
movl 0x4(%rdx,%rsi,4), %edx
subl %ecx, %edx
jne 0x18aa98
xorl %esi, %esi
jmp 0x18aaa0
imulq $0xc, %rcx, %rsi
addq 0x18(%rax), %rsi
movb 0x17(%rsp), %cl
movl 0x74(%rsp), %r12d
andl $0x1, %r14d
xorl %eax, %eax
movb %cl, %al
shll $0x1f, %eax
movl %eax, 0x30(%rsp)
xorl %r13d, %r13d
movl %r14d, 0x38(%rsp)
movq %rdx, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
cmpq %rdx, %r13
je 0x18ac7d
imulq $0xc, %r13, %rax
movl (%rsi,%rax), %ebp
movl %ebp, %ecx
andl $0x1, %ecx
cmpl %r14d, %ecx
jne 0x18ac75
shrl %ebp
cmpl %r15d, %ebp
je 0x18ac75
addq %rsi, %rax
movq (%r11), %rsi
movl 0x4(%rax), %ebx
imulq $0x58, %rbp, %rax
movq 0x30(%rsi,%rax), %rcx
imulq $0x24, %rbx, %rdx
movq 0x60(%rsp), %rdi
cmpl %edi, (%rcx,%rdx)
jne 0x18acb5
leaq (%rcx,%rdx), %rdi
btl $0x5, 0x20(%rdi)
movl %r14d, %edi
sbbl $0x0, %edi
jne 0x18acb5
addq %rsi, %rax
addq $0x20, %rax
movq (%rax), %rsi
leaq 0x10(%rcx), %rdi
xorl %eax, %eax
subq $0x1, %rsi
jb 0x18ab4d
addl (%rdi), %eax
subl -0x4(%rdi), %eax
addq $0x24, %rdi
jmp 0x18ab3c
leal 0x1(%rbx), %r14d
movl %eax, %eax
addq %rcx, %rdx
addq $0x1c, %rdx
imulq $0x24, %r14, %rsi
addq %rsi, %rcx
addq $0x20, %rcx
cmpq %rax, %r14
jae 0x18ac5e
movl -0x4(%rcx), %r15d
cmpl (%rdx), %r15d
jne 0x18ac5e
movl -0x20(%rcx), %esi
movl (%rcx), %edi
shrl $0x5, %edi
andl $0x1, %edi
leal (%rdi,%rsi,2), %edi
xorl %r12d, %edi
cmpl $0x1, %edi
je 0x18abaf
movq (%r10), %rdi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
movl (%rdi,%rsi,4), %esi
cmpq %r9, %rsi
jne 0x18ac5e
incq %r14
addq $0x24, %rcx
jmp 0x18ab65
cmpl %r14d, %ebx
jae 0x18ac5e
movq 0xd8(%rsp), %rdi
movq (%rdi), %rax
movq 0x8(%rdi), %rcx
cmpq 0x10(%rdi), %rcx
jne 0x18ac0e
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rdx
movq %rdx, 0x10(%rdi)
imulq $0x1c, %rdx, %rsi
movq %rax, %rdi
callq 0x2370
movq 0xd8(%rsp), %rdi
movq 0x48(%rsp), %r11
movq 0x50(%rsp), %r10
movq 0x58(%rsp), %r9
movq 0x78(%rsp), %r8
movq %rax, (%rdi)
movq 0x8(%rdi), %rcx
movl 0x2c(%rsp), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
orl 0x30(%rsp), %esi
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%rdi)
imulq $0x1c, %rcx, %rcx
movl %r15d, (%rax,%rcx)
movl %r8d, 0x4(%rax,%rcx)
movq 0xc0(%rsp), %rdx
movl %edx, 0x8(%rax,%rcx)
movl %ebp, 0xc(%rax,%rcx)
movl %ebx, 0x10(%rax,%rcx)
movl %r14d, 0x14(%rax,%rcx)
movl %esi, 0x2c(%rsp)
movl %esi, 0x18(%rax,%rcx)
movq 0x40(%rsp), %rax
incl %eax
movq %rax, 0x40(%rsp)
movl 0xd0(%rsp), %r15d
movl 0x38(%rsp), %r14d
movq 0x20(%rsp), %rdx
movq 0x18(%rsp), %rsi
incq %r13
jmp 0x18aaca
movl 0x40(%rsp), %ebp
movq %rbp, %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6a7bc(%rip), %rdi     # 0x1f5459
leaq 0x66e7f(%rip), %rsi     # 0x1f1b23
leaq 0x6a71e(%rip), %rcx     # 0x1f53c9
movl $0x4108, %edx           # imm = 0x4108
callq 0x2110
leaq 0x6a79d(%rip), %rdi     # 0x1f5459
leaq 0x66e60(%rip), %rsi     # 0x1f1b23
leaq 0x6a6ff(%rip), %rcx     # 0x1f53c9
movl $0x4123, %edx           # imm = 0x4123
callq 0x2110
leaq 0x6a6d9(%rip), %rdi     # 0x1f53b4
leaq 0x66e41(%rip), %rsi     # 0x1f1b23
leaq 0x6a6e0(%rip), %rcx     # 0x1f53c9
movl $0x40fd, %edx           # imm = 0x40FD
callq 0x2110