// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/hic.cpp
// Function: get_r_utg_bench(unsigned long, bench_idx*, ma_ug_t*)
void get_r_utg_bench(uint64_t index, bench_idx* idx, ma_ug_t *ug)
{

    bench_utg* a_list = idx->ug_idx.a;
    uint64_t a_n = idx->ug_idx.n;
    bench_utg *x = &(a_list[index]), *y = NULL;
    uint64_t i, k, t, rev, x_uid, y_uid, y_pos, x_pos, d;
    uint64_t rId, ori;
    ma_utg_t *u = NULL;
    for (i = x->uID_start; i < x->uID_end; i++)
    {
        u = &(ug->u.a[i]);
        x_uid = i;
        if(u->n == 0) continue;
        for (k = 0; k < u->n; k++)
        {
            rId = u->a[k]>>33;
            ori = u->a[k]>>32&1;
            if(x->r_idx[rId] == (uint64_t)-1) continue;
            x_pos = x->r_idx[rId] & idx->pos_mode;

            for (t = 0; t < a_n; t++)
            {
                if(t == index) continue;
                y = &(a_list[t]);
                if(y->r_idx[rId] == (uint64_t)-1) continue;
                rev = 0;
                if((y->r_idx[rId]>>63) != ori) rev = 1;
                y_uid = (y->r_idx[rId]<<1)>>(64 - idx->uID_bits);
                y_pos = y->r_idx[rId] & idx->pos_mode;
                if(rev) y_pos = ug->u.a[y_uid].len - y_pos - 1;
                ///if(ori) x_pos = ug->u.a[x_uid].len - x_pos - 1, y_pos = ug->u.a[y_uid].len - y_pos - 1;
                d = MAX(x_pos, y_pos) - MIN(x_pos, y_pos);
                d = (d<<2) + (rev<<1);
                if(y_pos > x_pos) d = d + 1;
                push_hc_edge(&(idx->link.a.a[x_uid]), y_uid, 1, 0, &d);
                if(x_pos != y_pos) d = d ^ 1;
                push_hc_edge(&(idx->link.a.a[y_uid]), x_uid, 1, 0, &d);
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdx, 0x10(%rsp)
movq %rsi, (%rsp)
movq 0x10(%rsi), %rcx
leaq (%rdi,%rdi,4), %rax
movq (%rcx,%rax,8), %r9
movq %rcx, %rsi
movq 0x8(%rcx,%rax,8), %rcx
cmpq %rcx, %r9
jae 0x164ceb
movq (%rsp), %rdx
movq (%rdx), %r8
leaq (%rsi,%rax,8), %r10
addq $0x20, %rsi
movq %rsi, 0x20(%rsp)
movq %rdi, 0x40(%rsp)
movq %r8, 0x38(%rsp)
movq %r10, 0x18(%rsp)
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rdx
leaq (%r9,%r9,4), %rsi
movl 0x10(%rdx,%rsi,8), %eax
testl %eax, %eax
je 0x164cdf
leaq (%rdx,%rsi,8), %rdx
xorl %esi, %esi
movq %rdx, 0x28(%rsp)
movq 0x18(%rdx), %rcx
movq (%rcx,%rsi,8), %rcx
movq %rcx, %r11
movq %rcx, %rbx
shrq $0x21, %rbx
movq 0x20(%r10), %rcx
movq %rbx, 0x50(%rsp)
movq (%rcx,%rbx,8), %r15
cmpq $-0x1, %r15
je 0x164ccd
testq %r8, %r8
je 0x164ccd
movq %rsi, 0x30(%rsp)
shrq $0x20, %r11
andl $0x1, %r11d
movq %r11, 0x48(%rsp)
movq (%rsp), %rax
andq 0x20(%rax), %r15
movq 0x20(%rsp), %rbx
xorl %r13d, %r13d
cmpq %r13, %rdi
je 0x164cab
movq (%rbx), %rax
movq 0x50(%rsp), %rcx
movq (%rax,%rcx,8), %r14
cmpq $-0x1, %r14
je 0x164cab
movq %r14, %rsi
shrq $0x3f, %rsi
xorl %eax, %eax
movq 0x48(%rsp), %r10
cmpq %r10, %rsi
setne %dl
leaq (%r14,%r14), %rbp
movq (%rsp), %r8
movb 0x18(%r8), %dil
xorl %ecx, %ecx
subb %dil, %cl
shrq %cl, %rbp
andq 0x20(%r8), %r14
cmpq %r10, %rsi
je 0x164c14
movq 0x10(%rsp), %rcx
movq 0x10(%rcx), %rcx
leaq (,%rbp,4), %rsi
addq %rbp, %rsi
movl (%rcx,%rsi,8), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
notq %r14
addq %rcx, %r14
movb %dl, %al
addl %eax, %eax
xorl %ecx, %ecx
movq %r14, %rdx
subq %r15, %rdx
seta %cl
movq %rdx, %rsi
negq %rsi
cmpq %r14, %r15
cmovbeq %rdx, %rsi
leaq (%rax,%rsi,4), %rax
orq %rax, %rcx
movq %rcx, 0x8(%rsp)
movq %r9, %r12
leaq (%r9,%r9,2), %rdi
shlq $0x4, %rdi
movq (%rsp), %rax
addq 0x38(%rax), %rdi
movq %rbp, %rsi
movsd 0xcc6b6(%rip), %xmm0    # 0x231310
xorl %edx, %edx
leaq 0x8(%rsp), %rcx
callq 0x1416e0
cmpq %r14, %r15
je 0x164c70
xorb $0x1, 0x8(%rsp)
leaq (,%rbp,2), %rdi
addq %rbp, %rdi
shlq $0x4, %rdi
movq (%rsp), %rax
addq 0x38(%rax), %rdi
movq %r12, %rsi
movsd 0xcc67e(%rip), %xmm0    # 0x231310
xorl %edx, %edx
leaq 0x8(%rsp), %rcx
callq 0x1416e0
movq %r12, %r9
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %r8
incq %r13
addq $0x28, %rbx
cmpq %r13, %r8
jne 0x164ba1
movq 0x28(%rsp), %rdx
movl 0x10(%rdx), %eax
movq 0x18(%rsp), %r10
movq 0x30(%rsp), %rsi
incq %rsi
movl %eax, %ecx
cmpq %rcx, %rsi
jb 0x164b4d
movq 0x8(%r10), %rcx
incq %r9
cmpq %rcx, %r9
jb 0x164b29
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq