// File: chhylp123[P]hifiasm/horder.cpp
// Function: get_new_offset(kvec_pe_hit*, unsigned long, unsigned long*, h_covs*, unsigned long)
int get_new_offset(kvec_pe_hit *hits, uint64_t id, uint64_t *index, h_covs *join, uint64_t new_uID_bits)
{
    uint64_t suid, sbeg, send, k, uid, os, oe, ls, le, occ, nuid, noff;
    uint64_t euid, ebeg, eend;
    resolve_hit(hits->a.a[id].s, hits->a.a[id].len>>32, hits->uID_bits, 
                                                                hits->pos_mode, &suid, &sbeg, &send);
    uid = suid; ls = sbeg; le = send; occ = 0; nuid = noff = (uint64_t)-1; 
    for (k = 0; k < ((uint32_t)index[uid]); k++)
    {
        os = join->a[(index[uid]>>32)+k].s;
        oe = join->a[(index[uid]>>32)+k].e;
        if(ls >= os && le <= oe)
        {
            occ++;
            nuid = (uint32_t)join->a[(index[uid]>>32)+k].dp;
            noff = os;
        }
    }
    if(occ != 1) return 0;
    noff = get_hit_spos(*hits, id) - noff;
    nuid <<= (64 - new_uID_bits - 1);
    hits->a.a[id].s >>= 63; hits->a.a[id].s <<= 63; 
    hits->a.a[id].s += nuid + noff;

    
    resolve_hit(hits->a.a[id].e, (uint32_t)hits->a.a[id].len, hits->uID_bits, 
                                                                hits->pos_mode, &euid, &ebeg, &eend);
    uid = euid; ls = ebeg; le = eend; occ = 0; nuid = noff = (uint64_t)-1;
    for (k = 0; k < ((uint32_t)index[uid]); k++)
    {
        os = join->a[(index[uid]>>32)+k].s;
        oe = join->a[(index[uid]>>32)+k].e;
        if(ls >= os && le <= oe)
        {
            occ++;
            nuid = (uint32_t)join->a[(index[uid]>>32)+k].dp;
            noff = os;
        }
    }
    if(occ != 1) return 0;
    noff = get_hit_epos(*hits, id) - noff;
    nuid <<= (64 - new_uID_bits - 1);
    hits->a.a[id].e >>= 63; hits->a.a[id].e <<= 63; 
    hits->a.a[id].e += nuid + noff;
    return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
shrq $0x20, %rax
movl %eax, %esi
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdx
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rcx
leaq -0x38(%rbp), %r8
leaq -0x40(%rbp), %r9
leaq -0x48(%rbp), %rax
movq %rax, (%rsp)
callq 0x233160
movq -0x38(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x78(%rbp)
movq $0x0, -0x80(%rbp)
movq $-0x1, -0x90(%rbp)
movq $-0x1, -0x88(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq -0x20(%rbp), %rcx
movq -0x58(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %ecx
cmpq %rcx, %rax
jae 0x23ad00
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x20(%rbp), %rcx
movq -0x58(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
addq -0x50(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x20(%rbp), %rcx
movq -0x58(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
addq -0x50(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x70(%rbp), %rax
cmpq -0x60(%rbp), %rax
jb 0x23aced
movq -0x78(%rbp), %rax
cmpq -0x68(%rbp), %rax
ja 0x23aced
movq -0x80(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x20(%rbp), %rcx
movq -0x58(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
addq -0x50(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movl %eax, %eax
movq %rax, -0x88(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x90(%rbp)
jmp 0x23acef
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x23ac25
cmpq $0x1, -0x80(%rbp)
je 0x23ad13
movl $0x0, -0x4(%rbp)
jmp 0x23b00a
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq -0x10(%rbp), %rcx
andq 0x50(%rcx), %rax
subq -0x90(%rbp), %rax
movq %rax, -0x90(%rbp)
movl $0x40, %ecx
subq -0x30(%rbp), %rcx
subq $0x1, %rcx
movq -0x88(%rbp), %rax
shlq %cl, %rax
movq %rax, -0x88(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rcx
shrq $0x3f, %rcx
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rcx
shlq $0x3f, %rcx
movq %rcx, (%rax)
movq -0x88(%rbp), %rcx
addq -0x90(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
movl %eax, %esi
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdx
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rcx
leaq -0x98(%rbp), %r8
leaq -0xa0(%rbp), %r9
leaq -0xa8(%rbp), %rax
movq %rax, (%rsp)
callq 0x233160
movq -0x98(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, -0x78(%rbp)
movq $0x0, -0x80(%rbp)
movq $-0x1, -0x90(%rbp)
movq $-0x1, -0x88(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq -0x20(%rbp), %rcx
movq -0x58(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %ecx
cmpq %rcx, %rax
jae 0x23af3e
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x20(%rbp), %rcx
movq -0x58(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
addq -0x50(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x20(%rbp), %rcx
movq -0x58(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
addq -0x50(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x70(%rbp), %rax
cmpq -0x60(%rbp), %rax
jb 0x23af2b
movq -0x78(%rbp), %rax
cmpq -0x68(%rbp), %rax
ja 0x23af2b
movq -0x80(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x20(%rbp), %rcx
movq -0x58(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
addq -0x50(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movl %eax, %eax
movq %rax, -0x88(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x90(%rbp)
jmp 0x23af2d
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x23ae63
cmpq $0x1, -0x80(%rbp)
je 0x23af51
movl $0x0, -0x4(%rbp)
jmp 0x23b00a
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
andq 0x50(%rcx), %rax
subq -0x90(%rbp), %rax
movq %rax, -0x90(%rbp)
movl $0x40, %ecx
subq -0x30(%rbp), %rcx
subq $0x1, %rcx
movq -0x88(%rbp), %rax
shlq %cl, %rax
movq %rax, -0x88(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rcx
shrq $0x3f, %rcx
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rcx
shlq $0x3f, %rcx
movq %rcx, 0x8(%rax)
movq -0x88(%rbp), %rcx
addq -0x90(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rax
addq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)