// File: /workspace/github_c_makefile_star2_O1/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 $0x58, %rsp
movl %ecx, %r14d
movq %rdx, %r12
movq %rsi, %rbx
movq %rdi, %r15
movq %rsi, %rdi
callq 0xd274
cmpl $0x1, %r14d
movq %r15, -0x70(%rbp)
jne 0xcfa1
testq %rbx, %rbx
je 0xce5f
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
xorl %eax, %eax
movq %rax, 0x10(%rbx)
movq %rax, 0x20(%rbx)
xorl %r13d, %r13d
cmpq $0x1, %r12
movl $0x0, %eax
sbbq %rax, %rax
orq %r12, %rax
movq %rax, -0x50(%rbp)
movl $0x1, %edi
movl $0x30, %esi
callq 0x2250
movq %rax, %r14
movl $0x1, (%rax)
movl $0x8, %edi
callq 0x2320
movq %rax, -0x48(%rbp)
movq %rax, 0x8(%r14)
movl $0x8, %edi
callq 0x2320
movq %rax, -0x58(%rbp)
movq %rax, 0x10(%r14)
movl $0x8, %edi
callq 0x2320
movq %rax, -0x40(%rbp)
movq %rax, 0x18(%r14)
movl $0x4, %edi
callq 0x2320
movq %rax, %r12
movq %rax, 0x20(%r14)
movq %r14, -0x30(%rbp)
movq %rbx, 0x28(%r14)
xorl %ebx, %ebx
movq %r15, %rdi
callq 0x1a2b4
testl %eax, %eax
js 0xcf67
movl %eax, %r14d
movq -0x48(%rbp), %rax
movq %r13, (%rax)
incq %r13
movq -0x70(%rbp), %rax
movq 0x18(%rax), %r15
movq 0x8(%r15), %rax
movq 0x10(%rax), %rdi
callq 0x24c0
movq -0x58(%rbp), %rcx
movq %rax, (%rcx)
movq 0x8(%r15), %rax
movq -0x70(%rbp), %r15
movq 0x40(%rax), %rdi
callq 0x24c0
movq -0x40(%rbp), %rcx
movq %rax, (%rcx)
movl %r14d, (%r12)
movq -0x30(%rbp), %rdi
callq 0x10d41
movl %r14d, %eax
addq %rax, %rbx
cmpq -0x50(%rbp), %rbx
jb 0xcede
movq 0x170a5(%rip), %rax     # 0x23ff0
movq (%rax), %rdi
leaq 0x11013(%rip), %rsi     # 0x1df68
leaq 0x113c2(%rip), %rdx     # 0x1e31e
movq -0x50(%rbp), %rcx
xorl %eax, %eax
callq 0x2290
movq -0x48(%rbp), %rdi
callq 0x2060
movq -0x58(%rbp), %rdi
callq 0x2060
movq -0x40(%rbp), %rdi
callq 0x2060
movq %r12, %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
testq %rbx, %rbx
je 0xcfb6
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
xorl %eax, %eax
movq %rax, 0x10(%rbx)
movq %rax, 0x20(%rbx)
movq %rbx, -0x68(%rbp)
xorl %eax, %eax
movq %r12, -0x30(%rbp)
cmpq $0x1, %r12
sbbq %rax, %rax
movq %rax, -0x40(%rbp)
movslq %r14d, %rdi
movl $0x30, %esi
movq %rdi, -0x48(%rbp)
callq 0x2250
movq %rax, %r13
movl %r14d, %eax
movq %rax, -0x60(%rbp)
movl %r14d, -0x34(%rbp)
testl %r14d, %r14d
jle 0xd0ae
movq -0x60(%rbp), %rax
shlq $0x4, %rax
leaq (%rax,%rax,2), %rbx
xorl %r14d, %r14d
xorl %r12d, %r12d
movl $0x0, (%r13,%r12)
movl $0x13880, %edi          # imm = 0x13880
callq 0x2320
movq %rax, 0x8(%r13,%r12)
movl $0x13880, %edi          # imm = 0x13880
callq 0x2320
movq %rax, 0x10(%r13,%r12)
movl $0x13880, %edi          # imm = 0x13880
callq 0x2320
movq %rax, 0x18(%r13,%r12)
movl $0x9c40, %edi           # imm = 0x9C40
callq 0x2320
movq %rax, 0x20(%r13,%r12)
movl $0x28, %edi
callq 0x2320
movq %rax, 0x28(%r13,%r12)
testq %rax, %rax
je 0xd078
movq -0x68(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq %r14, 0x10(%rax)
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq %rcx, 0x18(%rax)
movq %r14, 0x20(%rax)
cmpq $0x270f, 0x8(%rax)      # imm = 0x270F
ja 0xd0a1
movq $0x4000, 0x8(%rax)      # imm = 0x4000
movq 0x10(%rax), %rdi
movl $0x160000, %esi         # imm = 0x160000
callq 0x2360
movq 0x28(%r13,%r12), %rcx
movq %rax, 0x10(%rcx)
addq $0x30, %r12
cmpq %r12, %rbx
jne 0xd005
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, -0x48(%rbp), %rax # imm = 0x2710
movq %rax, -0x50(%rbp)
movq $0x0, -0x30(%rbp)
xorl %r14d, %r14d
xorl %ebx, %ebx
movq %r15, %rdi
callq 0x1a2b4
testl %eax, %eax
js 0xd1e3
movl %eax, %r12d
movq %r14, %rax
movabsq $0x346dc5d63886594b, %rcx # imm = 0x346DC5D63886594B
mulq %rcx
shrq $0xb, %rdx
movslq %edx, %rax
movq %r14, -0x48(%rbp)
leaq (%rax,%rax,2), %r14
shlq $0x4, %r14
movq %rbx, -0x58(%rbp)
movq %r15, %rbx
movslq (%r13,%r14), %r15
movq 0x8(%r13,%r14), %rax
movq -0x30(%rbp), %rcx
movq %rcx, (%rax,%r15,8)
movq 0x18(%rbx), %rax
movq 0x8(%rax), %rax
movq 0x10(%rax), %rdi
callq 0x24c0
movq 0x10(%r13,%r14), %rcx
movq %rax, (%rcx,%r15,8)
movq 0x18(%rbx), %rax
movq 0x8(%rax), %rax
movq 0x40(%rax), %rdi
callq 0x24c0
movq 0x18(%r13,%r14), %rcx
movq %rax, (%rcx,%r15,8)
movq 0x20(%r13,%r14), %rax
movl %r12d, (%rax,%r15,4)
incl (%r13,%r14)
movq -0x48(%rbp), %r14
incq %r14
cmpq -0x50(%rbp), %r14
jne 0xd1a4
movq %r13, %rdi
movq -0x78(%rbp), %rsi
movl -0x34(%rbp), %edx
movq -0x68(%rbp), %rcx
callq 0xd2d9
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 0xd0f0
movq 0x16e29(%rip), %rax     # 0x23ff0
movq (%rax), %rdi
leaq 0x10d97(%rip), %rsi     # 0x1df68
leaq 0x10dd6(%rip), %rdx     # 0x1dfae
movq -0x40(%rbp), %rcx
xorl %eax, %eax
callq 0x2290
movl -0x34(%rbp), %ebx
testq %r14, %r14
movq -0x68(%rbp), %rcx
je 0xd1fd
movq %r13, %rdi
movq -0x78(%rbp), %rsi
movl %ebx, %edx
callq 0xd2d9
testl %ebx, %ebx
jle 0xd259
movq -0x60(%rbp), %rax
shlq $0x4, %rax
leaq (%rax,%rax,2), %rbx
xorl %r14d, %r14d
movq 0x8(%r13,%r14), %rdi
callq 0x2060
movq 0x10(%r13,%r14), %rdi
callq 0x2060
movq 0x18(%r13,%r14), %rdi
callq 0x2060
movq 0x20(%r13,%r14), %rdi
callq 0x2060
movq 0x28(%r13,%r14), %rax
movq 0x10(%rax), %rdi
callq 0x2060
movq 0x28(%r13,%r14), %rdi
callq 0x2060
addq $0x30, %r14
cmpq %r14, %rbx
jne 0xd210
movq %r13, %rdi
callq 0x2060
movq -0x80(%rbp), %rsp
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq