// File: chhylp123[P]hifiasm/Overlaps.cpp
// Function: asg_arc_identify_simple_bubbles_pthread(void*)
void* asg_arc_identify_simple_bubbles_pthread(void* arg)
{
    int thr_ID = ((para_for_simple_bub*)arg)->threadID;
    int thr_num = ((para_for_simple_bub*)arg)->thread_num;
    asg_t *g = ((para_for_simple_bub*)arg)->g;
    int check_cross = ((para_for_simple_bub*)arg)->check_cross;
    ///the reason is that each read has two direction (query->target, target->query)    

	uint32_t v, w, n_vtx = g->n_seq * 2;
    buf_t b;
    memset(&b, 0, sizeof(buf_t));
    long long l, i;
    ///for (v = 0; v < n_vtx; ++v)
    for (v = thr_ID; v < n_vtx; v = v + thr_num) 
    {
        if (g->seq[v>>1].del) continue;

        b.b.n = 0;

        if(g->seq_vis[v] != 1)
        {
            ///if(detect_bubble_with_bubbles(g, v, &w, &l, &b, (uint32_t)-1))
            if(detect_bubble_with_bubbles(g, v, &w, &l, &b, SMALL_BUBBLE_SIZE))
            {
                for (i = 0; i < (long long)b.b.n; i++)
                {
                    if(b.b.a[i] != (v>>1) && b.b.a[i] != (w>>1))
                    {
                        g->seq_vis[b.b.a[i]<<1] = 1;
                        g->seq_vis[(b.b.a[i]<<1) + 1] = 1;
                    }
                }
                g->seq_vis[v] = 1;
                g->seq_vis[w^1] = 1;
            }
        }

        if(check_cross == 1 && check_if_cross(g, v))
        {
            g->seq_vis[v] = 2;
        }
    }
    free(b.b.a);

    free(arg);

    return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x1c(%rbp)
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
shll %eax
movl %eax, -0x28(%rbp)
leaq -0x90(%rbp), %rdi
xorl %esi, %esi
movl $0x68, %edx
callq 0x2100
movl -0xc(%rbp), %eax
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x28(%rbp), %eax
jae 0xd8347
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x20(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0xd81fd
jmp 0xd8339
movq $0x0, -0x58(%rbp)
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x20(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x1, %eax
je 0xd8311
movq -0x18(%rbp), %rdi
movl -0x20(%rbp), %esi
leaq -0x24(%rbp), %rdx
leaq -0x98(%rbp), %rcx
leaq -0x90(%rbp), %r8
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
callq 0xd5400
cmpl $0x0, %eax
je 0xd830f
movq $0x0, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
cmpq -0x58(%rbp), %rax
jge 0xd82ec
movq -0x48(%rbp), %rax
movq -0xa0(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl -0x20(%rbp), %ecx
shrl %ecx
cmpl %ecx, %eax
je 0xd82d3
movq -0x48(%rbp), %rax
movq -0xa0(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl -0x24(%rbp), %ecx
shrl %ecx
cmpl %ecx, %eax
je 0xd82d3
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x48(%rbp), %rcx
movq -0xa0(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
shll %ecx
movl %ecx, %ecx
movb $0x1, (%rax,%rcx)
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x48(%rbp), %rcx
movq -0xa0(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
shll %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movb $0x1, (%rax,%rcx)
jmp 0xd82d5
movq -0xa0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xa0(%rbp)
jmp 0xd8255
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x20(%rbp), %ecx
movb $0x1, (%rax,%rcx)
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x24(%rbp), %ecx
xorl $0x1, %ecx
movl %ecx, %ecx
movb $0x1, (%rax,%rcx)
jmp 0xd8311
cmpl $0x1, -0x1c(%rbp)
jne 0xd8337
movq -0x18(%rbp), %rdi
movl -0x20(%rbp), %esi
callq 0xd7cb0
cmpl $0x0, %eax
je 0xd8337
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x20(%rbp), %ecx
movb $0x2, (%rax,%rcx)
jmp 0xd8339
movl -0x20(%rbp), %eax
addl -0x10(%rbp), %eax
movl %eax, -0x20(%rbp)
jmp 0xd81d2
movq -0x48(%rbp), %rdi
callq 0x2210
movq -0x8(%rbp), %rdi
callq 0x2210
xorl %eax, %eax
addq $0xa0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)