// File: /workspace/github_cpp_makefile_star2_O3/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, %r14
movq 0x10(%rdi), %r9
movq 0x48(%rdi), %r10
shlq $0x5, %rsi
movq (%r9,%rsi), %r15
movq 0x18(%r9,%rsi), %rbp
movq %rbp, %r13
shrq $0x20, %r13
movq 0x50(%rdi), %rbx
leaq (%r15,%r15), %rdi
movq %r10, %rcx
negq %rcx
shrq %cl, %rdi
movq %rbx, %r12
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), %r11
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
andq %r11, %rdi
je 0x17945f
movq %rbp, -0x20(%rsp)
movq %rbx, -0x10(%rsp)
movq %r9, -0x8(%rsp)
leaq (%r9,%rsi), %rax
movq %rax, -0x28(%rsp)
movl $0x40, %r9d
subq %r10, %r9
movq %r14, -0x18(%rsp)
movq (%r14), %rax
shrq $0x20, %r11
shlq $0x3, %rdi
leaq (%rdi,%rdi,2), %rdi
leaq (%r11,%r11,2), %r10
leaq (%rax,%r10,8), %rax
addq $0x10, %rax
movq $-0x1, %rbx
xorl %r11d, %r11d
movq $-0x1, %rbp
xorl %r14d, %r14d
movq -0x10(%rax,%r11), %r10
cmpq %r10, %rcx
jb 0x17934c
cmpq -0x8(%rax,%r11), %r13
jae 0x17934c
incq %r14
movl (%rax,%r11), %ebp
movq %r10, %rbx
addq $0x18, %r11
cmpq %r11, %rdi
jne 0x179331
cmpq $0x1, %r14
jne 0x17945d
movl $0x3f, %edi
subq %r8, %rdi
movl %edi, %ecx
shlq %cl, %rbp
movabsq $-0x8000000000000000, %r8 # imm = 0x8000000000000000
andq %r8, %r15
addq %r15, %r12
subq %rbx, %r12
addq %rbp, %r12
movq -0x28(%rsp), %rax
movq %r12, (%rax)
movq 0x8(%rax), %r15
leaq (%r15,%r15), %r10
movl %r9d, %ecx
shrq %cl, %r10
movq -0x10(%rsp), %rbp
andq %r15, %rbp
movl -0x20(%rsp), %ecx
movq %rbp, %r9
subq %rcx, %r9
decq %rcx
incq %r9
xorl %eax, %eax
testq %r15, %r15
cmovsq %rax, %rcx
cmovnsq %rbp, %r9
addq %rbp, %rcx
testq %rcx, %rcx
cmovleq %rax, %rcx
testq %r9, %r9
cmovleq %rax, %r9
movq (%rdx,%r10,8), %rdx
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
andq %rdx, %r10
movq -0x8(%rsp), %r13
movq -0x18(%rsp), %r11
je 0x17945f
movq (%r11), %rax
shrq $0x20, %rdx
shlq $0x3, %r10
leaq (%r10,%r10,2), %r10
leaq (%rdx,%rdx,2), %rdx
leaq (%rax,%rdx,8), %r14
addq $0x10, %r14
movq $-0x1, %rdx
xorl %r11d, %r11d
movq $-0x1, %rax
xorl %r12d, %r12d
movq -0x10(%r14,%r11), %rbx
cmpq %rbx, %r9
jb 0x179431
cmpq -0x8(%r14,%r11), %rcx
jae 0x179431
incq %r12
movl (%r14,%r11), %eax
movq %rbx, %rdx
addq $0x18, %r11
cmpq %r11, %r10
jne 0x179416
cmpq $0x1, %r12
jne 0x17945d
movl %edi, %ecx
shlq %cl, %rax
andq %r8, %r15
subq %rdx, %rax
addq %r15, %rbp
addq %rax, %rbp
movq %rbp, 0x8(%r13,%rsi)
movl $0x1, %eax
jmp 0x17945f
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq