// File: /workspace/github_cpp_makefile_star2_O3/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 0x411f
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 0x411a
movq 0x8(%rsp), %rsi
cmpb $0x40, (%rsi)
jne 0x409a
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 0x4022
movl $0xf0, %edi
callq 0x3230
movq %rax, %rbp
movq %rax, %rdi
movq %r13, %rsi
callq 0x4a06
movl 0x20(%rbp), %eax
testb $0x1, %al
je 0x40bf
notl %eax
testb $0xc, %al
jne 0x40c4
incl (%rsp)
jmp 0x40fd
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x4f13
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 0x50fe
movl $0xf0, %esi
movq %rbp, %rdi
callq 0x3240
jmp 0x4022
leaq 0x18(%rsp), %r13
leaq 0x520b(%rip), %rax      # 0x9331
cmpb $0x1, (%rax)
jne 0x42e5
movq 0x4eba(%rip), %r15      # 0x8ff0
leaq 0x2309(%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 0x4e88(%rip), %rdi      # 0x8ff0
callq 0x3030
movq %rax, %rdi
callq 0x3170
movq 0x4e74(%rip), %rdi      # 0x8ff0
leaq 0x22da(%rip), %rsi      # 0x645d
movl $0xd, %edx
callq 0x3280
movq 0x4e5c(%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 0x4e23(%rip), %rdi      # 0x8ff0
leaq 0x2297(%rip), %rsi      # 0x646b
movl $0x11, %edx
callq 0x3280
movq 0x4e0b(%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 0x4dd2(%rip), %rdi      # 0x8ff0
leaq 0x2258(%rip), %rsi      # 0x647d
movl $0xe, %edx
callq 0x3280
movq 0x4dba(%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 0x21ac(%rip), %xmm1     # 0x6430
subsd %xmm0, %xmm1
mulsd 0x21a8(%rip), %xmm1     # 0x6438
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movq 0x4d4e(%rip), %rdi      # 0x8ff0
callq 0x3350
movq %rax, %r14
leaq 0x21db(%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 0x4304
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 0x432e
jmp 0x432b
jmp 0x432b
jmp 0x432b
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x434a
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3240
movq %rbx, %rdi
callq 0x33c0