// File: readmapping[P]alfalfa/src/main.cpp
// Function: paired_thread1(mapOptions_t const*)
void paired_thread1(const mapOptions_t * opt) {
    long total_seq_cnt = 0;
    long seq_mapped1 = 0;
    long alignments_printed1 = 0;
    long seq_mapped2 = 0;
    long alignments_printed2 = 0;
#ifndef NDEBUG
    if (opt->alnOptions.debugFile != NULL)
        fprintf(opt->alnOptions.debugFile, "#ALN\n");
#endif
    //init fields
    vector<read_t> mates1;
    vector<read_t> mates2;
    int bpCount = opt->query_threads * BUFFER_SIZE;
    //read reads
    while (readBatchPaired(bpCount, mates1, mates2) > 0) {
        //count reads, init fields
        int seq_cnt = mates1.size();
        total_seq_cnt += seq_cnt;
        cerr << "Progress " << seq_cnt << " reads ..." << endl;
        clock_t start = clock();
        paired_data pairedData(opt, sa, &mates1, &mates2);
        //parallel loop
        kt_for(opt->query_threads, seq_cnt, map_paired, &pairedData);
        //output
        for(int i = 0; i < mates1.size(); i++){
            if (mates1[i].alignments.empty())
                fprintf(outfile, "%s", mates1[i].emptyAlingment(true, mates2[i].alignments.empty(), true).c_str());
            else{
                seq_mapped1++;
                int mate1AlnCount;
                if (opt->pairedOpt.mixed)
                    mate1AlnCount = min(mates1[i].alignmentCount(), opt->alnOptions.alignmentCount);
                else
                    mate1AlnCount = min(mates1[i].pairedAlignmentCount, opt->alnOptions.alignmentCount);
                alignments_printed1 += mate1AlnCount;
                for (int k = 0; k < mate1AlnCount; k++)
                    fprintf(outfile, "%s", mates1[i].printPairedAlignments(k, true).c_str());
            }
            if (mates2[i].alignments.empty())
                fprintf(outfile, "%s", mates2[i].emptyAlingment(true, mates1[i].alignments.empty(), false).c_str());
            else {
                seq_mapped2++;
                int mate2AlnCount;
                if (opt->pairedOpt.mixed)
                    mate2AlnCount = min(mates2[i].alignmentCount(), opt->alnOptions.alignmentCount);
                else
                    mate2AlnCount = min(mates2[i].pairedAlignmentCount, opt->alnOptions.alignmentCount);
                alignments_printed2 += mate2AlnCount;
                for (int k = 0; k < mate2AlnCount; k++)
                    fprintf(outfile, "%s", mates2[i].printPairedAlignments(k, false).c_str());
            }
        }
        mates1.clear(); mates2.clear();
        clock_t end = clock();
        double cpu_time = (double) (end - start) / CLOCKS_PER_SEC;
        cerr << "Progress " << seq_cnt << " reads: done in " << cpu_time << " seconds" << endl;
    }
    //clean up
    mates1.clear();
    mates2.clear();
    //report statistics
    printf("sequences read: %ld\n", total_seq_cnt);
    printf("sequences mapped (mate1): %ld\n", seq_mapped1);
    printf("sequences mapped (mate2): %ld\n", seq_mapped2);
    printf("alignments printed (mate1): %ld\n", alignments_printed1);
    printf("alignments printed (mate2): %ld\n", alignments_printed2);
}

