// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/inter.cpp
// Function: extract_trans_scaf_res_t(uc_block_t*, ul_idx_t const*, scaf_res_t*, ma_ug_t*, kv_u_trans_t*, unsigned int, unsigned int, kv_ul_ov_t*)
void extract_trans_scaf_res_t(uc_block_t *qin, const ul_idx_t *uref, scaf_res_t *ref_sc, ma_ug_t *gfa, kv_u_trans_t *ta, uint32_t avid, uint32_t is_exact, kv_ul_ov_t *res)
{
	utg_rid_dt *a; uint64_t i, a_n; uc_block_t *rin; 
	u_trans_t *u; uint64_t k, u_n;
	ul_ov_t p; memset(&p, 0, sizeof(p));

	// fprintf(stderr, "\n[M::%s] utg%.6u%c, [%u, %u)\n", __func__, qin->hid+1, "lc"[gfa->u.a[qin->hid].circ], qin->qs, qin->qe);
	u = u_trans_a(*ta, qin->hid); 
	u_n = u_trans_n(*ta, qin->hid);
	for (k = 0; k < u_n; k++) {
		if(is_exact && u[k].f != RC_0 && u[k].f != RC_1) continue;
		// fprintf(stderr, "+[M::%s] utg%.6u%c->utg%.6u%c, q::[%u, %u), %c, t::[%u, %u)\n", __func__, qin->hid+1, "lc"[gfa->u.a[qin->hid].circ], u[k].tn+1, "lc"[gfa->u.a[u[k].tn].circ], u[k].qs, u[k].qe, "+-"[u[k].rev], u[k].ts, u[k].te);
		a = get_r_ug_region(uref->r_ug, &a_n, u[k].tn);
    	for (i = 0; i < a_n; i++) {
			if((a[i].u>>1) == avid) continue;
			rin = &(ref_sc->a[a[i].u>>1].bb.a[a[i].off]);
			if(gen_trans_ovlp_scaf(gfa, &(u[k]), qin, rin, &p)) {
				p.tn = a[i].u>>1; p.qn = u[k].f; p.el = 0; p.sec = u[k].nw;
				kv_push(ul_ov_t, *res, p);

				// fprintf(stderr, "-[M::%s] q::[%u, %u), %c, t::[%u, %u), qin->qs::%u, rin->qs::%u\n", __func__, p.qs, p.qe, "+-"[p.rev], p.ts, p.te, qin->qs, rin->qs);
			}
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rcx, 0x50(%rsp)
movq %rdx, 0x48(%rsp)
movq %rsi, 0x30(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x1c(%rsp)
movaps %xmm0, 0x10(%rsp)
movq 0x28(%r8), %rax
movq %rdi, 0x40(%rsp)
movl (%rdi), %ecx
movq (%rax,%rcx,8), %rax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
andq %rax, %rcx
movq %rcx, 0x38(%rsp)
je 0x1cdea5
movl %r9d, %ebx
movq 0x98(%rsp), %rbp
shrq $0x20, %rax
leaq (%rax,%rax,2), %rax
shlq $0x4, %rax
addq 0x10(%r8), %rax
movq %rax, 0x8(%rsp)
movq $0x0, (%rsp)
cmpl $0x0, 0x90(%rsp)
je 0x1cdd35
movq (%rsp), %rax
leaq (%rax,%rax,2), %rax
shlq $0x4, %rax
movq 0x8(%rsp), %rcx
testb $0x3e, 0x28(%rcx,%rax)
jne 0x1cde8f
movq 0x30(%rsp), %rax
movq 0x28(%rax), %rsi
movq (%rsp), %rax
leaq (%rax,%rax,2), %r12
shlq $0x4, %r12
movq 0x8(%rsp), %rax
movl 0x14(%rax,%r12), %eax
movq (%rsi), %rdx
movl (%rdx,%rax,4), %ecx
movl 0x4(%rdx,%rax,4), %edx
movl %edx, %eax
subl %ecx, %eax
jne 0x1cdd69
xorl %r15d, %r15d
jmp 0x1cdd75
leaq (%rcx,%rcx,2), %r15
shlq $0x2, %r15
addq 0x18(%rsi), %r15
cmpl %ecx, %edx
je 0x1cde8f
addq 0x8(%rsp), %r12
cmpl $0x1, %eax
adcl $0x0, %eax
shlq $0x2, %rax
leaq (%rax,%rax,2), %r13
xorl %r14d, %r14d
movl (%r15,%r14), %eax
shrl %eax
cmpl %ebx, %eax
je 0x1cde82
movq 0x48(%rsp), %rcx
movq (%rcx), %rdx
imulq $0x58, %rax, %rax
movl 0x4(%r15,%r14), %ecx
leaq (%rcx,%rcx,8), %rcx
shlq $0x2, %rcx
addq 0x30(%rdx,%rax), %rcx
movq 0x50(%rsp), %rdi
movq %r12, %rsi
movq 0x40(%rsp), %rdx
leaq 0x10(%rsp), %r8
callq 0x1cdbaf
testq %rax, %rax
je 0x1cde82
movl (%r15,%r14), %eax
shrl %eax
movl %eax, 0x1c(%rsp)
movzbl 0x28(%r12), %eax
andl $0x3f, %eax
movl %eax, 0x10(%rsp)
movl 0x28(%rsp), %eax
movl %eax, %ecx
andl $0xbfffffff, %ecx       # imm = 0xBFFFFFFF
movl %ecx, 0x28(%rsp)
cvttsd2si 0x20(%r12), %rcx
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
andl $0x80000000, %eax       # imm = 0x80000000
orl %ecx, %eax
movl %eax, 0x28(%rsp)
movq 0x10(%rbp), %rax
cmpq %rax, 0x8(%rbp)
jne 0x1cde54
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x10(%rbp)
movq (%rbp), %rdi
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rsi
addq %rcx, %rsi
callq 0x2370
movq %rax, (%rbp)
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
movups 0x1c(%rsp), %xmm0
movups %xmm0, 0xc(%rax,%rdx)
movaps 0x10(%rsp), %xmm0
movups %xmm0, (%rax,%rdx)
addq $0xc, %r14
cmpq %r14, %r13
jne 0x1cdd93
movq (%rsp), %rcx
incq %rcx
movq %rcx, (%rsp)
cmpq 0x38(%rsp), %rcx
jne 0x1cdd0f
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq