// File: chhylp123[P]hifiasm/inter.cpp
// Function: extract_scaf_res_t(uc_block_t*, ul_idx_t const*, scaf_res_t*, unsigned int, kv_ul_ov_t*)
uint64_t extract_scaf_res_t(uc_block_t *in, const ul_idx_t *uref, scaf_res_t *ref_sc, uint32_t avid, kv_ul_ov_t *res)
{
	utg_rid_dt *a; uint64_t i, a_n, nn, nw; uc_block_t *ou; ul_ov_t p; memset(&p, 0, sizeof(p));
	a = get_r_ug_region(uref->r_ug, &a_n, in->hid);
    for (i = nn = 0; i < a_n; i++) {
		if((a[i].u>>1) == avid) continue;
		ou = &(ref_sc->a[a[i].u>>1].bb.a[a[i].off]);
		p.qn = (uint32_t)-1; p.qs = in->qs; p.qe = in->qe;
		p.tn = a[i].u>>1; p.ts = ou->qs; p.te = ou->qe; 
		p.el = 1; p.rev = ((in->rev == ou->rev)?0:1);
		nw = MAX(p.te-p.ts, p.qe-p.qs); nw *= CHAIN_MATCH; 
		p.sec = ((nw>=0x3fffffff)?(0x3fffffff):(nw));
		kv_push(ul_ov_t, *res, p);

		nn++;
    }
	return nn;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
leaq -0x74(%rbp), %rdi
xorl %esi, %esi
movl $0x1c, %edx
callq 0x2100
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x8(%rbp), %rax
movl (%rax), %eax
movl %eax, %edx
leaq -0x40(%rbp), %rsi
callq 0x2cf9e0
movq %rax, -0x30(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
jae 0x2e03e7
movq -0x30(%rbp), %rax
imulq $0xc, -0x38(%rbp), %rcx
addq %rcx, %rax
movl (%rax), %eax
shrl %eax
cmpl -0x1c(%rbp), %eax
jne 0x2e01e3
jmp 0x2e03d6
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rcx
imulq $0xc, -0x38(%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 -0x30(%rbp), %rcx
imulq $0xc, -0x38(%rbp), %rdx
addq %rdx, %rcx
movl 0x4(%rcx), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movl $0xffffffff, -0x74(%rbp) # imm = 0xFFFFFFFF
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x70(%rbp)
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x6c(%rbp)
movq -0x30(%rbp), %rax
imulq $0xc, -0x38(%rbp), %rcx
addq %rcx, %rax
movl (%rax), %eax
shrl %eax
movl %eax, -0x68(%rbp)
movq -0x58(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x64(%rbp)
movq -0x58(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x60(%rbp)
movl -0x5c(%rbp), %eax
andl $0xbfffffff, %eax       # imm = 0xBFFFFFFF
orl $0x40000000, %eax       # imm = 0x40000000
movl %eax, -0x5c(%rbp)
movq -0x8(%rbp), %rax
movb 0x20(%rax), %al
shrb $0x5, %al
andb $0x1, %al
movzbl %al, %edx
movq -0x58(%rbp), %rax
movb 0x20(%rax), %al
shrb $0x5, %al
andb $0x1, %al
movzbl %al, %esi
movl $0x1, %ecx
xorl %eax, %eax
cmpl %esi, %edx
cmovel %eax, %ecx
movl -0x5c(%rbp), %eax
andl $0x1, %ecx
shll $0x1f, %ecx
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
orl %ecx, %eax
movl %eax, -0x5c(%rbp)
movl -0x60(%rbp), %eax
subl -0x64(%rbp), %eax
movl -0x6c(%rbp), %ecx
subl -0x70(%rbp), %ecx
cmpl %ecx, %eax
jb 0x2e02cb
movl -0x60(%rbp), %eax
subl -0x64(%rbp), %eax
movl %eax, -0x78(%rbp)
jmp 0x2e02d4
movl -0x6c(%rbp), %eax
subl -0x70(%rbp), %eax
movl %eax, -0x78(%rbp)
movl -0x78(%rbp), %eax
movl %eax, %eax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
shlq $0x0, %rax
movq %rax, -0x50(%rbp)
cmpq $0x3fffffff, -0x50(%rbp) # imm = 0x3FFFFFFF
jb 0x2e02fe
movl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movq %rax, -0x80(%rbp)
jmp 0x2e0306
movq -0x50(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
movl %eax, %ecx
movl -0x5c(%rbp), %eax
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
andl $0xc0000000, %eax       # imm = 0xC0000000
orl %ecx, %eax
movl %eax, -0x5c(%rbp)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x28(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x2e038c
movq -0x28(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x2e0350
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
shlq %rax
movq %rax, -0x88(%rbp)
jmp 0x2e035e
movl $0x2, %eax
movq %rax, -0x88(%rbp)
jmp 0x2e035e
movq -0x88(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x28(%rbp), %rax
movq (%rax), %rdi
movq -0x28(%rbp), %rax
imulq $0x1c, 0x10(%rax), %rsi
callq 0x2360
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x28(%rbp), %rdx
movq 0x8(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x8(%rdx)
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movq -0x74(%rbp), %rcx
movq %rcx, (%rax)
movq -0x6c(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x64(%rbp), %rcx
movq %rcx, 0x10(%rax)
movl -0x5c(%rbp), %ecx
movl %ecx, 0x18(%rax)
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x2e01bb
movq -0x48(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)