// File: /workspace/github_cpp_makefile_star2_O2/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, 0x18(%rsp)
movq (%rsi), %rdx
movq %rsi, (%rsp)
movq 0x10(%rsi), %rcx
imulq $0x28, %rdi, %rax
leaq (%rcx,%rax), %rsi
movq %rsi, 0x10(%rsp)
movq (%rcx,%rax), %r8
addq $0x20, %rcx
movq %rcx, 0x20(%rsp)
movq %rdi, 0x40(%rsp)
movq %rdx, 0x38(%rsp)
movq 0x10(%rsp), %rax
cmpq 0x8(%rax), %r8
jae 0x11f96a
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rsi
imulq $0x28, %r8, %rcx
movl 0x10(%rsi,%rcx), %eax
testl %eax, %eax
je 0x11f962
addq %rcx, %rsi
xorl %r9d, %r9d
movq %rsi, 0x28(%rsp)
movl %eax, %ecx
cmpq %rcx, %r9
jae 0x11f962
movq 0x18(%rsi), %rcx
movq (%rcx,%r9,8), %r10
movq %r10, %r11
shrq $0x21, %r11
movq 0x10(%rsp), %rcx
movq 0x20(%rcx), %rcx
movq %r11, 0x50(%rsp)
movq (%rcx,%r11,8), %r12
cmpq $-0x1, %r12
je 0x11f95a
movq %r9, 0x30(%rsp)
shrq $0x20, %r10
andl $0x1, %r10d
movq (%rsp), %rax
andq 0x20(%rax), %r12
movq 0x20(%rsp), %r15
xorl %ebx, %ebx
movq %r10, 0x48(%rsp)
cmpq %rbx, %rdx
je 0x11f94d
cmpq %rbx, %rdi
je 0x11f941
movq (%r15), %rax
movq 0x50(%rsp), %rcx
movq (%rax,%rcx,8), %r13
cmpq $-0x1, %r13
je 0x11f941
movq %r13, %rsi
shrq $0x3f, %rsi
xorl %eax, %eax
cmpq %r10, %rsi
setne %dl
leaq (,%r13,2), %rbp
movq (%rsp), %r9
movb 0x18(%r9), %dil
xorl %ecx, %ecx
subb %dil, %cl
shrq %cl, %rbp
andq 0x20(%r9), %r13
cmpq %r10, %rsi
je 0x11f8b4
movq 0x18(%rsp), %rcx
movq 0x10(%rcx), %rcx
imulq $0x28, %rbp, %rsi
movl (%rcx,%rsi), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
notq %r13
addq %rcx, %r13
movb %dl, %al
addl %eax, %eax
xorl %ecx, %ecx
movq %r13, %rdx
subq %r12, %rdx
seta %cl
movq %rdx, %rsi
negq %rsi
cmpq %r13, %r12
cmovbeq %rdx, %rsi
leaq (%rax,%rsi,4), %rax
orq %rax, %rcx
movq %rcx, 0x8(%rsp)
movq %r8, %r14
imulq $0x30, %r8, %rdi
movq (%rsp), %rax
addq 0x38(%rax), %rdi
movq %rbp, %rsi
movsd 0xc39aa(%rip), %xmm0    # 0x1e32a0
xorl %edx, %edx
leaq 0x8(%rsp), %rcx
callq 0xfa2fb
cmpq %r13, %r12
je 0x11f90c
xorb $0x1, 0x8(%rsp)
imulq $0x30, %rbp, %rdi
movq (%rsp), %rax
addq 0x38(%rax), %rdi
movq %r14, %rsi
movsd 0xc397d(%rip), %xmm0    # 0x1e32a0
xorl %edx, %edx
leaq 0x8(%rsp), %rcx
callq 0xfa2fb
movq %r14, %r8
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rdx
movq 0x48(%rsp), %r10
incq %rbx
addq $0x28, %r15
jmp 0x11f840
movq 0x28(%rsp), %rsi
movl 0x10(%rsi), %eax
movq 0x30(%rsp), %r9
incq %r9
jmp 0x11f7e9
incq %r8
jmp 0x11f7b6
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq