// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rcx, %rbx
movq 0x10(%rdi), %rax
movq 0x48(%rdi), %r10
shlq $0x5, %rsi
movq (%rax,%rsi), %r15
movq %rax, -0x20(%rsp)
movq 0x18(%rax,%rsi), %r13
movq %r13, -0x8(%rsp)
shrq $0x20, %r13
movq 0x50(%rdi), %r12
leaq (%r15,%r15), %rdi
movq %r10, %rcx
negq %rcx
shrq %cl, %rdi
movq %r12, -0x28(%rsp)
andq %r15, %r12
movq %r12, %rcx
subq %r13, %rcx
decq %r13
incq %rcx
xorl %eax, %eax
testq %r15, %r15
cmovsq %rax, %r13
cmovnsq %r12, %rcx
addq %r12, %r13
testq %r13, %r13
cmovleq %rax, %r13
testq %rcx, %rcx
cmovleq %rax, %rcx
movq (%rdx,%rdi,8), %r9
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
andq %r9, %rdi
je 0x172798
movq %r8, -0x18(%rsp)
movq %r10, -0x10(%rsp)
movq %rbx, %r8
movq (%rbx), %r10
shrq $0x20, %r9
shlq $0x3, %rdi
leaq (%rdi,%rdi,2), %rdi
leaq (%r9,%r9,2), %r9
leaq (%r10,%r9,8), %r11
addq $0x10, %r11
movq $-0x1, %r14
xorl %r10d, %r10d
movq $-0x1, %rbp
xorl %ebx, %ebx
movq -0x10(%r11,%r10), %r9
cmpq %r9, %rcx
jb 0x172779
cmpq -0x8(%r11,%r10), %r13
jae 0x172779
incq %rbx
movl (%r11,%r10), %ebp
movq %r9, %r14
addq $0x18, %r10
cmpq %r10, %rdi
jne 0x17275e
cmpq $0x1, %rbx
sete %cl
movq %r8, %rbx
movq -0x10(%rsp), %r10
movq -0x18(%rsp), %r8
jmp 0x1727a8
movq $-0x1, %rbp
xorl %ecx, %ecx
movq $-0x1, %r14
testb %cl, %cl
je 0x1728d6
movl $0x40, %eax
movq -0x20(%rsp), %rcx
leaq (%rcx,%rsi), %r9
subq %r10, %rax
movabsq $-0x8000000000000000, %r13 # imm = 0x8000000000000000
movl $0x3f, %edi
subq %r8, %rdi
movl %edi, %ecx
shlq %cl, %rbp
andq %r13, %r15
addq %r15, %r12
subq %r14, %r12
addq %rbp, %r12
movq %r12, (%r9)
movq 0x8(%r9), %r10
leaq (%r10,%r10), %r9
movl %eax, %ecx
shrq %cl, %r9
movq %r10, %r11
andq -0x28(%rsp), %r11
movl -0x8(%rsp), %ecx
movq %r11, %r8
subq %rcx, %r8
decq %rcx
incq %r8
xorl %eax, %eax
testq %r10, %r10
cmovsq %rax, %rcx
cmovnsq %r11, %r8
addq %r11, %rcx
testq %rcx, %rcx
cmovleq %rax, %rcx
testq %r8, %r8
cmovleq %rax, %r8
movq (%rdx,%r9,8), %rdx
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
andq %rdx, %r9
je 0x172895
movq (%rbx), %r10
shrq $0x20, %rdx
shlq $0x3, %r9
leaq (%r9,%r9,2), %rbx
leaq (%rdx,%rdx,2), %rdx
leaq (%r10,%rdx,8), %r11
addq $0x10, %r11
movq $-0x1, %r9
xorl %r10d, %r10d
movq $-0x1, %rdx
xorl %r15d, %r15d
movq -0x10(%r11,%r10), %r14
cmpq %r14, %r8
jb 0x172883
cmpq -0x8(%r11,%r10), %rcx
jae 0x172883
incq %r15
movl (%r11,%r10), %edx
movq %r14, %r9
addq $0x18, %r10
cmpq %r10, %rbx
jne 0x172868
cmpq $0x1, %r15
sete %cl
jmp 0x1728a5
movq $-0x1, %rdx
xorl %ecx, %ecx
movq $-0x1, %r9
testb %cl, %cl
je 0x1728d6
movl %edi, %ecx
shlq %cl, %rdx
movq -0x20(%rsp), %rcx
movq 0x8(%rcx,%rsi), %rax
movq -0x28(%rsp), %rdi
andq %rax, %rdi
subq %r9, %rdx
addq %rdi, %rdx
andq %rax, %r13
addq %rdx, %r13
movq %r13, 0x8(%rcx,%rsi)
movl $0x1, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq