// File: /workspace/github_cpp_makefile_star2_O3/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 0x1d7e4c
movl %r9d, %ebx
movq 0x98(%rsp), %rdi
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 0x1d7ceb
movq (%rsp), %rax
leaq (%rax,%rax,2), %rax
shlq $0x4, %rax
movq 0x8(%rsp), %rcx
testb $0x3e, 0x28(%rcx,%rax)
jne 0x1d7e36
movq 0x30(%rsp), %rax
movq 0x28(%rax), %rcx
movq (%rsp), %rax
leaq (%rax,%rax,2), %r12
shlq $0x4, %r12
movq 0x8(%rsp), %rax
movl 0x14(%rax,%r12), %eax
movq (%rcx), %rsi
movl (%rsi,%rax,4), %edx
movl 0x4(%rsi,%rax,4), %eax
cmpl %edx, %eax
je 0x1d7e36
leaq (%rdx,%rdx,2), %r15
shlq $0x2, %r15
addq 0x18(%rcx), %r15
addq 0x8(%rsp), %r12
subl %edx, %eax
cmpl $0x1, %eax
adcl $0x0, %eax
shlq $0x2, %rax
leaq (%rax,%rax,2), %r13
xorl %ebp, %ebp
movl (%r15,%rbp), %eax
shrl %eax
cmpl %ebx, %eax
je 0x1d7e29
movq 0x48(%rsp), %rcx
movq (%rcx), %rdx
imulq $0x58, %rax, %rax
movl 0x4(%r15,%rbp), %ecx
leaq (%rcx,%rcx,8), %rcx
shlq $0x2, %rcx
addq 0x30(%rdx,%rax), %rcx
movq %rdi, %r14
movq 0x50(%rsp), %rdi
movq %r12, %rsi
movq 0x40(%rsp), %rdx
leaq 0x10(%rsp), %r8
callq 0x1d7b65
movq %r14, %rdi
testq %rax, %rax
je 0x1d7e29
movl (%r15,%rbp), %eax
shrl %eax
movl %eax, 0x1c(%rsp)
movzbl 0x28(%r12), %eax
andl $0x3f, %eax
movl %eax, 0x10(%rsp)
cvttsd2si 0x20(%r12), %rax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movl 0x28(%rsp), %ecx
movl $0x80000000, %edx       # imm = 0x80000000
andl %edx, %ecx
orl %eax, %ecx
movl %ecx, 0x28(%rsp)
movq (%rdi), %rax
movq 0x8(%rdi), %rcx
cmpq 0x10(%rdi), %rcx
jne 0x1d7e03
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rdx
movq %rdx, 0x10(%rdi)
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rsi
addq %rdx, %rsi
movq %rax, %rdi
callq 0x2370
movq %r14, %rdi
movq %rax, (%r14)
movq 0x8(%r14), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%rdi)
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, %rbp
cmpq %rbp, %r13
jne 0x1d7d3f
movq (%rsp), %rcx
incq %rcx
movq %rcx, (%rsp)
cmpq 0x38(%rsp), %rcx
jne 0x1d7cc5
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq