// File: 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
movq %rsp, %rbp
subq $0x90, %rsp
movq 0x18(%rbp), %rax
movl 0x10(%rbp), %eax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
leaq -0x84(%rbp), %rdi
xorl %esi, %esi
movl $0x1c, %edx
callq 0x2100
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x28(%rbp), %rcx
movq 0x28(%rcx), %rcx
movq -0x8(%rbp), %rdx
movl (%rdx), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x8(%rbp), %rcx
movl (%rcx), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
movq %rax, -0x68(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x68(%rbp), %rax
jae 0x2e09af
cmpl $0x0, 0x10(%rbp)
je 0x2e07b1
movq -0x58(%rbp), %rax
imulq $0x30, -0x60(%rbp), %rcx
addq %rcx, %rax
movb 0x28(%rax), %al
andb $0x3f, %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0x2e07b1
movq -0x58(%rbp), %rax
imulq $0x30, -0x60(%rbp), %rcx
addq %rcx, %rax
movb 0x28(%rax), %al
andb $0x3f, %al
movzbl %al, %eax
cmpl $0x1, %eax
je 0x2e07b1
jmp 0x2e099e
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x58(%rbp), %rax
imulq $0x30, -0x60(%rbp), %rcx
addq %rcx, %rax
movl 0x14(%rax), %eax
movl %eax, %edx
leaq -0x48(%rbp), %rsi
callq 0x2cf9e0
movq %rax, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x48(%rbp), %rax
jae 0x2e099c
movq -0x38(%rbp), %rax
imulq $0xc, -0x40(%rbp), %rcx
addq %rcx, %rax
movl (%rax), %eax
shrl %eax
cmpl -0x2c(%rbp), %eax
jne 0x2e0807
jmp 0x2e098b
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x38(%rbp), %rcx
imulq $0xc, -0x40(%rbp), %rdx
addq %rdx, %rcx
movl (%rcx), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x58, %rcx, %rcx
addq %rcx, %rax
movq 0x30(%rax), %rax
movq -0x38(%rbp), %rcx
imulq $0xc, -0x40(%rbp), %rdx
addq %rdx, %rcx
movl 0x4(%rcx), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x20(%rbp), %rdi
movq -0x58(%rbp), %rsi
imulq $0x30, -0x60(%rbp), %rax
addq %rax, %rsi
movq -0x8(%rbp), %rdx
movq -0x50(%rbp), %rcx
leaq -0x84(%rbp), %r8
callq 0x2e0400
cmpq $0x0, %rax
je 0x2e0989
movq -0x38(%rbp), %rax
movq -0x40(%rbp), %rcx
leaq (%rcx,%rcx,2), %rcx
movl (%rax,%rcx,4), %eax
shrl %eax
movl %eax, -0x78(%rbp)
movq -0x58(%rbp), %rax
movq -0x60(%rbp), %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x4, %rcx
movzbl 0x28(%rax,%rcx), %eax
andl $0x3f, %eax
movl %eax, -0x84(%rbp)
movb -0x69(%rbp), %al
andb $-0x41, %al
movb %al, -0x69(%rbp)
movq -0x58(%rbp), %rax
movq -0x60(%rbp), %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x4, %rcx
cvttsd2si 0x20(%rax,%rcx), %rax
movl %eax, %ecx
movl -0x6c(%rbp), %eax
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
andl $0xc0000000, %eax       # imm = 0xC0000000
orl %ecx, %eax
movl %eax, -0x6c(%rbp)
movq 0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x18(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x2e0946
movq 0x18(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x2e090a
movq 0x18(%rbp), %rax
movq 0x10(%rax), %rax
shlq %rax
movq %rax, -0x90(%rbp)
jmp 0x2e0918
movl $0x2, %eax
movq %rax, -0x90(%rbp)
jmp 0x2e0918
movq -0x90(%rbp), %rcx
movq 0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movq 0x18(%rbp), %rax
movq (%rax), %rdi
movq 0x18(%rbp), %rax
imulq $0x1c, 0x10(%rax), %rsi
callq 0x2360
movq %rax, %rcx
movq 0x18(%rbp), %rax
movq %rcx, (%rax)
movq 0x18(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rbp), %rdx
movq 0x8(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x8(%rdx)
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movq -0x84(%rbp), %rcx
movq %rcx, (%rax)
movq -0x7c(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x74(%rbp), %rcx
movq %rcx, 0x10(%rax)
movl -0x6c(%rbp), %ecx
movl %ecx, 0x18(%rax)
jmp 0x2e0989
jmp 0x2e098b
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x2e07df
jmp 0x2e099e
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x2e0766
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax,%rax)