// File: /workspace/github_cpp_makefile_star2_O1/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 0x13d34c
movq 0x8(%rdi), %rax
movq 0x10(%rax), %r10
leaq (%rsi,%rsi,2), %rax
shlq $0x4, %rax
cmpq $0x0, (%r10,%rax)
je 0x13d34c
addq %rax, %r10
cmpq $0x0, (%r10)
je 0x13d34c
movq 0x10(%rdi), %r15
movq 0x18(%rdi), %rax
movq %rax, 0x50(%rsp)
movq 0x20(%rdi), %rax
movslq %edx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x88(%rsp)
movl 0x14(%r14), %eax
addl %eax, %eax
leal (%rsi,%rsi), %ebp
leaq 0x2(,%rsi,2), %rcx
movq %rcx, 0x18(%rsp)
movl %eax, %eax
movq %rax, 0x60(%rsp)
xorl %edi, %edi
movq %rsi, 0x40(%rsp)
movq %r10, 0x58(%rsp)
movq %r14, 0x90(%rsp)
movq %r15, 0x68(%rsp)
movq %rbp, 0x20(%rsp)
movq 0x10(%r10), %rcx
leaq (%rdi,%rdi,4), %rax
movq %rax, 0x8(%rsp)
cmpb $0x0, 0x18(%rcx,%rax,8)
js 0x13d341
movq 0x8(%rsp), %rax
leaq (%rcx,%rax,8), %rax
movl 0x8(%rax), %r12d
cmpq %rsi, %r12
je 0x13d341
movq %rcx, 0x10(%rsp)
movq %rdi, 0x48(%rsp)
cmpq %rbp, 0x18(%rsp)
jbe 0x13d14c
movq 0x10(%r15), %rdx
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rcx
leaq (%rcx,%rax,8), %rax
addq $0x10, %rax
movq %rax, %rsi
movq (%rax), %r8
movq 0x20(%rsp), %rdi
movq %rdi, %rax
shlq $0x5, %rax
pcmpeqd %xmm0, %xmm0
movdqa %xmm0, 0x30(%rsp)
movq (%rdx,%rax), %r9
testq %r9, %r9
je 0x13d0c6
addq %rdx, %rax
movq 0x10(%rax), %r10
movq 0x18(%r15), %rcx
movl $0x1, %r11d
xorl %eax, %eax
movq (%r10,%rax,8), %rax
movq %rax, %rbx
shrq %cl, %rbx
movq %rbx, %r13
shrq %r13
cmpq %r12, %r13
jne 0x13d0b6
andq 0x20(%r15), %rax
movq 0x20(%r14), %rbp
movl (%rbp,%r13,8), %ebp
andl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
addq %rax, %rbp
andl $0x1, %ebx
movq %rbp, 0x30(%rsp,%rbx,8)
cmpq %r12, %r13
ja 0x13d0c6
movl %r11d, %eax
incl %r11d
cmpq %rax, %r9
ja 0x13d083
movq %r8, %rcx
shrq $0x3, %rcx
cmpq $-0x1, %r8
cmoveq %r8, %rcx
movq 0x30(%rsp), %rax
cmpq %rcx, %rax
cmovbq %rax, %rcx
movq 0x38(%rsp), %r11
movl $0x0, %r10d
adcq $-0x1, %r10
cmpq %rcx, %r11
movq %rcx, %rax
cmovbq %r11, %rax
movq %r10, %r9
movl $0x1, %ebx
cmovbq %rbx, %r9
cmpq $-0x1, %r9
sete %bpl
cmpq $-0x1, %rax
sete %bl
orb %bpl, %bl
jne 0x13d13c
addq %r10, %r10
cmpq %rcx, %r11
movl $0x0, %ecx
cmovaeq %r10, %rcx
leaq (%rcx,%rax,4), %rax
movl %edi, %ecx
andl $0x1, %ecx
orq %rax, %rcx
leaq (%r9,%rcx,2), %r8
movq %r8, (%rsi)
incl %edi
movq %rdi, %rax
cmpq %rdi, 0x18(%rsp)
ja 0x13d059
movq 0x50(%rsp), %rax
movq (%rax), %rdx
movq 0x80(%rax), %rax
movq 0x40(%rsp), %rsi
movl (%rdx,%rsi,4), %ecx
incq %rax
cmpq %rcx, %rax
movq 0x58(%rsp), %r10
movq 0x20(%rsp), %rbp
movq 0x48(%rsp), %rdi
movq 0x10(%rsp), %r8
jbe 0x13d19d
movl (%rdx,%r12,4), %edx
cmpl %edx, %ecx
je 0x13d19d
cmpq %rdx, %rax
jbe 0x13d19d
movq 0x8(%rsp), %rax
cmpq $-0x1, 0x10(%r8,%rax,8)
jne 0x13d341
cmpq %rbp, 0x18(%rsp)
jbe 0x13d337
leal (%r12,%r12), %eax
movl %eax, 0x2c(%rsp)
leal 0x1(,%r12,2), %eax
movl %eax, 0x28(%rsp)
movq 0x20(%r14), %rax
movl %ebp, %r13d
shrl %r13d
movl (%rax,%r13,8), %esi
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andq %rdx, %rsi
movl (%rax,%r12,8), %ecx
andq %rdx, %rcx
subq $0x8, %rsp
movl %ebp, %edi
movl 0x34(%rsp), %edx
movq 0x90(%rsp), %rbx
movq %rbx, %r8
movq 0x68(%rsp), %r9
leaq 0x78(%rsp), %rax
pushq %rax
movq 0x60(%rsp), %r15
pushq %r15
pushq 0x80(%rsp)
callq 0x13cb83
addq $0x20, %rsp
movq %rax, 0x10(%rsp)
movq 0x20(%r14), %rax
movl (%rax,%r13,8), %esi
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andq %rdx, %rsi
movl (%rax,%r12,8), %ecx
andq %rdx, %rcx
subq $0x8, %rsp
movl %ebp, %edi
movl 0x30(%rsp), %edx
movq %rbx, %r8
movq 0x68(%rsp), %r9
leaq 0x80(%rsp), %rax
pushq %rax
pushq %r15
movq 0x80(%rsp), %r15
pushq %r15
callq 0x13cb83
movq 0x78(%rsp), %r10
addq $0x20, %rsp
movq 0x10(%r10), %rcx
movq 0x8(%rsp), %rdx
movq 0x10(%rcx,%rdx,8), %rdx
movq %rdx, %rsi
shrq $0x3, %rsi
cmpq $-0x1, %rdx
cmoveq %rdx, %rsi
movq 0x10(%rsp), %rdx
cmpq %rsi, %rdx
jae 0x13d29a
movl $0x2, %r8d
movq 0x70(%rsp), %rdi
movq %rdx, %rsi
xorl %edx, %edx
jmp 0x13d2af
movq $-0x2, %r8
movq $-0x1, %rdx
movq $-0x1, %rdi
cmpq %rsi, %rax
movq 0x90(%rsp), %r14
jae 0x13d2cf
movl $0x2, %r8d
movl $0x1, %edx
movq 0x78(%rsp), %rdi
movq %rax, %rsi
cmpq $-0x1, %rdx
sete %al
cmpq $-0x1, %rsi
sete %r9b
orb %al, %r9b
jne 0x13d309
movq 0x8(%rsp), %rax
leaq (%rcx,%rax,8), %rax
addq $0x10, %rax
leaq (%r8,%rsi,4), %rcx
movl %ebp, %esi
andl $0x1, %esi
xorq %rdi, %rsi
addq %rcx, %rsi
xorq %rdi, %rdx
leaq (%rdx,%rsi,2), %rcx
movq %rcx, (%rax)
incl %ebp
cmpq %rbp, 0x18(%rsp)
ja 0x13d1bc
movq $-0x1, 0x38(%rsp)
movq $-0x1, %rax
movq 0x40(%rsp), %rsi
movq 0x20(%rsp), %rbp
movq 0x48(%rsp), %rdi
jmp 0x13d33c
movq 0x30(%rsp), %rax
movq %rax, 0x30(%rsp)
incl %edi
cmpq %rdi, (%r10)
ja 0x13cff2
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq