// File: chhylp123[P]hifiasm/horder.cpp
// Function: get_switch_ovlp_hits(unsigned long*, unsigned long, unsigned long, unsigned long, u_trans_hit_t*, h_covs*, unsigned long*)
int get_switch_ovlp_hits(uint64_t *i, uint64_t pid, uint64_t ls, uint64_t le, u_trans_hit_t *hit, 
h_covs *join, uint64_t *idx)
{
    uint64_t os, oe;
    hit->qSpre = hit->qEpre = hit->qScur = hit->qEcur = hit->qn = (uint32_t)-1;
    hit->tSpre = hit->tEpre = hit->tScur = hit->tEcur = hit->tn = (uint32_t)-1;

    while ((*i) < ((uint32_t)idx[pid]))
    {
        os = join->a[(idx[pid]>>32)+(*i)].s;
        oe = join->a[(idx[pid]>>32)+(*i)].e;
        if(OVL(os, oe, ls, le) == 0)
        {
            (*i)++;
            continue;
        }
        
        hit->qn = (uint32_t)(join->a[(idx[pid]>>32)+(*i)].dp);
        hit->qScur = MAX(os, ls); hit->qEcur = MIN(oe, le);
        hit->qSpre = hit->qScur - os; hit->qEpre = hit->qEcur - os;
        (*i)++;
        return 1;
    }

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq -0x30(%rbp), %rax
movl $0xffffffff, 0x10(%rax) # imm = 0xFFFFFFFF
movq -0x30(%rbp), %rax
movl $0xffffffff, 0xc(%rax)  # imm = 0xFFFFFFFF
movq -0x30(%rbp), %rax
movl $0xffffffff, 0x8(%rax)  # imm = 0xFFFFFFFF
movq -0x30(%rbp), %rax
movl $0xffffffff, 0x4(%rax)  # imm = 0xFFFFFFFF
movq -0x30(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq -0x30(%rbp), %rax
movl $0xffffffff, 0x24(%rax) # imm = 0xFFFFFFFF
movq -0x30(%rbp), %rax
movl $0xffffffff, 0x20(%rax) # imm = 0xFFFFFFFF
movq -0x30(%rbp), %rax
movl $0xffffffff, 0x1c(%rax) # imm = 0xFFFFFFFF
movq -0x30(%rbp), %rax
movl $0xffffffff, 0x18(%rax) # imm = 0xFFFFFFFF
movq -0x30(%rbp), %rax
movl $0xffffffff, 0x14(%rax) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rbp), %rcx
movq -0x18(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %ecx
cmpq %rcx, %rax
jae 0x23a21f
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rbp), %rcx
movq -0x18(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
movq -0x10(%rbp), %rdx
addq (%rdx), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rbp), %rcx
movq -0x18(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
movq -0x10(%rbp), %rdx
addq (%rdx), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x28(%rbp), %rax
ja 0x23a09c
movq -0x48(%rbp), %rax
movq %rax, -0x50(%rbp)
jmp 0x23a0a4
movq -0x28(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x20(%rbp), %rax
jb 0x23a0c0
movq -0x40(%rbp), %rax
movq %rax, -0x60(%rbp)
jmp 0x23a0c8
movq -0x20(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x58(%rbp), %rax
movq -0x60(%rbp), %rcx
cmpq %rcx, %rax
jbe 0x23a126
movq -0x48(%rbp), %rax
cmpq -0x28(%rbp), %rax
ja 0x23a0e9
movq -0x48(%rbp), %rax
movq %rax, -0x68(%rbp)
jmp 0x23a0f1
movq -0x28(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x20(%rbp), %rax
jb 0x23a10d
movq -0x40(%rbp), %rax
movq %rax, -0x78(%rbp)
jmp 0x23a115
movq -0x20(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x70(%rbp), %rax
movq -0x78(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x80(%rbp)
jmp 0x23a12e
xorl %eax, %eax
movq %rax, -0x80(%rbp)
jmp 0x23a12e
movq -0x80(%rbp), %rax
cmpq $0x0, %rax
jne 0x23a14b
movq -0x10(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
jmp 0x23a011
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rbp), %rcx
movq -0x18(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
movq -0x10(%rbp), %rdx
addq (%rdx), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x40(%rbp), %rax
cmpq -0x20(%rbp), %rax
jb 0x23a194
movq -0x40(%rbp), %rax
movq %rax, -0x88(%rbp)
jmp 0x23a19f
movq -0x20(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x48(%rbp), %rax
cmpq -0x28(%rbp), %rax
ja 0x23a1c6
movq -0x48(%rbp), %rax
movq %rax, -0x90(%rbp)
jmp 0x23a1d1
movq -0x28(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x30(%rbp), %rax
movl 0x8(%rax), %eax
subq -0x40(%rbp), %rax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
movq -0x30(%rbp), %rax
movl 0xc(%rax), %eax
subq -0x40(%rbp), %rax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0x23a226
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x10, %rsp
popq %rbp
retq
nop