// File: 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
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x48(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
shll %eax
movl %eax, -0x54(%rbp)
movq -0x48(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x10(%rbp), %rcx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x1cde66
jmp 0x1ce55e
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x10(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x1cde89
jmp 0x1ce55e
movl $0x0, -0x60(%rbp)
movl -0x60(%rbp), %eax
movq -0x50(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x1ce55e
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x60(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movb 0x18(%rax), %al
shrb $0x7, %al
cmpb $0x0, %al
je 0x1cdec1
jmp 0x1ce550
movq -0x10(%rbp), %rax
movq -0x50(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x60(%rbp), %edx
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
cmpq %rcx, %rax
jne 0x1cdee4
jmp 0x1ce550
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x60(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x5c(%rbp)
movq -0x10(%rbp), %rax
shlq %rax
movl %eax, -0x58(%rbp)
movl -0x58(%rbp), %eax
movq -0x10(%rbp), %rcx
addq $0x1, %rcx
shlq %rcx
cmpq %rcx, %rax
jae 0x1ce1c4
movq $-0x1, -0x88(%rbp)
movq $-0x1, -0x90(%rbp)
movq $-0x1, -0x78(%rbp)
movq $-0x1, -0x80(%rbp)
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %eax
movq -0x30(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x58(%rbp), %edx
shlq $0x5, %rdx
addq %rdx, %rcx
cmpq (%rcx), %rax
jae 0x1ce021
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x58(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movl -0x64(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq -0x30(%rbp), %rcx
movq 0x18(%rcx), %rcx
shrq %cl, %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
shrq %rax
movl -0x5c(%rbp), %ecx
cmpq %rcx, %rax
jne 0x1cdffd
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x58(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movl -0x64(%rbp), %ecx
movq (%rax,%rcx,8), %rcx
movq -0x30(%rbp), %rax
andq 0x20(%rax), %rcx
movq -0x48(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x98(%rbp), %rdx
shrq %rdx
movl (%rax,%rdx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
addq %rax, %rcx
movq -0x98(%rbp), %rax
andq $0x1, %rax
movq %rcx, -0x80(%rbp,%rax,8)
movq -0x98(%rbp), %rax
shrq %rax
movl -0x5c(%rbp), %ecx
cmpq %rcx, %rax
jbe 0x1ce011
jmp 0x1ce021
jmp 0x1ce013
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x1cdf4a
movq $-0x1, -0xb0(%rbp)
movq $-0x1, -0xa8(%rbp)
movq $-0x1, -0xa0(%rbp)
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x60(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
cmpq $-0x1, 0x10(%rax)
je 0x1ce07c
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x60(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
shrq $0x3, %rax
movq %rax, -0xa0(%rbp)
movq -0x80(%rbp), %rax
cmpq -0xa0(%rbp), %rax
jae 0x1ce0aa
movq -0x80(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq $0x0, -0xa8(%rbp)
movq $0x0, -0xb0(%rbp)
movq -0x78(%rbp), %rax
cmpq -0xa0(%rbp), %rax
jae 0x1ce0d8
movq -0x78(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq $0x1, -0xa8(%rbp)
movq $0x0, -0xb0(%rbp)
cmpq $-0x1, -0xa8(%rbp)
je 0x1ce1b4
cmpq $-0x1, -0xa0(%rbp)
je 0x1ce1b4
movq -0xa0(%rbp), %rcx
shlq %rcx
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x60(%rbp), %edx
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x10(%rax)
movq -0xb0(%rbp), %rcx
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x60(%rbp), %edx
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
addq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x60(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rcx
shlq %rcx
movq %rcx, 0x10(%rax)
movl -0x58(%rbp), %eax
andl $0x1, %eax
movl %eax, %eax
movl %eax, %ecx
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x60(%rbp), %edx
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
addq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x60(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rcx
shlq %rcx
movq %rcx, 0x10(%rax)
movq -0xa8(%rbp), %rcx
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x60(%rbp), %edx
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
addq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
jmp 0x1ce1b6
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x1cdf06
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq -0x10(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x38(%rbp), %rcx
movq 0x80(%rcx), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jae 0x1ce242
movq -0x38(%rbp), %rax
movq (%rax), %rax
movl -0x5c(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movq -0x38(%rbp), %rcx
movq 0x80(%rcx), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jae 0x1ce242
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq -0x10(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x38(%rbp), %rcx
movq (%rcx), %rcx
movl -0x5c(%rbp), %edx
cmpl (%rcx,%rdx,4), %eax
je 0x1ce242
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x60(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
cmpq $-0x1, 0x10(%rax)
je 0x1ce242
jmp 0x1ce550
movq -0x10(%rbp), %rax
shlq %rax
movl %eax, -0x58(%rbp)
movl -0x58(%rbp), %eax
movq -0x10(%rbp), %rcx
addq $0x1, %rcx
shlq %rcx
cmpq %rcx, %rax
jae 0x1ce54e
movq $-0x1, -0x88(%rbp)
movq $-0x1, -0x90(%rbp)
movq $-0x1, -0x78(%rbp)
movq $-0x1, -0x80(%rbp)
movl -0x58(%rbp), %edi
movq -0x48(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x58(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %esi
movl -0x5c(%rbp), %edx
shll %edx
movq -0x48(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x5c(%rbp), %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %ecx
movq -0x40(%rbp), %r8
movl -0x54(%rbp), %eax
movl %eax, %r9d
movq -0x30(%rbp), %r11
movq -0x38(%rbp), %r10
leaq -0xc0(%rbp), %rax
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x1cd7b0
movq %rax, -0x90(%rbp)
movl -0x58(%rbp), %edi
movq -0x48(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x58(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %esi
movl -0x5c(%rbp), %edx
shll %edx
addl $0x1, %edx
movq -0x48(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x5c(%rbp), %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %ecx
movq -0x40(%rbp), %r8
movl -0x54(%rbp), %eax
movl %eax, %r9d
movq -0x30(%rbp), %r11
movq -0x38(%rbp), %r10
leaq -0xc0(%rbp), %rax
addq $0x8, %rax
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x1cd7b0
movq %rax, -0x88(%rbp)
movq $-0x1, -0xc8(%rbp)
movq $-0x1, -0xb0(%rbp)
movq $-0x1, -0xa8(%rbp)
movq $-0x1, -0xa0(%rbp)
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x60(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
cmpq $-0x1, 0x10(%rax)
je 0x1ce3d0
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x60(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
shrq $0x3, %rax
movq %rax, -0xa0(%rbp)
movq -0x90(%rbp), %rax
cmpq -0xa0(%rbp), %rax
jae 0x1ce412
movq -0x90(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq $0x0, -0xa8(%rbp)
movq $0x1, -0xb0(%rbp)
movq -0xc0(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x88(%rbp), %rax
cmpq -0xa0(%rbp), %rax
jae 0x1ce454
movq -0x88(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq $0x1, -0xa8(%rbp)
movq $0x1, -0xb0(%rbp)
movq -0xb8(%rbp), %rax
movq %rax, -0xc8(%rbp)
cmpq $-0x1, -0xa8(%rbp)
je 0x1ce53e
cmpq $-0x1, -0xa0(%rbp)
je 0x1ce53e
movq -0xa0(%rbp), %rcx
shlq %rcx
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x60(%rbp), %edx
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x10(%rax)
movq -0xb0(%rbp), %rcx
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x60(%rbp), %edx
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
addq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x60(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rcx
shlq %rcx
movq %rcx, 0x10(%rax)
movl -0x58(%rbp), %eax
andl $0x1, %eax
movl %eax, %eax
movl %eax, %ecx
xorq -0xc8(%rbp), %rcx
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x60(%rbp), %edx
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
addq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x60(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rcx
shlq %rcx
movq %rcx, 0x10(%rax)
movq -0xa8(%rbp), %rcx
xorq -0xc8(%rbp), %rcx
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x60(%rbp), %edx
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
addq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
jmp 0x1ce540
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x1ce24c
jmp 0x1ce550
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x1cde90
addq $0xe0, %rsp
popq %rbp
retq
nopw (%rax,%rax)