// Assembly:
subq $0x208, %rsp            # imm = 0x208
movq %rdi, 0x200(%rsp)
movq $0x0, 0x1f8(%rsp)
movq $0x0, 0x1f0(%rsp)
movq $0x0, 0x1e8(%rsp)
movq $0x0, 0x1e0(%rsp)
movq $0x0, 0x1d8(%rsp)
leaq 0x1c0(%rsp), %rdi
callq 0xbdf0
leaq 0x1a8(%rsp), %rdi
callq 0xbdf0
movq 0x200(%rsp), %rax
imull $0x989680, 0x8(%rax), %eax # imm = 0x989680
movl %eax, 0x1a4(%rsp)
movl 0x1a4(%rsp), %edi
leaq 0x1c0(%rsp), %rsi
leaq 0x1a8(%rsp), %rdx
callq 0x9530
movl %eax, 0xac(%rsp)
jmp 0x9780
movl 0xac(%rsp), %eax
cmpl $0x0, %eax
jle 0x9eb0
leaq 0x1c0(%rsp), %rdi
callq 0xbdd0
movl %eax, 0x190(%rsp)
movslq 0x190(%rsp), %rcx
movq 0x1f8(%rsp), %rax
addq %rcx, %rax
movq %rax, 0x1f8(%rsp)
movq 0x8d82a(%rip), %rdi     # 0x96ff0
leaq 0x6f887(%rip), %rsi     # 0x79054
callq 0x8360
movq %rax, 0xa0(%rsp)
jmp 0x97dc
movq 0xa0(%rsp), %rdi
movl 0x190(%rsp), %esi
callq 0x8710
movq %rax, 0x98(%rsp)
jmp 0x97fa
movq 0x98(%rsp), %rdi
leaq 0x6f855(%rip), %rsi     # 0x7905e
callq 0x8360
movq %rax, 0x90(%rsp)
jmp 0x9818
movq 0x90(%rsp), %rdi
movq 0x8d789(%rip), %rsi     # 0x96fb0
callq 0x83b0
jmp 0x982e
callq 0x8230
movq %rax, 0x188(%rsp)
movq 0x200(%rsp), %rsi
movq 0x8dc8e(%rip), %rdx     # 0x974d8
leaq 0x168(%rsp), %rdi
leaq 0x1c0(%rsp), %rcx
leaq 0x1a8(%rsp), %r8
callq 0xc600
jmp 0x9869
movq 0x200(%rsp), %rax
movl 0x8(%rax), %edi
movl 0x190(%rsp), %esi
leaq 0x6fe(%rip), %rdx       # 0x9f80
leaq 0x168(%rsp), %rcx
callq 0x780a0
jmp 0x9891
movl $0x0, 0x164(%rsp)
movslq 0x164(%rsp), %rax
movq %rax, 0x88(%rsp)
leaq 0x1c0(%rsp), %rdi
callq 0xbdd0
movq %rax, %rcx
movq 0x88(%rsp), %rax
cmpq %rcx, %rax
jae 0x9dca
movslq 0x164(%rsp), %rsi
leaq 0x1c0(%rsp), %rdi
callq 0xbe40
movq %rax, %rdi
addq $0xb0, %rdi
callq 0xbe60
testb $0x1, %al
jne 0x98fa
jmp 0x99d2
movq 0x8dbdf(%rip), %rax     # 0x974e0
movq %rax, 0x78(%rsp)
movslq 0x164(%rsp), %rsi
leaq 0x1c0(%rsp), %rdi
callq 0xbe40
movq %rax, 0x80(%rsp)
movslq 0x164(%rsp), %rsi
leaq 0x1a8(%rsp), %rdi
callq 0xbe40
movq %rax, %rdi
addq $0xb0, %rdi
callq 0xbe60
movq 0x80(%rsp), %rsi
movzbl %al, %ecx
leaq 0x140(%rsp), %rdi
movl $0x1, %r8d
movl %r8d, %edx
callq 0xbeb0
jmp 0x996a
leaq 0x140(%rsp), %rdi
callq 0x8170
movq 0x78(%rsp), %rdi
movq %rax, %rdx
leaq 0x6f6e3(%rip), %rsi     # 0x79069
movb $0x0, %al
callq 0x85c0
leaq 0x140(%rsp), %rdi
callq 0x8858
jmp 0x9b5e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x198(%rsp)
movl %eax, 0x194(%rsp)
leaq 0x1a8(%rsp), %rdi
callq 0xc5a0
leaq 0x1c0(%rsp), %rdi
callq 0xc5a0
jmp 0x9f64
movq 0x1f0(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x1f0(%rsp)
movq 0x200(%rsp), %rax
testb $0x1, 0x1a0(%rax)
je 0x9a58
movslq 0x164(%rsp), %rsi
leaq 0x1c0(%rsp), %rdi
callq 0xbe40
movq %rax, %rdi
callq 0xc0c0
movl %eax, 0x74(%rsp)
jmp 0x9a1a
movl 0x74(%rsp), %eax
movl %eax, 0x138(%rsp)
movq 0x200(%rsp), %rsi
addq $0x150, %rsi            # imm = 0x150
leaq 0x138(%rsp), %rdi
callq 0xc080
movq %rax, 0x68(%rsp)
jmp 0x9a48
movq 0x68(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x13c(%rsp)
jmp 0x9aa0
movslq 0x164(%rsp), %rsi
leaq 0x1c0(%rsp), %rdi
callq 0xbe40
movq %rax, %rdi
addq $0xc8, %rdi
movq 0x200(%rsp), %rsi
addq $0x150, %rsi            # imm = 0x150
callq 0xc080
movq %rax, 0x60(%rsp)
jmp 0x9a92
movq 0x60(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x13c(%rsp)
movslq 0x13c(%rsp), %rax
addq 0x1e8(%rsp), %rax
movq %rax, 0x1e8(%rsp)
movl $0x0, 0x134(%rsp)
movl 0x134(%rsp), %eax
cmpl 0x13c(%rsp), %eax
jge 0x9b5c
movq 0x8da02(%rip), %rax     # 0x974e0
movq %rax, 0x58(%rsp)
movslq 0x164(%rsp), %rsi
leaq 0x1c0(%rsp), %rdi
callq 0xbe40
movq %rax, %rsi
movl 0x134(%rsp), %edx
leaq 0x110(%rsp), %rdi
movl $0x1, %ecx
callq 0xc650
jmp 0x9b16
leaq 0x110(%rsp), %rdi
callq 0x8170
movq 0x58(%rsp), %rdi
movq %rax, %rdx
leaq 0x6f537(%rip), %rsi     # 0x79069
movb $0x0, %al
callq 0x85c0
leaq 0x110(%rsp), %rdi
callq 0x8858
movl 0x134(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x134(%rsp)
jmp 0x9ac3
jmp 0x9b5e
movslq 0x164(%rsp), %rsi
leaq 0x1a8(%rsp), %rdi
callq 0xbe40
movq %rax, %rdi
addq $0xb0, %rdi
callq 0xbe60
testb $0x1, %al
jne 0x9b8b
jmp 0x9c29
movq 0x8d94e(%rip), %rax     # 0x974e0
movq %rax, 0x48(%rsp)
movslq 0x164(%rsp), %rsi
leaq 0x1a8(%rsp), %rdi
callq 0xbe40
movq %rax, 0x50(%rsp)
movslq 0x164(%rsp), %rsi
leaq 0x1c0(%rsp), %rdi
callq 0xbe40
movq %rax, %rdi
addq $0xb0, %rdi
callq 0xbe60
movq 0x50(%rsp), %rsi
movzbl %al, %ecx
leaq 0xf0(%rsp), %rdi
movl $0x1, %edx
xorl %r8d, %r8d
callq 0xbeb0
jmp 0x9bf4
leaq 0xf0(%rsp), %rdi
callq 0x8170
movq 0x48(%rsp), %rdi
movq %rax, %rdx
leaq 0x6f459(%rip), %rsi     # 0x79069
movb $0x0, %al
callq 0x85c0
leaq 0xf0(%rsp), %rdi
callq 0x8858
jmp 0x9db2
movq 0x1e0(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x1e0(%rsp)
movq 0x200(%rsp), %rax
testb $0x1, 0x1a0(%rax)
je 0x9caf
movslq 0x164(%rsp), %rsi
leaq 0x1a8(%rsp), %rdi
callq 0xbe40
movq %rax, %rdi
callq 0xc0c0
movl %eax, 0x44(%rsp)
jmp 0x9c71
movl 0x44(%rsp), %eax
movl %eax, 0xe8(%rsp)
movq 0x200(%rsp), %rsi
addq $0x150, %rsi            # imm = 0x150
leaq 0xe8(%rsp), %rdi
callq 0xc080
movq %rax, 0x38(%rsp)
jmp 0x9c9f
movq 0x38(%rsp), %rax
movl (%rax), %eax
movl %eax, 0xec(%rsp)
jmp 0x9cf7
movslq 0x164(%rsp), %rsi
leaq 0x1a8(%rsp), %rdi
callq 0xbe40
movq %rax, %rdi
addq $0xc8, %rdi
movq 0x200(%rsp), %rsi
addq $0x150, %rsi            # imm = 0x150
callq 0xc080
movq %rax, 0x30(%rsp)
jmp 0x9ce9
movq 0x30(%rsp), %rax
movl (%rax), %eax
movl %eax, 0xec(%rsp)
movslq 0xec(%rsp), %rax
addq 0x1d8(%rsp), %rax
movq %rax, 0x1d8(%rsp)
movl $0x0, 0xe4(%rsp)
movl 0xe4(%rsp), %eax
cmpl 0xec(%rsp), %eax
jge 0x9db0
movq 0x8d7ab(%rip), %rax     # 0x974e0
movq %rax, 0x28(%rsp)
movslq 0x164(%rsp), %rsi
leaq 0x1a8(%rsp), %rdi
callq 0xbe40
movq %rax, %rsi
movl 0xe4(%rsp), %edx
leaq 0xc0(%rsp), %rdi
xorl %ecx, %ecx
callq 0xc650
jmp 0x9d6a
leaq 0xc0(%rsp), %rdi
callq 0x8170
movq 0x28(%rsp), %rdi
movq %rax, %rdx
leaq 0x6f2e3(%rip), %rsi     # 0x79069
movb $0x0, %al
callq 0x85c0
leaq 0xc0(%rsp), %rdi
callq 0x8858
movl 0xe4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xe4(%rsp)
jmp 0x9d1a
jmp 0x9db2
jmp 0x9db4
movl 0x164(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x164(%rsp)
jmp 0x989c
leaq 0x1c0(%rsp), %rdi
callq 0xc580
leaq 0x1a8(%rsp), %rdi
callq 0xc580
callq 0x8230
movq %rax, 0xb8(%rsp)
movq 0xb8(%rsp), %rax
movq 0x188(%rsp), %rcx
subq %rcx, %rax
cvtsi2sd %rax, %xmm0
movsd 0x6f1f7(%rip), %xmm1    # 0x79008
divsd %xmm1, %xmm0
movsd %xmm0, 0xb0(%rsp)
movq 0x8d1cb(%rip), %rdi     # 0x96ff0
leaq 0x6f228(%rip), %rsi     # 0x79054
callq 0x8360
movq %rax, 0x20(%rsp)
jmp 0x9e38
movq 0x20(%rsp), %rdi
movl 0x190(%rsp), %esi
callq 0x8710
movq %rax, 0x18(%rsp)
jmp 0x9e50
movq 0x18(%rsp), %rdi
leaq 0x6f210(%rip), %rsi     # 0x7906c
callq 0x8360
movq %rax, 0x10(%rsp)
jmp 0x9e68
movq 0x10(%rsp), %rdi
movsd 0xb0(%rsp), %xmm0
callq 0x87e0
movq %rax, 0x8(%rsp)
jmp 0x9e82
movq 0x8(%rsp), %rdi
leaq 0x6f1ef(%rip), %rsi     # 0x7907d
callq 0x8360
movq %rax, (%rsp)
jmp 0x9e99
movq (%rsp), %rdi
movq 0x8d10c(%rip), %rsi     # 0x96fb0
callq 0x83b0
jmp 0x9eab
jmp 0x975b
leaq 0x1c0(%rsp), %rdi
callq 0xc580
leaq 0x1a8(%rsp), %rdi
callq 0xc580
movq 0x1f8(%rsp), %rsi
leaq 0x6f1ad(%rip), %rdi     # 0x79086
xorl %eax, %eax
callq 0x8070
jmp 0x9ee2
movq 0x1f0(%rsp), %rsi
leaq 0x6f1da(%rip), %rdi     # 0x790cb
xorl %eax, %eax
callq 0x8070
jmp 0x9efa
movq 0x1e0(%rsp), %rsi
leaq 0x6f1e1(%rip), %rdi     # 0x790ea
xorl %eax, %eax
callq 0x8070
jmp 0x9f12
movq 0x1e8(%rsp), %rsi
leaq 0x6f1e8(%rip), %rdi     # 0x79109
xorl %eax, %eax
callq 0x8070
jmp 0x9f2a
movq 0x1d8(%rsp), %rsi
leaq 0x6f1f1(%rip), %rdi     # 0x7912a
xorl %eax, %eax
callq 0x8070
jmp 0x9f42
leaq 0x1a8(%rsp), %rdi
callq 0xc5a0
leaq 0x1c0(%rsp), %rdi
callq 0xc5a0
addq $0x208, %rsp            # imm = 0x208
retq
movq 0x198(%rsp), %rdi
callq 0x8730
nopw %cs:(%rax,%rax)