// File: splatlab[P]debgr/main.cc
// Function: fastq_read_parts(int, file_pointer*)
static bool fastq_read_parts(int mode, file_pointer *fp)
{
	char *& _part = (fp->part);
	uint64_t& _size = fp->size;
	char*& part_buffer = (fp->part_buffer);
	uint64_t& part_filled = fp->part_filled;
	reader& file_reader = *(fp->freader.get());

	uint32_t OVERHEAD_SIZE = 65535;
	uint64_t part_size = 1ULL << 23;
	char *part = (char *)malloc((part_size + OVERHEAD_SIZE)*sizeof(char));
	memcpy(part, part_buffer, part_filled);

	if(is_eof(file_reader, mode))
		return false;

	uint64_t readed = 0;

	if (mode == 0)
		readed = fread(part+part_filled, 1, part_size, file_reader.in);
	else if (mode == 1)
		readed = gzread(file_reader.in_gzip, part+part_filled, (int) part_size);
	else if (mode == 2)
		readed = BZ2_bzRead(&file_reader.bzerror, file_reader.in_bzip2,
												part+part_filled, (int) part_size);
	else 
		readed = 0;

	int64_t total_filled = part_filled + readed;
	int64_t i;
	if(part_filled >= OVERHEAD_SIZE)
	{
		cout << "Error: Wrong input file!\n";
		exit(EXIT_FAILURE);
	}
	if(is_eof(file_reader, mode))
	{
		_part = part;
		_size = total_filled;
		part = NULL;
		return true;
	}
	// Looking for a FASTQ record at the end of the area
	{
		int64_t line_start[9];
		int32_t j;
		i = total_filled - OVERHEAD_SIZE / 2;
		for(j = 0; j < 9; ++j)
		{
			if(!skip_next_eol(part, i, total_filled))
				break;
			line_start[j] = i;
		}
		_part = part;
		if(j < 9)
			_size = 0;
		else
		{
			int k;
			for(k = 0; k < 4; ++k)
			{
				if(part[line_start[k]+0] == '@' && part[line_start[k+2]+0] == '+')
				{
					if(part[line_start[k+2]+1] == '\n' || part[line_start[k+2]+1] == '\r')
						break;
					if(line_start[k+1]-line_start[k] == line_start[k+3]-line_start[k+2] &&
						 memcmp(part+line_start[k]+1, part+line_start[k+2]+1,
										line_start[k+3]-line_start[k+2]-1) == 0)
						break;
				}
			}
			if(k == 4)
				_size = 0;
			else
				_size = line_start[k];
		}
	}

	copy(_part+_size, _part+total_filled, part_buffer);
	part_filled = total_filled - _size;

	return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
addq $0x20, %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
addq $0x28, %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rdi
callq 0x11eb0
movq %rax, -0x38(%rbp)
movl $0xffff, -0x3c(%rbp)    # imm = 0xFFFF
movq $0x800000, -0x48(%rbp)  # imm = 0x800000
movq -0x48(%rbp), %rdi
movl -0x3c(%rbp), %eax
addq %rax, %rdi
shlq $0x0, %rdi
callq 0x65e0
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
movq -0x28(%rbp), %rax
movq (%rax), %rsi
movq -0x30(%rbp), %rax
movq (%rax), %rdx
callq 0x6350
movq -0x38(%rbp), %rdi
movl -0x8(%rbp), %esi
callq 0x11ee0
testb $0x1, %al
jne 0xa07e
jmp 0xa087
movb $0x0, -0x1(%rbp)
jmp 0xa3fc
movq $0x0, -0x58(%rbp)
cmpl $0x0, -0x8(%rbp)
jne 0xa0bb
movq -0x50(%rbp), %rdi
movq -0x30(%rbp), %rax
addq (%rax), %rdi
movq -0x48(%rbp), %rdx
movq -0x38(%rbp), %rax
movq (%rax), %rcx
movl $0x1, %esi
callq 0x6680
movq %rax, -0x58(%rbp)
jmp 0xa127
cmpl $0x1, -0x8(%rbp)
jne 0xa0e7
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x50(%rbp), %rsi
movq -0x30(%rbp), %rax
addq (%rax), %rsi
movq -0x48(%rbp), %rax
movl %eax, %edx
callq 0x6800
cltq
movq %rax, -0x58(%rbp)
jmp 0xa125
cmpl $0x2, -0x8(%rbp)
jne 0xa11b
movq -0x38(%rbp), %rdi
addq $0x18, %rdi
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x50(%rbp), %rdx
movq -0x30(%rbp), %rax
addq (%rax), %rdx
movq -0x48(%rbp), %rax
movl %eax, %ecx
callq 0x6700
cltq
movq %rax, -0x58(%rbp)
jmp 0xa123
movq $0x0, -0x58(%rbp)
jmp 0xa125
jmp 0xa127
movq -0x30(%rbp), %rax
movq (%rax), %rax
addq -0x58(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movl -0x3c(%rbp), %ecx
cmpq %rcx, %rax
jb 0xa162
movq 0x1de7c(%rip), %rdi     # 0x27fc8
leaq 0x129fa(%rip), %rsi     # 0x1cb4d
callq 0x6420
movl $0x1, %edi
callq 0x6570
movq -0x38(%rbp), %rdi
movl -0x8(%rbp), %esi
callq 0x11ee0
testb $0x1, %al
jne 0xa174
jmp 0xa19b
movq -0x50(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x60(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq $0x0, -0x50(%rbp)
movb $0x1, -0x1(%rbp)
jmp 0xa3fc
movq -0x60(%rbp), %rax
movl -0x3c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
subq %rcx, %rax
movq %rax, -0x68(%rbp)
movl $0x0, -0xb4(%rbp)
cmpl $0x9, -0xb4(%rbp)
jge 0xa1fb
movq -0x50(%rbp), %rdi
movq -0x60(%rbp), %rdx
leaq -0x68(%rbp), %rsi
callq 0x7090
testb $0x1, %al
jne 0xa1d7
jmp 0xa1fb
movq -0x68(%rbp), %rcx
movslq -0xb4(%rbp), %rax
movq %rcx, -0xb0(%rbp,%rax,8)
movl -0xb4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb4(%rbp)
jmp 0xa1b7
movq -0x50(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
cmpl $0x9, -0xb4(%rbp)
jge 0xa21f
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
jmp 0xa3c1
movl $0x0, -0xb8(%rbp)
cmpl $0x4, -0xb8(%rbp)
jge 0xa393
movq -0x50(%rbp), %rax
movslq -0xb8(%rbp), %rcx
movq -0xb0(%rbp,%rcx,8), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x40, %eax
jne 0xa37d
movq -0x50(%rbp), %rax
movl -0xb8(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movq -0xb0(%rbp,%rcx,8), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2b, %eax
jne 0xa37d
movq -0x50(%rbp), %rax
movl -0xb8(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movq -0xb0(%rbp,%rcx,8), %rcx
movsbl 0x1(%rax,%rcx), %eax
cmpl $0xa, %eax
je 0xa2bf
movq -0x50(%rbp), %rax
movl -0xb8(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movq -0xb0(%rbp,%rcx,8), %rcx
movsbl 0x1(%rax,%rcx), %eax
cmpl $0xd, %eax
jne 0xa2c4
jmp 0xa393
movl -0xb8(%rbp), %eax
addl $0x1, %eax
cltq
movq -0xb0(%rbp,%rax,8), %rax
movslq -0xb8(%rbp), %rcx
subq -0xb0(%rbp,%rcx,8), %rax
movl -0xb8(%rbp), %ecx
addl $0x3, %ecx
movslq %ecx, %rcx
movq -0xb0(%rbp,%rcx,8), %rcx
movl -0xb8(%rbp), %edx
addl $0x2, %edx
movslq %edx, %rdx
subq -0xb0(%rbp,%rdx,8), %rcx
cmpq %rcx, %rax
jne 0xa37b
movq -0x50(%rbp), %rdi
movslq -0xb8(%rbp), %rax
addq -0xb0(%rbp,%rax,8), %rdi
addq $0x1, %rdi
movq -0x50(%rbp), %rsi
movl -0xb8(%rbp), %eax
addl $0x2, %eax
cltq
addq -0xb0(%rbp,%rax,8), %rsi
addq $0x1, %rsi
movl -0xb8(%rbp), %eax
addl $0x3, %eax
cltq
movq -0xb0(%rbp,%rax,8), %rdx
movl -0xb8(%rbp), %eax
addl $0x2, %eax
cltq
subq -0xb0(%rbp,%rax,8), %rdx
subq $0x1, %rdx
callq 0x6180
cmpl $0x0, %eax
jne 0xa37b
jmp 0xa393
jmp 0xa37d
jmp 0xa37f
movl -0xb8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb8(%rbp)
jmp 0xa229
cmpl $0x4, -0xb8(%rbp)
jne 0xa3a9
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
jmp 0xa3bf
movslq -0xb8(%rbp), %rax
movq -0xb0(%rbp,%rax,8), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
jmp 0xa3c1
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movq -0x20(%rbp), %rax
addq (%rax), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rsi
addq -0x60(%rbp), %rsi
movq -0x28(%rbp), %rax
movq (%rax), %rdx
callq 0x11f60
movq -0x60(%rbp), %rcx
movq -0x20(%rbp), %rax
subq (%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xc0, %rsp
popq %rbp
retq
nopw (%rax,%rax)