// File: /workspace/github_c_makefile_star2_O0/c-zhou[P]oatk/alignment.c
// Function: scg_read_alignment
void scg_read_alignment(sr_db_t *sr_db, scg_ra_v *ra_v, scg_t *g, int n_threads, int for_unzip)
{
    if (sr_db->n == 0 || !asmg_vtx_n1(g->utg_asmg)) return;

    int i;
    uint64_t j, b;

    if (n_threads == 0)
        n_threads = 1;

    if (pthread_mutex_init(&lock, NULL) != 0) {
        fprintf(stderr, "[E::%s] mutex init failed\n", __func__);
        return;
    }

    int64_t *old_ra;
    scg_ra_t *ra;
    MYCALLOC(old_ra, sr_db->n);
    if (for_unzip && ra_v->n > 0) {
        // for unzipping purpose
        // only map reads previously mapped to at least three unitigs
        // only map previouly mapped reads
        // only keep mapping results without mapping score decrease
        double fractpart, intpart;
        uint64_t sid;
        for (j = 0; j < ra_v->n; ++j) {
            ra = &ra_v->a[j];
            sid = ra->sid;
            if (ra->n > 2 && (old_ra[sid] & 1) == 0) {
                fractpart = modf(ra->s, &intpart);
                if (fractpart < DBL_EPSILON)
                    intpart -= 1;
                old_ra[sid] = (uint64_t) intpart << 1 | 1;
            }
        }
    } else {
        // map every reads
        for (j = 0; j < sr_db->n; ++j) old_ra[j] = 1;
    }

    b = sr_db->n / n_threads + 1;
    p_data_t *dat;
    MYCALLOC(dat, n_threads);
    for (i = 0; i < n_threads; ++i) {
        dat[i].tid = i;
        dat[i].sr = sr_db->a + i * b;
        dat[i].old_ra = old_ra + i * b;
        MYCALLOC(dat[i].ra_v, 1);
        dat[i].g = g;
        if (sr_db->n >= (i + 1) * b) {
            dat[i].n = b;
        } else {
            dat[i].n = sr_db->n - i * b;
            break;
        }
    }

    pthread_t threads[n_threads];
    for (i = 1; i < n_threads; ++i)
        pthread_create(threads + i, NULL, scg_ra_analysis_thread, dat + i);

    scg_ra_analysis_thread(dat);

    for (i = 1; i < n_threads; ++i)
        pthread_join(threads[i], NULL);

    // clean old results in ra_v
    scg_ra_v_clean(ra_v);
    // collect results
    ra_v->m = 0;
    for (i = 0; i < n_threads; ++i)
        ra_v->m += dat[i].ra_v->n;
    ra_v->n = 0;
    MYMALLOC(ra_v->a, ra_v->m);
    for (i = 0; i < n_threads; ++i) {
        // copy data
        memcpy(ra_v->a + ra_v->n, dat[i].ra_v->a, sizeof(scg_ra_t) * dat[i].ra_v->n);
        ra_v->n += dat[i].ra_v->n;
        free(dat[i].ra_v->a);
        free(dat[i].ra_v);
    }

    uint64_t n_r, n_m, n_u, n;
    n_r = n_m = n_u = 0;
    for (n = 0; n < sr_db->n; ++n)
        n_r += sr_db->a[n].n > 0;
    for (i = 0; i < n_threads; ++i) {
        n_m += dat[i].m_stats[0];
        n_u += dat[i].m_stats[1];
    }
    fprintf(stderr ,"[M::%s] %lu mappable reads, %lu mapped (%lu unique mapping)\n", __func__, n_r, n_m, n_u);

    pthread_mutex_destroy(&lock);
    free(old_ra);
    free(dat);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, (%rax)
je 0x25f6b
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x26570
cmpq $0x0, %rax
jne 0x25f70
jmp 0x26561
cmpl $0x0, -0x1c(%rbp)
jne 0x25f7d
movl $0x1, -0x1c(%rbp)
leaq 0xe54c(%rip), %rdi      # 0x344d0
xorl %eax, %eax
movl %eax, %esi
callq 0x24f0
cmpl $0x0, %eax
je 0x25fb6
movq 0xe05f(%rip), %rax      # 0x33ff8
movq (%rax), %rdi
leaq 0x8dc5(%rip), %rsi      # 0x2ed68
leaq 0x8dd9(%rip), %rdx      # 0x2ed83
movb $0x0, %al
callq 0x2290
jmp 0x26561
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movl $0x8, %esi
callq 0x2250
movq %rax, -0x40(%rbp)
cmpl $0x0, -0x20(%rbp)
je 0x260d1
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
jbe 0x260d1
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x260cf
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x30(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x48(%rbp), %rax
cmpl $0x2, 0x8(%rax)
jbe 0x260bc
movq -0x40(%rbp), %rax
movq -0x60(%rbp), %rcx
movq (%rax,%rcx,8), %rax
andq $0x1, %rax
cmpq $0x0, %rax
jne 0x260bc
movq -0x48(%rbp), %rax
movsd 0x18(%rax), %xmm0
leaq -0x58(%rbp), %rdi
callq 0x21b0
movsd %xmm0, -0x50(%rbp)
movsd 0x7717(%rip), %xmm0     # 0x2d778
ucomisd -0x50(%rbp), %xmm0
jbe 0x2607e
movsd -0x58(%rbp), %xmm0
movsd 0x7713(%rip), %xmm1     # 0x2d788
subsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x58(%rbp), %xmm0
movsd 0x8cd5(%rip), %xmm2     # 0x2ed60
movaps %xmm0, %xmm1
subsd %xmm2, %xmm1
cvttsd2si %xmm1, %rax
cvttsd2si %xmm0, %rdx
movq %rdx, %rcx
sarq $0x3f, %rcx
andq %rcx, %rax
orq %rax, %rdx
shlq %rdx
orq $0x1, %rdx
movq -0x40(%rbp), %rax
movq -0x60(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x260be
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x25feb
jmp 0x26106
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x26104
movq -0x40(%rbp), %rax
movq -0x30(%rbp), %rcx
movq $0x1, (%rax,%rcx,8)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x260d9
jmp 0x26106
movq -0x8(%rbp), %rax
movq (%rax), %rax
movslq -0x1c(%rbp), %rcx
xorl %edx, %edx
divq %rcx
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movslq -0x1c(%rbp), %rdi
movl $0x50, %esi
callq 0x2250
movq %rax, -0x68(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x26250
movl -0x24(%rbp), %ecx
movq -0x68(%rbp), %rax
movslq -0x24(%rbp), %rdx
imulq $0x50, %rdx, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rcx
movslq -0x24(%rbp), %rax
imulq -0x38(%rbp), %rax
imulq $0x58, %rax, %rax
addq %rax, %rcx
movq -0x68(%rbp), %rax
movslq -0x24(%rbp), %rdx
imulq $0x50, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq -0x40(%rbp), %rcx
movslq -0x24(%rbp), %rax
imulq -0x38(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rcx
movq -0x68(%rbp), %rax
movslq -0x24(%rbp), %rdx
imulq $0x50, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x20(%rax)
movl $0x1, %edi
movl $0x18, %esi
callq 0x2250
movq %rax, %rcx
movq -0x68(%rbp), %rax
movslq -0x24(%rbp), %rdx
imulq $0x50, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rcx
movq -0x68(%rbp), %rax
movslq -0x24(%rbp), %rdx
imulq $0x50, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x18(%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl -0x24(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
imulq -0x38(%rbp), %rcx
cmpq %rcx, %rax
jb 0x26218
movq -0x38(%rbp), %rcx
movq -0x68(%rbp), %rax
movslq -0x24(%rbp), %rdx
imulq $0x50, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x28(%rax)
jmp 0x26240
movq -0x8(%rbp), %rax
movq (%rax), %rcx
movslq -0x24(%rbp), %rax
imulq -0x38(%rbp), %rax
subq %rax, %rcx
movq -0x68(%rbp), %rax
movslq -0x24(%rbp), %rdx
imulq $0x50, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x28(%rax)
jmp 0x26250
jmp 0x26242
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x26137
movl -0x1c(%rbp), %eax
movq %rsp, %rcx
movq %rcx, -0x70(%rbp)
leaq 0xf(,%rax,8), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0xa0(%rbp)
movq %rcx, %rsp
movq %rax, -0x78(%rbp)
movl $0x1, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x262c5
movq -0xa0(%rbp), %rdi
movslq -0x24(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rdi
movq -0x68(%rbp), %rcx
movslq -0x24(%rbp), %rax
imulq $0x50, %rax, %rax
addq %rax, %rcx
xorl %eax, %eax
movl %eax, %esi
leaq 0x32b(%rip), %rdx       # 0x265e0
callq 0x2370
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x26281
movq -0x68(%rbp), %rdi
callq 0x265e0
movl $0x1, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x26300
movq -0xa0(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x24a0
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x262d5
movq -0x10(%rbp), %rdi
callq 0x25ec0
movq -0x10(%rbp), %rax
movq $0x0, 0x8(%rax)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x26351
movq -0x68(%rbp), %rax
movslq -0x24(%rbp), %rcx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movq (%rax), %rcx
movq -0x10(%rbp), %rax
addq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x2631c
movq -0x10(%rbp), %rax
movq $0x0, (%rax)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
shlq $0x5, %rdi
callq 0x2320
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x26439
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rax
shlq $0x5, %rax
addq %rax, %rdi
movq -0x68(%rbp), %rax
movslq -0x24(%rbp), %rcx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rsi
movq -0x68(%rbp), %rax
movslq -0x24(%rbp), %rcx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movq (%rax), %rdx
shlq $0x5, %rdx
callq 0x22c0
movq -0x68(%rbp), %rax
movslq -0x24(%rbp), %rcx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movq (%rax), %rcx
movq -0x10(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movq -0x68(%rbp), %rax
movslq -0x24(%rbp), %rcx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rdi
callq 0x2060
movq -0x68(%rbp), %rax
movslq -0x24(%rbp), %rcx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rdi
callq 0x2060
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x2637f
movq $0x0, -0x90(%rbp)
movq $0x0, -0x88(%rbp)
movq $0x0, -0x80(%rbp)
movq $0x0, -0x98(%rbp)
movq -0x98(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x264af
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x58, -0x98(%rbp), %rcx
addq %rcx, %rax
cmpl $0x0, 0x38(%rax)
seta %al
andb $0x1, %al
movzbl %al, %eax
cltq
addq -0x80(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x98(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x98(%rbp)
jmp 0x26462
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x2650b
movq -0x68(%rbp), %rax
movslq -0x24(%rbp), %rcx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movq 0x30(%rax), %rax
addq -0x88(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x68(%rbp), %rax
movslq -0x24(%rbp), %rcx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movq 0x38(%rax), %rax
addq -0x90(%rbp), %rax
movq %rax, -0x90(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x264b6
movq 0xdae6(%rip), %rax      # 0x33ff8
movq (%rax), %rdi
movq -0x80(%rbp), %rcx
movq -0x88(%rbp), %r8
movq -0x90(%rbp), %r9
leaq 0x8868(%rip), %rsi      # 0x2ed96
leaq 0x884e(%rip), %rdx      # 0x2ed83
movb $0x0, %al
callq 0x2290
leaq 0xdf8d(%rip), %rdi      # 0x344d0
callq 0x2190
movq -0x40(%rbp), %rdi
callq 0x2060
movq -0x68(%rbp), %rdi
callq 0x2060
movq -0x70(%rbp), %rax
movq %rax, %rsp
movq %rbp, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)