// File: /workspace/github_cpp_makefile_star2_O1/bcthomas[P]shrinksam/src/process_stream.cpp
// Function: process_shrunk(std::basic_ifstream<char, std::char_traits<char>>&, std::basic_ofstream<char, std::char_traits<char>>&)
void process_shrunk(std::ifstream &in, std::ofstream &shr_out) {
	string line;

	int total_reads = 0;
	int output_reads = 0;
	int discarded_reads = 0;
	if (in.is_open()) {
		while(getline(in,line)) {
			if (line[0] == '@') {           // header so just write to output
				shr_out << line << endl;
			} else {
				++total_reads;
				Sam *s = new Sam(line);
				if (s->get_flag() & BAM_FPAIRED) {
					if ((s->get_flag() & BAM_FUNMAP) && (s->get_flag() & BAM_FMUNMAP)) {
						// both mates of the pair are unmapped
						++discarded_reads;
					} else {
						shr_out << *s << endl;
						++output_reads;
					}
				} else {
					++discarded_reads;
				}
				delete s;
			}
		} // end of while() loop
	}
	
	if (Shrinksam::verbose_flag) {
		float percent = (1.0 - ((float) output_reads / (float) total_reads)) * 100;
		cerr << "--- Shrink summary ---" << endl;
		cerr << "Total Reads: " << total_reads << endl;
		cerr << "Discarded Reads: " << discarded_reads << endl;
		cerr << "Output Reads: " << output_reads << endl;
		cerr << percent << "% shrunk" << endl;
	}

   // close files
    shr_out.close();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %rbx
movq %rdi, %r12
leaq 0x18(%rsp), %r13
movq %r13, -0x10(%r13)
movq $0x0, -0x8(%r13)
movb $0x0, (%r13)
addq $0x78, %rdi
callq 0x3070
movl $0x0, (%rsp)
movl $0x0, 0x4(%rsp)
movl $0x0, %r14d
testb %al, %al
je 0x4161
movl $0x0, (%rsp)
leaq 0x8(%rsp), %r13
movl $0x0, 0x4(%rsp)
xorl %r14d, %r14d
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3200
movsbl %al, %edx
movq %r12, %rdi
movq %r13, %rsi
callq 0x33f0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x415c
movq 0x8(%rsp), %rsi
cmpb $0x40, (%rsi)
jne 0x40dc
movq 0x10(%rsp), %rdx
movq %rbx, %rdi
callq 0x3280
movq %rax, %rbp
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x3200
movsbl %al, %esi
movq %rbp, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3170
jmp 0x4064
movl $0xf0, %edi
callq 0x3230
movq %rax, %rbp
movq %rax, %rdi
movq %r13, %rsi
callq 0x4a9e
movl 0x20(%rbp), %eax
testb $0x1, %al
je 0x4101
notl %eax
testb $0xc, %al
jne 0x4106
incl (%rsp)
jmp 0x413f
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x4fab
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3200
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3170
incl 0x4(%rsp)
incl %r14d
movq %rbp, %rdi
callq 0x5196
movl $0xf0, %esi
movq %rbp, %rdi
callq 0x3240
jmp 0x4064
leaq 0x18(%rsp), %r13
leaq 0x51c9(%rip), %rax      # 0x9331
cmpb $0x1, (%rax)
jne 0x4327
movq 0x4e78(%rip), %r15      # 0x8ff0
leaq 0x22c7(%rip), %rsi      # 0x6446
movl $0x16, %edx
movq %r15, %rdi
callq 0x3280
movq (%r15), %rax
addq -0x18(%rax), %r15
movq %r15, %rdi
movl $0xa, %esi
callq 0x3200
movsbl %al, %esi
movq 0x4e46(%rip), %rdi      # 0x8ff0
callq 0x3030
movq %rax, %rdi
callq 0x3170
movq 0x4e32(%rip), %rdi      # 0x8ff0
leaq 0x2298(%rip), %rsi      # 0x645d
movl $0xd, %edx
callq 0x3280
movq 0x4e1a(%rip), %rdi      # 0x8ff0
movl %r14d, %esi
callq 0x33a0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3200
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3170
movq 0x4de1(%rip), %rdi      # 0x8ff0
leaq 0x2255(%rip), %rsi      # 0x646b
movl $0x11, %edx
callq 0x3280
movq 0x4dc9(%rip), %rdi      # 0x8ff0
movl (%rsp), %esi
callq 0x33a0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3200
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3170
movq 0x4d90(%rip), %rdi      # 0x8ff0
leaq 0x2216(%rip), %rsi      # 0x647d
movl $0xe, %edx
callq 0x3280
movq 0x4d78(%rip), %rdi      # 0x8ff0
movl 0x4(%rsp), %esi
callq 0x33a0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3200
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3170
cvtsi2ssl 0x4(%rsp), %xmm0
cvtsi2ss %r14d, %xmm1
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x216a(%rip), %xmm1     # 0x6430
subsd %xmm0, %xmm1
mulsd 0x2166(%rip), %xmm1     # 0x6438
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movq 0x4d0c(%rip), %rdi      # 0x8ff0
callq 0x3350
movq %rax, %r14
leaq 0x2199(%rip), %rsi      # 0x648c
movl $0x8, %edx
movq %rax, %rdi
callq 0x3280
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3200
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3170
movq %rbx, %rdi
callq 0x32e0
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x4346
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3240
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movl $0xf0, %esi
movq %rbp, %rdi
callq 0x3240
jmp 0x4370
jmp 0x436d
jmp 0x436d
jmp 0x436d
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x438c
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3240
movq %rbx, %rdi
callq 0x33c0