// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/hic.cpp
// Function: worker_for_dis(void*, long, int)
static void worker_for_dis(void *data, long i, int tid) 
{
    utg_d_t* s = (utg_d_t*)data;
    hc_links* link = s->link;
    MT* M = s->M; 
    bubble_type* bub = s->bub;
    uint8_t* dis_buf = s->dis_buf[tid];
    asg_t *sg = s->sg;
    hc_linkeage* t = NULL;
    uint32_t n_vtx = sg->n_seq<<1, v, u, k, j;
    uint64_t d[2], db[2], q_u, min, min_i, min_b, rev[2], min_rev;

    if (sg->seq[i].del) return;
    t = &(link->a.a[i]);
    if (t->e.n == 0) return;

    for (k = 0; k < t->e.n; k++)
    {
        if(t->e.a[k].del) continue;
        if(i == t->e.a[k].uID) continue;
        u = t->e.a[k].uID;

        for (v = ((uint64_t)(i)<<1); v < ((uint64_t)(i+1)<<1); v++)///two directions
        {
            d[0] = d[1] = db[0] = db[1] = (uint64_t)-1;            
            for (j = 0; j < M->matrix.a[v].a.n; j++)
            {
                q_u = M->matrix.a[v].a.a[j] >> M->uID_shift;
                if((q_u>>1) == u) d[q_u&1] = (M->matrix.a[v].a.a[j] & M->dis_mode) + sg->seq[q_u>>1].len;
                if((q_u>>1) > u) break;///just for speeding up, doesn't affect results
            }

            min = min_i = min_b = (uint64_t)-1;
            if(t->e.a[k].dis != (uint64_t)-1) min = t->e.a[k].dis >> 3;
            
            if(d[0] < min) min = d[0], min_i = 0, min_b = 0;
            if(d[1] < min) min = d[1], min_i = 1, min_b = 0;

            if(min_i != (uint64_t)-1 && min != (uint64_t)-1)
            {
                t->e.a[k].dis = min<<1;
                t->e.a[k].dis += min_b;
                t->e.a[k].dis <<=1;
                t->e.a[k].dis += v&1;//s-direction
                t->e.a[k].dis <<=1;
                t->e.a[k].dis += min_i;//e-direction
            }
        }


        ///might be wrong
        if(IF_BUB(i, *bub) && IF_BUB(u, *bub)
            && bub->index[i] != bub->index[u] && t->e.a[k].dis != (uint64_t)-1)
        {
            continue;
        }

        for (v = ((uint64_t)(i)<<1); v < ((uint64_t)(i+1)<<1); v++)
        {
            d[0] = d[1] = db[0] = db[1] = (uint64_t)-1;  
            db[0] = get_LCA(v, sg->seq[v>>1].len, u<<1, sg->seq[u].len, 
                                                        dis_buf, n_vtx, M, bub, &rev[0]);
            db[1] = get_LCA(v, sg->seq[v>>1].len, (u<<1) + 1, sg->seq[u].len, 
                                                        dis_buf, n_vtx, M, bub, &rev[1]);

            min = min_i = min_b = min_rev = (uint64_t)-1;
            if(t->e.a[k].dis != (uint64_t)-1) min = t->e.a[k].dis >> 3;
            
            if(db[0] < min) min = db[0], min_i = 0, min_b = 1, min_rev = rev[0];
            if(db[1] < min) min = db[1], min_i = 1, min_b = 1, min_rev = rev[1];

            if(min_i != (uint64_t)-1 && min != (uint64_t)-1)
            {
                t->e.a[k].dis = min<<1;
                t->e.a[k].dis += min_b;
                t->e.a[k].dis <<=1;
                t->e.a[k].dis += ((v&1)^min_rev);//s-direction
                t->e.a[k].dis <<=1;
                t->e.a[k].dis += (min_i^min_rev);//e-direction
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq (%rdi), %r14
movq 0x20(%r14), %rax
cmpl $0x0, (%rax,%rsi,8)
js 0x1431b1
movq 0x8(%rdi), %rax
movq 0x10(%rax), %rcx
leaq (%rsi,%rsi,2), %rax
shlq $0x4, %rax
movq (%rcx,%rax), %r9
testq %r9, %r9
je 0x1431b1
movq %rcx, %r8
movq 0x10(%rdi), %r15
movq 0x18(%rdi), %rcx
movq %rcx, 0x58(%rsp)
movq 0x20(%rdi), %rcx
movslq %edx, %rdx
movq (%rcx,%rdx,8), %rcx
movq %rcx, 0x88(%rsp)
movl 0x14(%r14), %ecx
addl %ecx, %ecx
addq %rax, %r8
leal (%rsi,%rsi), %r12d
leaq 0x2(,%rsi,2), %rax
movq %rax, 0x10(%rsp)
movl %ecx, %eax
movq %rax, 0x60(%rsp)
movq %r8, 0x50(%rsp)
movq 0x10(%r8), %rdx
xorl %ecx, %ecx
movq %rsi, 0x40(%rsp)
movq %r14, 0x90(%rsp)
movq %r15, 0x68(%rsp)
movq %r12, (%rsp)
leaq (%rcx,%rcx,4), %rdi
cmpb $0x0, 0x18(%rdx,%rdi,8)
js 0x1431a6
leaq (%rdx,%rdi,8), %rax
movl 0x8(%rax), %ebp
cmpq %rsi, %rbp
je 0x1431a6
movq %r9, 0x8(%rsp)
movq %rdi, 0x18(%rsp)
movq %rcx, 0x48(%rsp)
cmpq %r12, 0x10(%rsp)
jbe 0x142fa7
movq 0x10(%r15), %rsi
movq 0x18(%rsp), %rax
leaq (%rdx,%rax,8), %rax
addq $0x10, %rax
movq %rax, 0x20(%rsp)
movq (%rax), %r9
movq (%rsp), %r8
movq %r8, %rax
shlq $0x5, %rax
pcmpeqd %xmm0, %xmm0
movdqa %xmm0, 0x30(%rsp)
movq (%rsi,%rax), %r10
testq %r10, %r10
je 0x142f1f
addq %rsi, %rax
movq 0x10(%rax), %r11
movq 0x18(%r15), %rcx
movl $0x1, %ebx
xorl %eax, %eax
movq (%r11,%rax,8), %rax
movq %rax, %r12
shrq %cl, %r12
movq %r12, %r13
shrq %r13
cmpq %rbp, %r13
jne 0x142f05
andq 0x20(%r15), %rax
movq 0x20(%r14), %rdi
movl (%rdi,%rbp,8), %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
addq %rax, %rdi
andl $0x1, %r12d
movq %rdi, 0x30(%rsp,%r12,8)
cmpq %rbp, %r13
ja 0x142f13
movl %ebx, %eax
incl %ebx
cmpq %rax, %r10
ja 0x142ed3
movq 0x30(%rsp), %rax
movq 0x38(%rsp), %rcx
jmp 0x142f2d
movq $-0x1, %rcx
movq $-0x1, %rax
movq %r9, %r10
shrq $0x3, %r10
cmpq $-0x1, %r9
cmoveq %r9, %r10
cmpq %r10, %rax
cmovbq %rax, %r10
movl $0x0, %eax
adcq $-0x1, %rax
cmpq %r10, %rcx
movq %r10, %rbx
cmovbq %rcx, %rbx
movq %rax, %r11
movl $0x1, %edi
cmovbq %rdi, %r11
cmpq $-0x1, %rbx
je 0x142f96
cmpq $-0x1, %r11
je 0x142f96
addq %rax, %rax
cmpq %r10, %rcx
movl $0x0, %ecx
cmovaeq %rax, %rcx
leaq (%rcx,%rbx,4), %rax
movl %r8d, %ecx
andl $0x1, %ecx
orq %rax, %rcx
leaq (%r11,%rcx,2), %r9
movq 0x20(%rsp), %rax
movq %r9, (%rax)
incl %r8d
movq %r8, %rax
cmpq %r8, 0x10(%rsp)
ja 0x142eaa
movq 0x58(%rsp), %rax
movq (%rax), %rdi
movq 0x80(%rax), %rax
movq 0x40(%rsp), %rsi
movl (%rdi,%rsi,4), %ecx
incq %rax
cmpq %rcx, %rax
movq 0x18(%rsp), %r8
jbe 0x142ff2
movl (%rdi,%rbp,4), %edi
cmpl %edi, %ecx
je 0x142ff2
cmpq %rdi, %rax
jbe 0x142ff2
cmpq $-0x1, 0x10(%rdx,%r8,8)
je 0x142ff2
movq (%rsp), %r12
movq 0x48(%rsp), %rcx
movq 0x8(%rsp), %r9
jmp 0x1431a6
movq (%rsp), %r12
cmpq %r12, 0x10(%rsp)
movq 0x8(%rsp), %r9
jbe 0x143197
leal (,%rbp,2), %eax
movl %eax, 0x8(%rsp)
leal 0x1(,%rbp,2), %eax
movl %eax, 0x2c(%rsp)
movq 0x20(%r14), %rax
movl %r12d, %r13d
shrl %r13d
movl (%rax,%r13,8), %esi
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andq %rdx, %rsi
movl (%rax,%rbp,8), %ecx
andq %rdx, %rcx
subq $0x8, %rsp
movl %r12d, %edi
movl 0x10(%rsp), %edx
movq 0x90(%rsp), %rbx
movq %rbx, %r8
movq 0x68(%rsp), %r9
leaq 0x78(%rsp), %rax
pushq %rax
movq 0x68(%rsp), %r15
pushq %r15
pushq 0x80(%rsp)
callq 0x1429c7
addq $0x20, %rsp
movq %rax, 0x20(%rsp)
movq 0x20(%r14), %rax
movl (%rax,%r13,8), %esi
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andq %rdx, %rsi
movl (%rax,%rbp,8), %ecx
andq %rdx, %rcx
subq $0x8, %rsp
movl %r12d, %edi
movl 0x34(%rsp), %edx
movq %rbx, %r8
movq 0x68(%rsp), %r9
leaq 0x80(%rsp), %rax
pushq %rax
pushq %r15
movq 0x80(%rsp), %r15
pushq %r15
callq 0x1429c7
movq 0x38(%rsp), %r10
addq $0x20, %rsp
movq 0x50(%rsp), %rcx
movq 0x10(%rcx), %rdx
movq 0x10(%rdx,%r10,8), %rcx
movq %rcx, %rsi
shrq $0x3, %rsi
cmpq $-0x1, %rcx
cmoveq %rcx, %rsi
movq 0x20(%rsp), %rcx
cmpq %rsi, %rcx
jae 0x1430fa
movl $0x2, %r8d
movq 0x70(%rsp), %rdi
movq %rcx, %rsi
xorl %ecx, %ecx
jmp 0x14310f
movq $-0x2, %r8
movq $-0x1, %rcx
movq $-0x1, %rdi
cmpq %rsi, %rax
movq 0x90(%rsp), %r14
jae 0x14312f
movl $0x2, %r8d
movl $0x1, %ecx
movq 0x78(%rsp), %rdi
movq %rax, %rsi
cmpq $-0x1, %rcx
sete %al
cmpq $-0x1, %rsi
sete %r9b
orb %al, %r9b
jne 0x143166
leaq (%rdx,%r10,8), %rax
addq $0x10, %rax
leaq (%r8,%rsi,4), %rsi
movl %r12d, %r8d
andl $0x1, %r8d
xorq %rdi, %r8
addq %rsi, %r8
xorq %rdi, %rcx
leaq (%rcx,%r8,2), %rcx
movq %rcx, (%rax)
incl %r12d
cmpq %r12, 0x10(%rsp)
ja 0x14301c
movq $-0x1, 0x38(%rsp)
movq 0x50(%rsp), %rax
movq (%rax), %r9
movq $-0x1, %rax
movq 0x40(%rsp), %rsi
movq (%rsp), %r12
jmp 0x14319c
movq 0x30(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x48(%rsp), %rcx
incl %ecx
cmpq %rcx, %r9
ja 0x142e51
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq