// File: /workspace/github_cpp_makefile_star2_O2/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
subq $0x78, %rsp
movq %r8, 0x28(%rsp)
movq %rcx, %r15
movq %rdx, %rbx
movq 0x10(%rdi), %rax
movq 0x48(%rdi), %rdx
shlq $0x5, %rsi
leaq (%rax,%rsi), %rcx
movq %rcx, 0x8(%rsp)
movq (%rax,%rsi), %r12
movq %rax, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
movq 0x18(%rax,%rsi), %rsi
movq %rsi, 0x30(%rsp)
shrq $0x20, %rsi
movq 0x50(%rdi), %rcx
leaq 0x60(%rsp), %rbp
movq %rbp, (%rsp)
leaq 0x70(%rsp), %r14
leaq 0x68(%rsp), %r13
movq %r12, %rdi
movq %rdx, 0x38(%rsp)
movq %rcx, 0x10(%rsp)
movq %r14, %r8
movq %r13, %r9
callq 0x131ad6
movq (%r14), %rax
movq (%r13), %rcx
movq (%rbp), %rdx
movq %rbx, 0x40(%rsp)
movq (%rbx,%rax,8), %rax
movl %eax, %esi
shrq $0x20, %rax
imulq $0x18, %rax, %rdi
pushq $-0x1
popq %rax
xorl %r8d, %r8d
movq %rax, %r9
subq $0x1, %rsi
jb 0x13544d
movq (%r15), %r11
movq (%r11,%rdi), %r10
cmpq %r10, %rcx
jb 0x135437
cmpq 0x8(%r11,%rdi), %rdx
jbe 0x13543c
movq %r9, %r10
jmp 0x135444
incq %r8
movl 0x10(%r11,%rdi), %eax
addq $0x18, %rdi
movq %r10, %r9
jmp 0x13541e
cmpq $0x1, %r8
jne 0x135550
movabsq $-0x8000000000000000, %rbx # imm = 0x8000000000000000
pushq $0x3f
popq %r14
subq 0x28(%rsp), %r14
movl %r14d, %ecx
shlq %cl, %rax
movq %r12, %rdx
movq 0x10(%rsp), %rcx
andq %rcx, %rdx
andq %rbx, %r12
addq %rdx, %r12
subq %r9, %rax
addq %r12, %rax
movq 0x8(%rsp), %rdx
movq %rax, (%rdx)
movq 0x8(%rdx), %rdi
leaq 0x48(%rsp), %rbp
movq %rbp, (%rsp)
leaq 0x58(%rsp), %r13
leaq 0x50(%rsp), %r12
movq %rdi, 0x8(%rsp)
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq %r13, %r8
movq %r12, %r9
callq 0x131ad6
movq (%r13), %rax
movq (%r12), %rcx
movq (%rbp), %rdx
movq 0x40(%rsp), %rsi
movq (%rsi,%rax,8), %rax
movl %eax, %esi
shrq $0x20, %rax
imulq $0x18, %rax, %rdi
pushq $-0x1
popq %rax
xorl %r8d, %r8d
movq %rax, %r9
subq $0x1, %rsi
jb 0x135517
movq (%r15), %r11
movq (%r11,%rdi), %r10
cmpq %r10, %rcx
jb 0x135501
cmpq 0x8(%r11,%rdi), %rdx
jbe 0x135506
movq %r9, %r10
jmp 0x13550e
incq %r8
movl 0x10(%r11,%rdi), %eax
addq $0x18, %rdi
movq %r10, %r9
jmp 0x1354e8
cmpq $0x1, %r8
jne 0x135550
movl %r14d, %ecx
shlq %cl, %rax
movq 0x10(%rsp), %rcx
movq 0x8(%rsp), %rdx
andq %rdx, %rcx
andq %rdx, %rbx
addq %rcx, %rbx
subq %r9, %rax
addq %rbx, %rax
movq 0x20(%rsp), %rcx
movq 0x18(%rsp), %rdx
movq %rax, 0x8(%rcx,%rdx)
pushq $0x1
popq %rax
jmp 0x135552
xorl %eax, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq