// File: /workspace/github_cpp_makefile_star2_O2/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 %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %r14
leaq 0x8(%rdi), %rbx
leaq 0x88(%rdi), %r12
movq %r12, %rdi
callq 0x40b0
testb %al, %al
je 0x106ed
movq %rbx, %rdi
callq 0x4050
leaq 0x218(%r14), %r15
movq 0x218(%r14), %rsi
pushq $0x8
popq %rdx
movq %rbx, %rdi
callq 0x4280
movq %r12, %rdi
callq 0x40b0
testb %al, %al
je 0x107ba
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x8(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4060
movq 0x8(%rsp), %rax
cmpb $0x23, (%rax)
je 0x1072c
movl $0xa00000, %edi         # imm = 0xA00000
callq 0x4030
movq %rax, %r12
xorl %r15d, %r15d
movq 0x8(%r14), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x28(%r14,%rax)
jne 0x1078e
movl $0xa00000, %edx         # imm = 0xA00000
movq %rbx, %rdi
movq %r12, %rsi
callq 0x4340
movq 0x10(%r14), %rax
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x10751
xorl %edx, %edx
cmpb $0xa, (%r12,%rcx)
sete %dl
addq %rdx, %r15
incq %rcx
jmp 0x10777
movq %rbx, %rdi
callq 0x4050
movq %r12, %rdi
callq 0x4370
incq %r15
leaq 0x8(%rsp), %rdi
callq 0x4558
movq %r15, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq 0xb82f(%rip), %rdi      # 0x1bff0
leaq 0x45d0(%rip), %rsi      # 0x14d98
callq 0x42a0
movq %rax, %rdi
movq %r15, %rsi
callq 0x4270
leaq 0x3d8d(%rip), %rsi      # 0x1456c
movq %rax, %rdi
callq 0x42a0
movq %rax, %rdi
callq 0x4140
pushq $0x2
jmp 0x10843
jmp 0x10906
movq %rax, %rbx
cmpl $0x2, %edx
jne 0x10909
movq %rbx, %rdi
callq 0x4110
movq %rax, %rbx
movq 0xb7da(%rip), %rdi      # 0x1bff0
leaq 0x45ba(%rip), %rsi      # 0x14dd7
callq 0x42a0
movq %rax, %r14
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movq %r14, %rdi
movq %rax, %rsi
callq 0x42a0
movq %rax, %rdi
callq 0x4140
pushq $0x4
popq %rdi
callq 0x4310
movq %rax, %rbx
callq 0x4470
jmp 0x10909
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x10913
movq %rbx, %rdi
callq 0x4110
movq %rax, %rbx
movq 0xb77c(%rip), %rdi      # 0x1bff0
leaq 0x453e(%rip), %rsi      # 0x14db9
callq 0x42a0
movq %rax, %rdi
movq %r15, %rsi
callq 0x4270
leaq 0x416b(%rip), %rsi      # 0x149fd
movq %rax, %rdi
callq 0x42a0
movq %rax, %r14
movq 0x18(%rbx), %rsi
movl 0x10(%rbx), %edx
movq (%rsi), %rax
leaq 0x8(%rsp), %rdi
callq *0x20(%rax)
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x4270
movq %rax, %rdi
callq 0x41c0
leaq 0x8(%rsp), %rdi
callq 0x4558
leaq 0x3f3d(%rip), %rdi      # 0x14812
callq 0x4250
pushq $0x1
jmp 0x10843
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x4558
jmp 0x108f5
jmp 0x108f2
movq %rax, %rbx
callq 0x4470
jmp 0x10913
movq %rax, %rdi
callq 0x6194
jmp 0x10906
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x4558
movq %rbx, %rdi
callq 0x44d0
nop