// File: /workspace/github_c_makefile_star2_O3/c-zhou[P]oatk/syncmer.c
// Function: sr_read
void sr_read(sstream_t *s_stream, sr_db_t *sr_db, size_t mD, int n_threads)
{
    if (n_threads == 1) {
        sr_read_single_thread(s_stream, sr_db, mD);
        return;
    }

    sr_db_clean(sr_db);
    sr_db_init(sr_db, sr_db->k, sr_db->s);
    
    if (mD == 0)
        mD = SIZE_MAX;

    p_data_t *dat;
    int t;
    uint64_t batch_n;
    MYCALLOC(dat, n_threads);
    batch_n = 10000;
    for (t = 0; t < n_threads; ++t) {
        dat[t].n_reads = 0;
        MYMALLOC(dat[t].sid, batch_n);
        MYMALLOC(dat[t].name, batch_n);
        MYMALLOC(dat[t].seq, batch_n);
        MYMALLOC(dat[t].len, batch_n);
        MYMALLOC(dat[t].sr_db, 1);
        sr_db_init(dat[t].sr_db, sr_db->k, sr_db->s);
        kv_resize(sr_t, *dat[t].sr_db, batch_n);
    }

    pthread_t threads[n_threads];
    int l;
    uint64_t i, j, n;
    size_t D;
    i = j = n = 0;
    D = 0;
    while ((l = sstream_read(s_stream)) >= 0) {
        t = j / batch_n;
        n = dat[t].n_reads;
        dat[t].sid[n] = i;
        dat[t].name[n] = strdup(s_stream->s->ks->name.s);
        dat[t].seq[n] = strdup(s_stream->s->ks->seq.s);
        dat[t].len[n] = l;
        dat[t].n_reads++;

        ++i, ++j;
        if (j == batch_n * n_threads) {
            do_analysis(dat, threads, n_threads, sr_db);
            j = 0;
        }

        D += l;
        if (D >= mD) {
            fprintf(stderr, "[M::%s] data limit (%lu) reached. Discard the remaining sequences...\n", __func__, mD);
            break;
        }
    }
    if (j > 0) do_analysis(dat, threads, n_threads, sr_db);

    for (t = 0; t < n_threads; ++t) {
        free(dat[t].sid);
        free(dat[t].name);
        free(dat[t].seq);
        free(dat[t].len);
        free(dat[t].sr_db->a);
        free(dat[t].sr_db);
    }
    free(dat);

    return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %ecx, %r14d
movq %rdx, %r13
movq %rsi, %rbx
movq %rdi, %r15
movq %rsi, %rdi
callq 0xdaba
cmpl $0x1, %r14d
movq %r15, -0x70(%rbp)
xorps %xmm0, %xmm0
jne 0xd7f9
movups %xmm0, (%rbx)
xorl %r12d, %r12d
movq %r12, 0x10(%rbx)
movq %r12, 0x20(%rbx)
cmpq $0x1, %r13
movl $0x0, %eax
sbbq %rax, %rax
orq %r13, %rax
movq %rax, -0x40(%rbp)
movl $0x1, %edi
movl $0x30, %esi
callq 0x2250
movq %rax, %r14
movl $0x1, (%rax)
movl $0x8, %edi
callq 0x2310
movq %rax, -0x50(%rbp)
movq %rax, 0x8(%r14)
movl $0x8, %edi
callq 0x2310
movq %rax, -0x58(%rbp)
movq %rax, 0x10(%r14)
movl $0x8, %edi
callq 0x2310
movq %rax, -0x48(%rbp)
movq %rax, 0x18(%r14)
movl $0x4, %edi
callq 0x2310
movq %rax, %r13
movq %rax, 0x20(%r14)
movq %r14, -0x30(%rbp)
movq %rbx, 0x28(%r14)
xorl %ebx, %ebx
movq %r15, %rdi
callq 0x1c23d
testl %eax, %eax
js 0xd7bf
movl %eax, %r14d
movq -0x50(%rbp), %rax
movq %r12, (%rax)
incq %r12
movq -0x70(%rbp), %rax
movq 0x18(%rax), %r15
movq 0x8(%r15), %rax
movq 0x10(%rax), %rdi
callq 0x24b0
movq -0x58(%rbp), %rcx
movq %rax, (%rcx)
movq 0x8(%r15), %rax
movq -0x70(%rbp), %r15
movq 0x40(%rax), %rdi
callq 0x24b0
movq -0x48(%rbp), %rcx
movq %rax, (%rcx)
movl %r14d, (%r13)
movq -0x30(%rbp), %rdi
callq 0x11761
movl %r14d, %eax
addq %rax, %rbx
cmpq -0x40(%rbp), %rbx
jb 0xd736
movq 0x1884d(%rip), %rax     # 0x25ff0
movq (%rax), %rdi
leaq 0x1284b(%rip), %rsi     # 0x1fff8
leaq 0x12bfa(%rip), %rdx     # 0x203ae
movq -0x40(%rbp), %rcx
xorl %eax, %eax
callq 0x2280
movq -0x50(%rbp), %rdi
callq 0x2060
movq -0x58(%rbp), %rdi
callq 0x2060
movq -0x48(%rbp), %rdi
callq 0x2060
movq %r13, %rdi
callq 0x2060
movq -0x30(%rbp), %rdi
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2060
movups %xmm0, (%rbx)
xorl %eax, %eax
movq %rax, 0x10(%rbx)
movq %rbx, -0x68(%rbp)
movq %rax, 0x20(%rbx)
movq %r13, -0x30(%rbp)
cmpq $0x1, %r13
sbbq %rax, %rax
movq %rax, -0x40(%rbp)
movslq %r14d, %rdi
movl $0x30, %esi
movq %rdi, -0x50(%rbp)
callq 0x2250
movq %rax, -0x48(%rbp)
movl %r14d, %eax
movq %rax, -0x60(%rbp)
movl %r14d, -0x34(%rbp)
testl %r14d, %r14d
jle 0xd8e8
movq -0x60(%rbp), %rax
shlq $0x4, %rax
leaq (%rax,%rax,2), %rbx
xorl %r13d, %r13d
movq -0x48(%rbp), %r12
movl $0x0, (%r12,%r13)
movl $0x13880, %edi          # imm = 0x13880
callq 0x2310
movq %rax, 0x8(%r12,%r13)
movl $0x13880, %edi          # imm = 0x13880
callq 0x2310
movq %rax, 0x10(%r12,%r13)
movl $0x13880, %edi          # imm = 0x13880
callq 0x2310
movq %rax, 0x18(%r12,%r13)
movl $0x9c40, %edi           # imm = 0x9C40
callq 0x2310
movq %rax, 0x20(%r12,%r13)
movl $0x28, %edi
callq 0x2310
movq %rax, %r14
movq %rax, 0x28(%r12,%r13)
testq %rax, %rax
je 0xd8c5
xorl %ecx, %ecx
movq %rcx, (%r14)
movq -0x68(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x18(%r14)
movq %rcx, 0x20(%r14)
movq $0x4000, 0x8(%r14)      # imm = 0x4000
movl $0x160000, %edi         # imm = 0x160000
callq 0x2310
movq %rax, 0x10(%r14)
addq $0x30, %r13
cmpq %r13, %rbx
jne 0xd855
movq %rsp, -0x80(%rbp)
movq -0x30(%rbp), %rax
orq %rax, -0x40(%rbp)
movq %rsp, %rcx
movq -0x60(%rbp), %rax
leaq 0xf(,%rax,8), %rax
andq $-0x10, %rax
subq %rax, %rcx
movq %rcx, -0x78(%rbp)
movq %rcx, %rsp
imulq $0x2710, -0x50(%rbp), %rax # imm = 0x2710
movq %rax, -0x88(%rbp)
movq $0x0, -0x30(%rbp)
xorl %r14d, %r14d
xorl %ebx, %ebx
movq %r15, %rdi
callq 0x1c23d
testl %eax, %eax
js 0xda25
movl %eax, %r12d
movq %r14, %rax
movabsq $0x346dc5d63886594b, %rcx # imm = 0x346DC5D63886594B
mulq %rcx
shrq $0xb, %rdx
movslq %edx, %rax
movq %r14, -0x50(%rbp)
leaq (%rax,%rax,2), %r14
shlq $0x4, %r14
movq %r15, %r13
movq %rbx, -0x58(%rbp)
movq -0x48(%rbp), %rbx
movslq (%rbx,%r14), %r15
movq 0x8(%rbx,%r14), %rax
movq -0x30(%rbp), %rcx
movq %rcx, (%rax,%r15,8)
movq 0x18(%r13), %rax
movq 0x8(%rax), %rax
movq 0x10(%rax), %rdi
callq 0x24b0
movq 0x10(%rbx,%r14), %rcx
movq %rax, (%rcx,%r15,8)
movq 0x18(%r13), %rax
movq 0x8(%rax), %rax
movq 0x40(%rax), %rdi
callq 0x24b0
movq 0x18(%rbx,%r14), %rcx
movq %rax, (%rcx,%r15,8)
movq 0x20(%rbx,%r14), %rax
movl %r12d, (%rax,%r15,4)
incl (%rbx,%r14)
movq -0x50(%rbp), %r14
incq %r14
cmpq -0x88(%rbp), %r14
jne 0xd9e6
movq %rbx, %rdi
movq -0x78(%rbp), %rsi
movl -0x34(%rbp), %edx
movq -0x68(%rbp), %rcx
callq 0xdb1f
xorl %r14d, %r14d
movl %r12d, %eax
movq -0x58(%rbp), %rbx
addq %rax, %rbx
incq -0x30(%rbp)
cmpq -0x40(%rbp), %rbx
movq -0x70(%rbp), %r15
jb 0xd92d
movq 0x185e7(%rip), %rax     # 0x25ff0
movq (%rax), %rdi
leaq 0x125e5(%rip), %rsi     # 0x1fff8
leaq 0x12624(%rip), %rdx     # 0x2003e
movq -0x40(%rbp), %rcx
xorl %eax, %eax
callq 0x2280
movl -0x34(%rbp), %ebx
testq %r14, %r14
movq -0x68(%rbp), %rcx
movq -0x48(%rbp), %r15
je 0xda43
movq %r15, %rdi
movq -0x78(%rbp), %rsi
movl %ebx, %edx
callq 0xdb1f
testl %ebx, %ebx
jle 0xda9f
movq -0x60(%rbp), %rax
shlq $0x4, %rax
leaq (%rax,%rax,2), %rbx
xorl %r14d, %r14d
movq 0x8(%r15,%r14), %rdi
callq 0x2060
movq 0x10(%r15,%r14), %rdi
callq 0x2060
movq 0x18(%r15,%r14), %rdi
callq 0x2060
movq 0x20(%r15,%r14), %rdi
callq 0x2060
movq 0x28(%r15,%r14), %rax
movq 0x10(%rax), %rdi
callq 0x2060
movq 0x28(%r15,%r14), %rdi
callq 0x2060
addq $0x30, %r14
cmpq %r14, %rbx
jne 0xda56
movq %r15, %rdi
callq 0x2060
movq -0x80(%rbp), %rsp
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq