// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Overlaps.cpp
// Function: get_scaf_res_t(scaf_res_t*, unsigned int, unsigned int, unsigned int, unsigned int*, unsigned int*, unsigned int*, unsigned int*, uc_block_t**)
uint32_t get_scaf_res_t(scaf_res_t *pa, uint32_t uid, uint32_t s, uint32_t e, uint32_t *in, uint32_t *rs, uint32_t *re, uint32_t *rn, uc_block_t **ra)
{
    // fprintf(stderr, "s::%u, e::%u, uid::%u, pa->n::%u\n", s, e, uid, (uint32_t)pa->n);
    if(uid >= pa->n) return 0;
    ul_vec_t *idx = &(pa->a[uid]); uint32_t k, z, a_n, os, oe, z0; uc_block_t *a; 
    (*rs) = (*re) = (uint32_t)-1; (*rn) = 0; (*ra) = NULL;
    
    for (k = (*in); k < idx->bb.n; k++) {
        a = idx->bb.a + idx->bb.a[k].ts; a_n = idx->bb.a[k].te - idx->bb.a[k].ts;
        os = MAX(s, idx->bb.a[k].qs); 
        oe = MIN(e, idx->bb.a[k].qe);
        // fprintf(stderr, "k::%u, os::%u, oe::%u, a_n::%u\n", k, os, oe, a_n);
        if(os >= oe) continue;
        for(z = 0; z < a_n && a[z].qe <= os; z++);
        if(z >= a_n) continue;
        for(z0 = z; z < a_n && a[z].qs < oe; z++);
        if(z <= z0 ) continue;
        *rs = os; *re = oe; *rn = z - z0; *ra = a + z0; (*in) = k + 1;
        return 1;
    }
    return 0;
}

// Assembly:
movl %esi, %esi
xorl %eax, %eax
cmpq %rsi, 0x8(%rdi)
jbe 0xda97b
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq 0x48(%rsp), %r11
movq 0x40(%rsp), %rbx
movq 0x38(%rsp), %r14
movq (%rdi), %r10
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
movl %edi, (%r14)
movl %edi, (%r9)
movl $0x0, (%rbx)
movq $0x0, (%r11)
movl (%r8), %edi
imulq $0x58, %rsi, %rsi
movq 0x20(%r10,%rsi), %rbx
cmpq %rdi, %rbx
jbe 0xda971
movq %r9, -0x20(%rsp)
movq %r8, -0x18(%rsp)
addq %r10, %rsi
addq $0x20, %rsi
movq 0x10(%rsi), %r14
leaq 0x2c(%r14), %rsi
movq %rsi, -0x8(%rsp)
leaq 0x4(%r14), %rsi
movq %rsi, -0x10(%rsp)
leaq (%rdi,%rdi,8), %rsi
movl 0x4(%r14,%rsi,4), %ebp
movl 0x8(%r14,%rsi,4), %r13d
cmpl %edx, %ebp
cmovbel %edx, %ebp
cmpl %ecx, %r13d
cmovael %ecx, %r13d
cmpl %r13d, %ebp
jae 0xda966
movl 0xc(%r14,%rsi,4), %r15d
movl 0x10(%r14,%rsi,4), %r11d
cmpl %r15d, %r11d
setne %r8b
je 0xda966
leaq (%r15,%r15,8), %r12
leaq (%r14,%r12,4), %r9
movl %r11d, %esi
subl %r15d, %esi
xorl %r10d, %r10d
cmpl %ebp, 0x8(%r9)
ja 0xda929
movq -0x8(%rsp), %r8
leaq (%r8,%r12,4), %r8
notl %r15d
addl %r11d, %r15d
xorl %r10d, %r10d
cmpl %r10d, %r15d
je 0xda966
leaq 0x24(%r8), %r11
incl %r10d
cmpl %ebp, (%r8)
movq %r11, %r8
jbe 0xda90e
cmpl %esi, %r10d
setb %r8b
testb %r8b, %r8b
je 0xda966
movl %r10d, %r15d
cmpl %esi, %r10d
jae 0xda961
movl %r10d, %r8d
leaq (%r8,%r8,8), %r8
shlq $0x2, %r8
leaq (%r8,%r12,4), %r8
addq -0x10(%rsp), %r8
movl %r10d, %r15d
cmpl %r13d, (%r8)
jae 0xda961
incl %r15d
addq $0x24, %r8
cmpl %esi, %r15d
jb 0xda94d
movl %esi, %r15d
subl %r10d, %r15d
ja 0xda97c
incl %edi
cmpq %rdi, %rbx
ja 0xda8ab
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq -0x20(%rsp), %rax
movl %ebp, (%rax)
movq 0x38(%rsp), %rax
movl %r13d, (%rax)
movq 0x40(%rsp), %rax
movl %r15d, (%rax)
movl %r10d, %eax
leaq (%rax,%rax,8), %rax
leaq (%r9,%rax,4), %rax
movq 0x48(%rsp), %rcx
movq %rax, (%rcx)
incl %edi
movq -0x18(%rsp), %rax
movl %edi, (%rax)
movl $0x1, %eax
jmp 0xda971