// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/hic.cpp
// Function: get_hic_distance_bench(pe_hit*, hc_links*, bench_idx*, ma_ug_t*, unsigned long*)
uint64_t get_hic_distance_bench(pe_hit* hit, hc_links* link, bench_idx* idx, ma_ug_t *ug, uint64_t* is_trans)
{
    (*is_trans) = (uint64_t)-1;
    uint64_t s_uid, e_uid;
    long long s_pos, e_pos;
    s_uid = ((hit->s<<1)>>(64 - idx->uID_bits)); s_pos = hit->s & idx->pos_mode;
    e_uid = ((hit->e<<1)>>(64 - idx->uID_bits)); e_pos = hit->e & idx->pos_mode;
    if(s_uid == e_uid)
    {
        (*is_trans) = 0;
        return MAX(s_pos, e_pos) - MIN(s_pos, e_pos);
    }

    uint64_t s_i, e_i, k, ori;
    for (s_i = 0; s_i < idx->ug_idx.n; s_i++)
    {
        if(s_uid >= idx->ug_idx.a[s_i].uID_start && s_uid < idx->ug_idx.a[s_i].uID_end) break;
    }
    for (e_i = 0; e_i < idx->ug_idx.n; e_i++)
    {
        if(e_uid >= idx->ug_idx.a[e_i].uID_start && e_uid < idx->ug_idx.a[e_i].uID_end) break;
    }
    if(s_i == idx->ug_idx.n || e_i == idx->ug_idx.n) return (uint64_t)-1;
    if(s_i == e_i)
    {
        (*is_trans) = 0;
        return (uint64_t)-1;
    }

    (*is_trans) = 1;
    hc_linkeage* t = &(link->a.a[s_uid]);
    long long m_x[2] = {1, -1}, dis;
    for (k = 0; k < t->e.n; k++)
    {
        if(t->e.a[k].del || t->e.a[k].uID != e_uid) continue;
        ori = !!(t->e.a[k].dis & (uint64_t)2);
        dis = (long long)(t->e.a[k].dis>>2) * m_x[t->e.a[k].dis & (uint64_t)1];
        if(ori) e_pos = ug->u.a[e_uid].len - e_pos - 1;
        e_pos = e_pos + dis;
        return MAX(s_pos, e_pos) - MIN(s_pos, e_pos);
    }

    return (uint64_t)-1;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rcx, %rax
orq $-0x1, (%r8)
movq (%rdi), %r9
movq 0x8(%rdi), %rdi
leaq (%r9,%r9), %r11
xorl %ecx, %ecx
subb 0x18(%rdx), %cl
shrq %cl, %r11
leaq (%rdi,%rdi), %r10
shrq %cl, %r10
movq 0x20(%rdx), %rcx
andq %rcx, %r9
andq %rcx, %rdi
cmpq %r10, %r11
jne 0x11fc5c
andq $0x0, (%r8)
subq %rdi, %r9
movq %r9, %rax
negq %rax
cmovsq %r9, %rax
jmp 0x11fcdc
movq (%rdx), %rbx
movabsq $0x8, %r14
xorl %ecx, %ecx
cmpq %rcx, %rbx
je 0x11fc8a
movq 0x10(%rdx), %r15
cmpq -0x8(%r15,%r14), %r11
jb 0x11fc81
cmpq (%r15,%r14), %r11
jb 0x11fc8d
incq %rcx
addq $0x28, %r14
jmp 0x11fc6b
movq %rbx, %rcx
movabsq $0x8, %r15
xorl %r14d, %r14d
cmpq %r14, %rbx
je 0x11fcd2
movq 0x10(%rdx), %r12
cmpq -0x8(%r12,%r15), %r10
jb 0x11fcb0
cmpq (%r12,%r15), %r10
jb 0x11fcb9
incq %r14
addq $0x28, %r15
jmp 0x11fc9a
cmpq %rbx, %rcx
sete %dl
cmpq %r14, %rbx
sete %bl
orb %dl, %bl
jne 0x11fcd2
cmpq %r14, %rcx
jne 0x11fce4
andq $0x0, (%r8)
movabsq $-0x1, %rax
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq $0x1, (%r8)
movq 0x10(%rsi), %rdx
imulq $0x30, %r11, %rsi
leaq (%rdx,%rsi), %rcx
movq (%rdx,%rsi), %rsi
movabsq $0x18, %rdx
subq $0x1, %rsi
jb 0x11fcd2
movq 0x10(%rcx), %r8
cmpb $0x0, (%r8,%rdx)
js 0x11fd20
movl -0x10(%r8,%rdx), %r11d
cmpq %r11, %r10
je 0x11fd26
addq $0x28, %rdx
jmp 0x11fd05
movq -0x8(%r8,%rdx), %rdx
movq %rdx, %rcx
shrq $0x2, %rcx
movl %edx, %esi
andl $0x1, %esi
leaq 0xcd3d2(%rip), %r8      # 0x1ed110
imulq (%r8,%rsi,8), %rcx
testb $0x2, %dl
je 0x11fd5e
movq 0x10(%rax), %rax
imulq $0x28, %r10, %rdx
movl (%rax,%rdx), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
notq %rdi
addq %rax, %rdi
addq %rdi, %rcx
subq %rcx, %r9
jmp 0x11fc4d