// File: /workspace/github_cpp_makefile_star2_O1/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, (%rsp)
movq 0x10(%rsi), %rdx
leaq (%rdi,%rdi,4), %rax
movq (%rdx,%rax,8), %r14
cmpq 0x8(%rdx,%rax,8), %r14
jae 0x15e2e9
movq %rdx, %rcx
movq (%rsp), %rdx
movq (%rdx), %rdx
leaq (%rcx,%rax,8), %rax
movq %rax, 0x10(%rsp)
addq $0x20, %rcx
movq %rcx, 0x20(%rsp)
movq %rdi, 0x40(%rsp)
movq %rdx, 0x38(%rsp)
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rax
leaq (%r14,%r14,4), %rcx
cmpl $0x0, 0x10(%rax,%rcx,8)
je 0x15e2d7
leaq (%rax,%rcx,8), %rcx
cmpl $0x0, 0x10(%rcx)
je 0x15e2d7
xorl %esi, %esi
movq %rcx, 0x28(%rsp)
movq 0x18(%rcx), %rax
movq %rsi, 0x30(%rsp)
movq (%rax,%rsi,8), %rax
movq %rax, %rcx
movq %rax, %rsi
shrq $0x21, %rsi
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rax
movq %rsi, 0x50(%rsp)
movq (%rax,%rsi,8), %r15
cmpq $-0x1, %r15
je 0x15e2be
testq %rdx, %rdx
je 0x15e2be
shrq $0x20, %rcx
andl $0x1, %ecx
movq %rcx, 0x48(%rsp)
movq (%rsp), %rax
andq 0x20(%rax), %r15
movq 0x20(%rsp), %rbx
xorl %r13d, %r13d
cmpq %r13, %rdi
je 0x15e2ae
movq (%rbx), %rax
movq 0x50(%rsp), %rcx
movq (%rax,%rcx,8), %r12
cmpq $-0x1, %r12
je 0x15e2ae
movq %r12, %rsi
shrq $0x3f, %rsi
xorl %eax, %eax
movq 0x48(%rsp), %r9
cmpq %r9, %rsi
setne %dl
leaq (%r12,%r12), %rbp
movq (%rsp), %r8
movb 0x18(%r8), %dil
xorl %ecx, %ecx
subb %dil, %cl
shrq %cl, %rbp
andq 0x20(%r8), %r12
cmpq %r9, %rsi
je 0x15e21d
movq 0x18(%rsp), %rcx
movq 0x10(%rcx), %rcx
leaq (,%rbp,4), %rsi
addq %rbp, %rsi
movl (%rcx,%rsi,8), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
notq %r12
addq %rcx, %r12
movb %dl, %al
addl %eax, %eax
xorl %ecx, %ecx
movq %r12, %rdx
subq %r15, %rdx
seta %cl
movq %rdx, %rsi
negq %rsi
cmpq %r12, %r15
cmovbeq %rdx, %rsi
leaq (%rax,%rsi,4), %rax
orq %rax, %rcx
movq %rcx, 0x8(%rsp)
leaq (%r14,%r14,2), %rdi
shlq $0x4, %rdi
movq (%rsp), %rax
addq 0x38(%rax), %rdi
movq %rbp, %rsi
movsd 0xc7010(%rip), %xmm0    # 0x225270
xorl %edx, %edx
leaq 0x8(%rsp), %rcx
callq 0x13b8bb
cmpq %r12, %r15
je 0x15e276
xorb $0x1, 0x8(%rsp)
leaq (,%rbp,2), %rdi
addq %rbp, %rdi
shlq $0x4, %rdi
movq (%rsp), %rax
addq 0x38(%rax), %rdi
movq %r14, %rsi
movsd 0xc6fd8(%rip), %xmm0    # 0x225270
xorl %edx, %edx
leaq 0x8(%rsp), %rcx
callq 0x13b8bb
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rdx
incq %r13
addq $0x28, %rbx
cmpq %r13, %rdx
jne 0x15e1aa
movq 0x30(%rsp), %rsi
incq %rsi
movq 0x28(%rsp), %rcx
movl 0x10(%rcx), %eax
cmpq %rax, %rsi
jb 0x15e152
incq %r14
movq 0x10(%rsp), %rax
cmpq 0x8(%rax), %r14
jb 0x15e125
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq