// File: /workspace/github_c_makefile_star2_O2/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, %r13
movq %rsi, %rbx
movq %rdi, %r12
movq %rsi, %rdi
callq 0xa715
cmpl $0x1, %r14d
movq %r12, -0x60(%rbp)
xorps %xmm0, %xmm0
jne 0xa486
andq $0x0, 0x10(%rbx)
movups %xmm0, (%rbx)
andq $0x0, 0x20(%rbx)
xorl %r14d, %r14d
cmpq $0x1, %r13
movl $0x0, %eax
sbbq %rax, %rax
orq %r13, %rax
movq %rax, -0x38(%rbp)
pushq $0x1
popq %rdi
pushq $0x30
popq %rsi
callq 0x2250
movq %rax, %r13
movl $0x1, (%rax)
pushq $0x8
popq %r15
movq %r15, %rdi
callq 0x2310
movq %rax, -0x48(%rbp)
movq %rax, 0x8(%r13)
movq %r15, %rdi
callq 0x2310
movq %rax, -0x40(%rbp)
movq %rax, 0x10(%r13)
movq %r15, %rdi
callq 0x2310
movq %rax, -0x58(%rbp)
movq %rax, 0x18(%r13)
pushq $0x4
popq %rdi
callq 0x2310
movq %rax, %r15
movq %rax, 0x20(%r13)
movq %r13, -0x50(%rbp)
movq %rbx, 0x28(%r13)
xorl %ebx, %ebx
movq %r12, %rdi
callq 0x166d7
testl %eax, %eax
js 0xa44c
movl %eax, %r13d
movq -0x48(%rbp), %rax
movq %r14, (%rax)
incq %r14
movq -0x60(%rbp), %rax
movq 0x18(%rax), %r12
movq 0x8(%r12), %rax
movq 0x10(%rax), %rdi
callq 0x24b0
movq -0x40(%rbp), %rcx
movq %rax, (%rcx)
movq 0x8(%r12), %rax
movq -0x60(%rbp), %r12
movq 0x40(%rax), %rdi
callq 0x24b0
movq -0x58(%rbp), %rcx
movq %rax, (%rcx)
movl %r13d, (%r15)
movq -0x50(%rbp), %rdi
callq 0xda96
movl %r13d, %eax
addq %rax, %rbx
cmpq -0x38(%rbp), %rbx
jb 0xa3c2
movq 0x16bc0(%rip), %rax     # 0x20ff0
movq (%rax), %rdi
leaq 0xfb76(%rip), %rsi      # 0x19fb0
leaq 0xff25(%rip), %rdx      # 0x1a366
movq -0x38(%rbp), %rcx
xorl %eax, %eax
callq 0x2280
movq -0x48(%rbp), %rdi
callq 0x2060
movq -0x40(%rbp), %rdi
callq 0x2060
movq -0x58(%rbp), %rdi
callq 0x2060
movq %r15, %rdi
callq 0x2060
movq -0x50(%rbp), %rdi
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2060
movups %xmm0, (%rbx)
andq $0x0, 0x10(%rbx)
movq %rbx, -0x38(%rbp)
andq $0x0, 0x20(%rbx)
movslq %r14d, %rdi
pushq $0x30
popq %rsi
movq %rdi, -0x40(%rbp)
callq 0x2250
movq %rax, %r15
xorl %ebx, %ebx
testl %r14d, %r14d
movl $0x0, %eax
movl %r14d, -0x2c(%rbp)
cmovgl %r14d, %eax
imulq $0x30, %rax, %rax
movq %rax, -0x50(%rbp)
pushq $0x28
popq %r14
cmpq %rbx, -0x50(%rbp)
je 0xa564
andl $0x0, (%r15,%rbx)
movl $0x13880, %edi          # imm = 0x13880
callq 0x2310
movq %rax, 0x8(%r15,%rbx)
movl $0x13880, %edi          # imm = 0x13880
callq 0x2310
movq %rax, 0x10(%r15,%rbx)
movl $0x13880, %edi          # imm = 0x13880
callq 0x2310
movq %rax, 0x18(%r15,%rbx)
movl $0x9c40, %edi           # imm = 0x9C40
callq 0x2310
movq %rax, 0x20(%r15,%rbx)
movq %r14, %rdi
callq 0x2310
movq %rax, %r12
movq %rax, 0x28(%r15,%rbx)
testq %rax, %rax
je 0xa53f
andq $0x0, (%r12)
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x18(%r12)
andq $0x0, 0x20(%r12)
movq $0x4000, 0x8(%r12)      # imm = 0x4000
movl $0x160000, %edi         # imm = 0x160000
callq 0x2310
movq %rax, 0x10(%r12)
addq $0x30, %rbx
movq -0x60(%rbp), %r12
jmp 0xa4c7
movq %rsp, -0x78(%rbp)
movq $0x0, -0x48(%rbp)
cmpq $0x1, %r13
movl $0x0, %eax
sbbq %rax, %rax
orq %r13, %rax
movq %rax, -0x70(%rbp)
movl -0x2c(%rbp), %eax
movq %rsp, %rcx
leaq 0xf(,%rax,8), %rax
andq $-0x10, %rax
subq %rax, %rcx
movq %rcx, -0x68(%rbp)
movq %rcx, %rsp
imulq $0x2710, -0x40(%rbp), %rax # imm = 0x2710
movq %rax, -0x80(%rbp)
xorl %ebx, %ebx
xorl %r13d, %r13d
movq %r12, %rdi
callq 0x166d7
testl %eax, %eax
js 0xa694
movl %eax, %r14d
movq %rbx, %rax
xorl %edx, %edx
movl $0x2710, %ecx           # imm = 0x2710
divq %rcx
cltq
movq %r13, -0x58(%rbp)
imulq $0x30, %rax, %r13
movq %rbx, -0x40(%rbp)
movq %r12, %rbx
movslq (%r15,%r13), %r12
movq 0x8(%r15,%r13), %rax
movq -0x48(%rbp), %rcx
movq %rcx, (%rax,%r12,8)
movq 0x18(%rbx), %rax
movq 0x8(%rax), %rax
movq 0x10(%rax), %rdi
callq 0x24b0
movq 0x10(%r15,%r13), %rcx
movq %rax, (%rcx,%r12,8)
movq 0x18(%rbx), %rax
movq -0x40(%rbp), %rbx
movq 0x8(%rax), %rax
movq 0x40(%rax), %rdi
callq 0x24b0
movq 0x18(%r15,%r13), %rcx
movq %rax, (%rcx,%r12,8)
movq 0x20(%r15,%r13), %rax
movl %r14d, (%rax,%r12,4)
incl (%r15,%r13)
incq %rbx
cmpq -0x80(%rbp), %rbx
jne 0xa655
movq %r15, %rdi
movq -0x68(%rbp), %rsi
movl -0x2c(%rbp), %edx
movq -0x38(%rbp), %rcx
callq 0xa772
xorl %ebx, %ebx
movl %r14d, %eax
movq -0x58(%rbp), %r13
addq %rax, %r13
incq -0x48(%rbp)
cmpq -0x70(%rbp), %r13
movq -0x60(%rbp), %r12
jb 0xa5b0
movq 0x16978(%rip), %rax     # 0x20ff0
movq (%rax), %rdi
leaq 0xf92e(%rip), %rsi      # 0x19fb0
leaq 0xf96d(%rip), %rdx      # 0x19ff6
movq -0x70(%rbp), %rcx
xorl %eax, %eax
callq 0x2280
testq %rbx, %rbx
movl -0x2c(%rbp), %edx
je 0xa6ac
movq %r15, %rdi
movq -0x68(%rbp), %rsi
movq -0x38(%rbp), %rcx
callq 0xa772
xorl %ebx, %ebx
cmpq %rbx, -0x50(%rbp)
je 0xa6fa
movq 0x8(%r15,%rbx), %rdi
callq 0x2060
movq 0x10(%r15,%rbx), %rdi
callq 0x2060
movq 0x18(%r15,%rbx), %rdi
callq 0x2060
movq 0x20(%r15,%rbx), %rdi
callq 0x2060
movq 0x28(%r15,%rbx), %rax
movq 0x10(%rax), %rdi
callq 0x2060
movq 0x28(%r15,%rbx), %rdi
callq 0x2060
addq $0x30, %rbx
jmp 0xa6ae
movq %r15, %rdi
callq 0x2060
movq -0x78(%rbp), %rsp
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq