// File: /workspace/github_cpp_makefile_star2_O2/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 $0x88, %rsp
movq (%rdi), %r14
movq 0x20(%r14), %rax
cmpl $0x0, (%rax,%rsi,8)
js 0xfbb45
movq 0x8(%rdi), %rax
movq 0x10(%rax), %rax
imulq $0x30, %rsi, %rcx
movq %rax, 0x8(%rsp)
movq (%rax,%rcx), %rax
testq %rax, %rax
je 0xfbb45
movq 0x10(%rdi), %r15
movq 0x18(%rdi), %r8
movq %r8, 0x18(%rsp)
movq 0x20(%rdi), %rdi
movslq %edx, %rdx
movq (%rdi,%rdx,8), %rdx
movq %rdx, 0x68(%rsp)
movl 0x14(%r14), %edx
addl %edx, %edx
addq %rcx, 0x8(%rsp)
leal (%rsi,%rsi), %ecx
movl %ecx, 0x4(%rsp)
leaq 0x2(,%rsi,2), %rcx
movq %rcx, 0x48(%rsp)
movl %edx, %ecx
movq %rcx, 0x40(%rsp)
xorl %r9d, %r9d
movq %rsi, 0x60(%rsp)
movq %r14, 0x70(%rsp)
movl %r9d, %r9d
cmpq %r9, %rax
jbe 0xfbb45
movq 0x8(%rsp), %rdi
movq 0x10(%rdi), %r8
imulq $0x28, %r9, %r10
cmpb $0x0, 0x18(%r8,%r10)
js 0xfbb3d
movq %r9, 0x10(%rsp)
leaq (%r8,%r10), %rdi
movl 0x8(%rdi), %ebp
cmpq %rsi, %rbp
je 0xfbb38
movq %r10, 0x78(%rsp)
leaq (%r8,%r10), %r13
addq $0x10, %r13
movl 0x4(%rsp), %edi
movl %edi, %edi
cmpq %rdi, 0x48(%rsp)
jbe 0xfb98a
pcmpeqd %xmm0, %xmm0
movdqa %xmm0, 0x30(%rsp)
movq 0x10(%r15), %rcx
movq %rdi, %r8
shlq $0x5, %r8
leaq (%rcx,%r8), %rdx
movq (%rcx,%r8), %r8
xorl %r9d, %r9d
movl %r9d, %r9d
cmpq %r9, %r8
jbe 0xfb907
movq 0x10(%rdx), %rcx
movq (%rcx,%r9,8), %r11
movb 0x18(%r15), %cl
movq %r11, %r10
shrq %cl, %r10
movq %r10, %rcx
shrq %rcx
cmpq %rbp, %rcx
jne 0xfb8ff
andq 0x20(%r15), %r11
movq 0x20(%r14), %rbx
movl (%rbx,%rbp,8), %ebx
andl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
addq %r11, %rbx
andl $0x1, %r10d
movq %rbx, 0x30(%rsp,%r10,8)
incl %r9d
cmpq %rbp, %rcx
jbe 0xfb8bd
movq (%r13), %rcx
movq %rcx, %r8
shrq $0x3, %r8
cmpq $-0x1, %rcx
cmoveq %rcx, %r8
movq 0x30(%rsp), %rcx
cmpq %r8, %rcx
cmovbq %rcx, %r8
movq 0x38(%rsp), %rdx
movl $0x0, %r10d
adcq $-0x1, %r10
cmpq %r8, %rdx
movq %r8, %r11
cmovbq %rdx, %r11
movq %r10, %r9
pushq $0x1
popq %rbx
cmovbq %rbx, %r9
cmpq $-0x1, %r9
sete %bl
cmpq $-0x1, %r11
sete %r12b
orb %bl, %r12b
jne 0xfb983
addq %r10, %r10
cmpq %r8, %rdx
movl $0x0, %r8d
cmovaeq %r10, %r8
leaq (%r8,%r11,4), %r8
movl %edi, %r10d
andl $0x1, %r10d
orq %r8, %r10
leaq (%r9,%r10,2), %r8
movq %r8, (%r13)
incl %edi
jmp 0xfb890
movq 0x18(%rsp), %rdi
movq (%rdi), %r9
movq 0x80(%rdi), %rdi
movl (%r9,%rsi,4), %r8d
incq %rdi
cmpq %r8, %rdi
jbe 0xfb9be
movl (%r9,%rbp,4), %r9d
cmpl %r9d, %r8d
je 0xfb9be
cmpq %r9, %rdi
jbe 0xfb9be
cmpq $-0x1, (%r13)
jne 0xfbb38
leal (,%rbp,2), %eax
movl %eax, 0x28(%rsp)
leal 0x1(,%rbp,2), %eax
movl %eax, 0x24(%rsp)
movl 0x4(%rsp), %ebx
movl %ebx, %eax
cmpq %rax, 0x48(%rsp)
jbe 0xfbb21
movq 0x20(%r14), %rax
movl %ebx, %r12d
shrl %r12d
movl (%rax,%r12,8), %esi
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andq %rdx, %rsi
movl (%rax,%rbp,8), %ecx
andq %rdx, %rcx
subq $0x8, %rsp
movl %ebx, %edi
movl 0x30(%rsp), %edx
movq 0x70(%rsp), %r13
movq %r13, %r8
movq 0x48(%rsp), %r9
leaq 0x58(%rsp), %rax
pushq %rax
pushq 0x28(%rsp)
pushq %r15
callq 0xfb410
addq $0x20, %rsp
movq %rax, 0x80(%rsp)
movq 0x20(%r14), %rax
movl (%rax,%r12,8), %esi
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andq %rdx, %rsi
movl (%rax,%rbp,8), %ecx
andq %rdx, %rcx
subq $0x8, %rsp
movl %ebx, 0x34(%rsp)
movl %ebx, %edi
movl 0x2c(%rsp), %edx
movq %r13, %r8
movq 0x80(%rsp), %r12
movq 0x48(%rsp), %r9
leaq 0x60(%rsp), %rax
pushq %rax
pushq 0x28(%rsp)
pushq %r15
callq 0xfb410
movq 0xa0(%rsp), %rdi
addq $0x20, %rsp
movq 0x8(%rsp), %rcx
movq 0x10(%rcx), %rcx
movq 0x10(%rcx,%r12), %rdx
movq %rdx, %r10
shrq $0x3, %r10
cmpq $-0x1, %rdx
cmoveq %rdx, %r10
pushq $-0x1
popq %rdx
movq %rdx, %rsi
pushq $-0x2
popq %r8
cmpq %r10, %rdi
jae 0xfbac0
movq 0x50(%rsp), %rdx
movq %rdi, %r10
xorl %esi, %esi
pushq $0x2
popq %r8
cmpq %r10, %rax
jae 0xfbad4
movq 0x58(%rsp), %rdx
movq %rax, %r10
pushq $0x1
popq %rsi
pushq $0x2
popq %r8
cmpq $-0x1, %rsi
sete %al
cmpq $-0x1, %r10
sete %r9b
orb %al, %r9b
movq 0x70(%rsp), %r14
movl 0x2c(%rsp), %ebx
jne 0xfbb14
leaq (%rcx,%r12), %rax
addq $0x10, %rax
leaq (%r8,%r10,4), %rcx
movl %ebx, %r8d
andl $0x1, %r8d
xorq %rdx, %r8
addq %rcx, %r8
xorq %rdx, %rsi
leaq (%rsi,%r8,2), %rcx
movq %rcx, (%rax)
incl %ebx
pushq $-0x1
popq %rcx
movq %rcx, %rdx
jmp 0xfb9d8
movq %rdx, 0x38(%rsp)
movq %rcx, 0x30(%rsp)
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq 0x60(%rsp), %rsi
movq 0x10(%rsp), %r9
incl %r9d
jmp 0xfb845
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq