// File: /workspace/github_cpp_makefile_star2_O3/tonymugen[P]sampleSNPs/varfiles.cpp
// Function: sampFiles::VcfFileI::_numLines()
uint64_t VcfFileI::_numLines(){
	uint64_t N = 0;

	/*
	 * I am using the line-end counting method. It is > 2-fold faster than reading lines with getline().
	 */
	if (_varFile.is_open()) {
        _varFile.close();
    }
    try {
        _varFile.open(_fileName.c_str(), ios::in);
		if (!_varFile.is_open()) {
			cerr << "ERROR: failed to open .vcf file " << _fileName << " for input" << endl;
			exit(2);
		}

    } catch (system_error &error) {
        cerr << "ERROR: cannot open .vcf file " << _fileName << " for input: " << error.code().message() << flush;
        perror(" ");
        exit(1);

    }
	string trash;
	// skip header lines. Will also read the one after the last header line.
	while (1) {
		getline(_varFile, trash);
		if (trash[0] != '#') {
			break;
		}
	}

	const size_t bufSize = BUF_SIZE;
	char *buf;
	try {
		buf = new char[bufSize];
	} catch (bad_alloc& error) {
		cerr << "ERROR: failed to allocate buffer in VcfFileI::_numLines(): " << error.what() << endl;
		exit(4);
	}

	while (_varFile) {
		_varFile.read(buf, bufSize);
		for (size_t i = 0; i < _varFile.gcount(); i++) {
			if (buf[i] == '\n') {
				N++;
			}
		}
	}
	_varFile.close();
	delete [] buf;

	return N + 1; // adding 1 for the line immediately after the header
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x20, %rsp
movq %rdi, %rbx
leaq 0x8(%rdi), %r14
leaq 0x88(%rdi), %r15
movq %r15, %rdi
callq 0x40a0
testb %al, %al
je 0x14769
movq %r14, %rdi
callq 0x4060
movq 0x218(%rbx), %rsi
movq %r14, %rdi
movl $0x8, %edx
callq 0x4270
movq %r15, %rdi
callq 0x40a0
testb %al, %al
je 0x1486f
leaq 0x10(%rsp), %r13
movq %r13, -0x10(%r13)
movq $0x0, -0x8(%r13)
movb $0x0, (%r13)
movq %rsp, %r15
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x4290
movsbl %al, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x4500
movq (%rsp), %rax
cmpb $0x23, (%rax)
je 0x147a6
movl $0xa00000, %edi         # imm = 0xA00000
callq 0x4030
movq %rax, %r12
movq 0x8(%rbx), %rax
movq -0x18(%rax), %rax
movl $0x1, %r15d
testb $0x5, 0x28(%rbx,%rax)
jne 0x14838
xorl %r15d, %r15d
movl $0xa00000, %edx         # imm = 0xA00000
movq %r14, %rdi
movq %r12, %rsi
callq 0x4350
movq 0x10(%rbx), %rax
testq %rax, %rax
je 0x14826
xorl %ecx, %ecx
xorl %edx, %edx
cmpb $0xa, (%r12,%rcx)
sete %dl
addq %rdx, %r15
incq %rcx
cmpq %rcx, %rax
jne 0x14811
movq 0x8(%rbx), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x28(%rbx,%rax)
je 0x147f6
incq %r15
movq %r14, %rdi
callq 0x4060
movq %r12, %rdi
callq 0x4380
movq (%rsp), %rdi
cmpq %r13, %rdi
je 0x1485e
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x42d0
movq %r15, %rax
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq 0xb77a(%rip), %rdi      # 0x1fff0
leaq 0x451b(%rip), %rsi      # 0x18d98
movl $0x20, %edx
callq 0x42f0
movq 0x218(%rbx), %rsi
movq 0x220(%rbx), %rdx
movq 0xb754(%rip), %rdi      # 0x1fff0
callq 0x42f0
movq %rax, %r14
leaq 0x3cc1(%rip), %rsi      # 0x1856c
movl $0xa, %edx
movq %rax, %rdi
callq 0x42f0
movq %r14, %rdi
callq 0x4130
movl $0x2, %edi
callq 0x4320
jmp 0x149fd
movq %rax, %r14
cmpl $0x2, %edx
jne 0x14a00
movq %r14, %rdi
callq 0x4110
movq %rax, %rbx
movq 0xb703(%rip), %rdi      # 0x1fff0
leaq 0x44e3(%rip), %rsi      # 0x18dd7
movl $0x3b, %edx
callq 0x42f0
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movq 0xb6e2(%rip), %rdi      # 0x1fff0
movq %rax, %rsi
callq 0x42a0
movq %rax, %rdi
callq 0x4130
movl $0x4, %edi
callq 0x4320
movq %rax, %r14
callq 0x4480
jmp 0x14a00
movq %rax, %r14
cmpl $0x1, %edx
jne 0x14a16
movq %r14, %rdi
callq 0x4110
movq %rax, %r14
movq 0xb69d(%rip), %rdi      # 0x1fff0
leaq 0x445f(%rip), %rsi      # 0x18db9
movl $0x1d, %edx
callq 0x42f0
movq 0x218(%rbx), %rsi
movq 0x220(%rbx), %rdx
movq 0xb677(%rip), %rdi      # 0x1fff0
callq 0x42f0
movq %rax, %rbx
leaq 0x4075(%rip), %rsi      # 0x189fd
movl $0xc, %edx
movq %rax, %rdi
callq 0x42f0
movq 0x18(%r14), %rsi
movl 0x10(%r14), %edx
movq (%rsi), %rax
movq %rsp, %rdi
callq *0x20(%rax)
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq %rbx, %rdi
callq 0x42f0
movq %rax, %rdi
callq 0x41b0
movq %rsp, %rdi
callq 0x4ab9
movq %rax, %r14
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x149ec
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x42d0
jmp 0x149ec
jmp 0x149e9
movq %rax, %r14
callq 0x4480
jmp 0x14a16
movq %rax, %rdi
callq 0x76d8
jmp 0x149fd
movq %rax, %r14
movq (%rsp), %rdi
cmpq %r13, %rdi
je 0x14a16
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x42d0
movq %r14, %rdi
callq 0x44e0