// File: CK7[P]abawaca/src/ReadMappingReader.cpp
// Function: Bio::SAMReader::next_mapping()
ReadMapping* SAMReader::next_mapping()
{
	// The following loop should have an effect just once - at the beginning. Otherwise it should result with an entry 
	// every time it reads a line 
	static char* 	next_line = (char*)calloc(1024, sizeof(char));
	static size_t	next_line_size = 1024;
	next_line[0] = 0;
	do {
		// We do the following because we don't know whether the size of next_line is sufficient for storing the next line. 
		// If not we will increase the size of next_line until we have enough space. Eventually next_line will be able to 
		// store the longest line in the file.
		char 	*p = next_line;
		size_t	s = next_line_size;
		while(fgets(p, s, m_fp)) {
			if((*(p+strlen(p)-1) == '\n') || !this->good())
				break;
			if(strlen(p) != s-1) {
				// This is weird!
			}
			// Else - we did not read the whole line, need to increase next_line's size and continue reading
			next_line_size *= 2;
			next_line = (char*)realloc(next_line, next_line_size);
			p = next_line+strlen(next_line); 
			s = next_line_size - strlen(next_line);
		}
		if(next_line[0] == '@')
			m_total_to_read -= strlen(next_line);		
	} while(this->good() && ((next_line[0] == 0) || (next_line[0] == '@')));
	if(next_line[0] == 0) {
		return NULL;
	}
//		return new ReadMapping(SAMReader::_end);
	m_total_read += strlen(next_line);
	chomp(next_line);

	return new ReadMapping(next_line);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpb $0x0, 0x29855(%rip)     # 0x323a0
jne 0x8b80
leaq 0x2984c(%rip), %rdi     # 0x323a0
callq 0x45e0
cmpl $0x0, %eax
je 0x8b80
movl $0x400, %edi            # imm = 0x400
movl $0x1, %esi
callq 0x41f0
movq %rax, 0x29824(%rip)     # 0x32398
leaq 0x29825(%rip), %rdi     # 0x323a0
callq 0x41e0
movq 0x29811(%rip), %rax     # 0x32398
movb $0x0, (%rax)
movq 0x29807(%rip), %rax     # 0x32398
movq %rax, -0x18(%rbp)
movq 0x297c4(%rip), %rax     # 0x32360
movq %rax, -0x20(%rbp)
movq -0x38(%rbp), %rax
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rcx
movl %ecx, %esi
movq 0x8(%rax), %rdx
callq 0x4540
cmpq $0x0, %rax
je 0x8c88
movq -0x18(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rdi
callq 0x4150
movq %rax, %rcx
movq -0x40(%rbp), %rax
movsbl -0x1(%rax,%rcx), %eax
cmpl $0xa, %eax
je 0x8bf1
movq -0x38(%rbp), %rdi
movq (%rdi), %rax
callq *0x20(%rax)
testb $0x1, %al
jne 0x8bf6
jmp 0x8c88
movq -0x18(%rbp), %rdi
callq 0x4150
movq -0x20(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
je 0x8c0e
jmp 0x8c0e
movq 0x2974b(%rip), %rax     # 0x32360
shlq %rax
movq %rax, 0x29741(%rip)     # 0x32360
movq 0x29772(%rip), %rdi     # 0x32398
movq 0x29733(%rip), %rsi     # 0x32360
callq 0x4580
movq %rax, 0x2975f(%rip)     # 0x32398
movq 0x29758(%rip), %rax     # 0x32398
movq %rax, -0x50(%rbp)
movq 0x2974d(%rip), %rdi     # 0x32398
callq 0x4150
movq %rax, %rcx
movq -0x50(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x18(%rbp)
movq 0x296fb(%rip), %rax     # 0x32360
movq %rax, -0x48(%rbp)
movq 0x29728(%rip), %rdi     # 0x32398
callq 0x4150
movq %rax, %rcx
movq -0x48(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x20(%rbp)
jmp 0x8ba0
movq 0x29709(%rip), %rax     # 0x32398
movsbl (%rax), %eax
cmpl $0x40, %eax
jne 0x8cb5
movq 0x296fa(%rip), %rdi     # 0x32398
callq 0x4150
movq %rax, %rdx
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rcx
subq %rdx, %rcx
movq %rcx, 0x30(%rax)
jmp 0x8cb7
movq -0x38(%rbp), %rdi
movq (%rdi), %rax
callq *0x20(%rax)
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x51(%rbp)
jne 0x8ccf
jmp 0x8cfc
movq 0x296c2(%rip), %rax     # 0x32398
movsbl (%rax), %ecx
movb $0x1, %al
cmpl $0x0, %ecx
movb %al, -0x52(%rbp)
je 0x8cf6
movq 0x296ae(%rip), %rax     # 0x32398
movsbl (%rax), %eax
cmpl $0x40, %eax
sete %al
movb %al, -0x52(%rbp)
movb -0x52(%rbp), %al
movb %al, -0x51(%rbp)
movb -0x51(%rbp), %al
testb $0x1, %al
jne 0x8b8a
movq 0x2968a(%rip), %rax     # 0x32398
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x8d20
movq $0x0, -0x8(%rbp)
jmp 0x8d8d
movq 0x29671(%rip), %rdi     # 0x32398
callq 0x4150
movq %rax, %rdx
movq -0x38(%rbp), %rax
movq 0x38(%rax), %rcx
addq %rdx, %rcx
movq %rcx, 0x38(%rax)
movq 0x29653(%rip), %rdi     # 0x32398
callq 0x1eb10
movl $0xe8, %edi
callq 0x4310
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x60(%rbp)
movq 0x29633(%rip), %rsi     # 0x32398
callq 0x5e70
jmp 0x8d6c
movq -0x60(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x8d8d
movq -0x60(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
callq 0x42c0
jmp 0x8d97
movq -0x8(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
movq -0x28(%rbp), %rdi
callq 0x45c0