// File: /workspace/github_cpp_makefile_star2_O2/tonymugen[P]sampleSNPs/varfiles.cpp
// Function: sampFiles::TpedFileI::_famLines()
uint64_t TpedFileI::_famLines(){
	uint64_t N = 0;

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

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

    }

	const size_t bufSize = BUF_SIZE; // 10M seems optimal based on experiments on my MacBook Pro (with SSD)
	char *buf;
	try {
		buf = new char[bufSize];
	} catch (bad_alloc& error) {
		cerr << "ERROR: failed to allocate buffer in TpedFile::_numLines(): " << error.what() << endl;
		exit(4);
	}

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

	return N;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %r14
leaq 0x240(%rdi), %rbx
leaq 0x2c0(%rdi), %r15
movq %r15, %rdi
callq 0x40b0
testb %al, %al
je 0xecca
movq %rbx, %rdi
callq 0x4050
leaq 0x450(%r14), %rsi
leaq 0x5f67(%rip), %rdx      # 0x14c3f
leaq 0x8(%rsp), %r12
movq %r12, %rdi
callq 0x5e08
movq (%r12), %rsi
pushq $0x8
popq %rdx
movq %rbx, %rdi
callq 0x4280
movq %r15, %rdi
callq 0x40b0
testb %al, %al
je 0xed7f
movl $0xa00000, %edi         # imm = 0xA00000
callq 0x4030
movq %rax, %r12
xorl %r15d, %r15d
movq 0x240(%r14), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x260(%r14,%rax)
jne 0xed56
movl $0xa00000, %edx         # imm = 0xA00000
movq %rbx, %rdi
movq %r12, %rsi
callq 0x4340
movq 0x248(%r14), %rax
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0xed10
xorl %edx, %edx
cmpb $0xa, (%r12,%rcx)
sete %dl
addq %rdx, %r15
incq %rcx
jmp 0xed3f
movq %r12, %rdi
callq 0x4370
movq %rbx, %rdi
callq 0x4050
leaq 0x8(%rsp), %rdi
callq 0x4558
movq %r15, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq 0xd26a(%rip), %rdi      # 0x1bff0
leaq 0x5eb8(%rip), %rsi      # 0x14c45
callq 0x42a0
leaq 0x8(%rsp), %rsi
movq %rax, %rdi
callq 0x4270
leaq 0x57c6(%rip), %rsi      # 0x1456c
movq %rax, %rdi
callq 0x42a0
movq %rax, %rdi
callq 0x4140
pushq $0x2
jmp 0xee0a
jmp 0xeecd
movq %rax, %rbx
cmpl $0x2, %edx
jne 0xeed0
movq %rbx, %rdi
callq 0x4110
movq %rax, %rbx
movq 0xd213(%rip), %rdi      # 0x1bff0
leaq 0x5ea2(%rip), %rsi      # 0x14c86
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 0xeed0
movq %rax, %rbx
cmpl $0x1, %edx
jne 0xeed0
movq %rbx, %rdi
callq 0x4110
movq %rax, %rbx
movq 0xd1b5(%rip), %rdi      # 0x1bff0
leaq 0x5e25(%rip), %rsi      # 0x14c67
callq 0x42a0
leaq 0x8(%rsp), %rsi
movq %rax, %rdi
callq 0x4270
leaq 0x5ba2(%rip), %rsi      # 0x149fd
movq %rax, %rdi
callq 0x42a0
movq %rax, %r14
movq 0x18(%rbx), %rsi
movl 0x10(%rbx), %edx
movq (%rsi), %rax
leaq 0x28(%rsp), %rdi
callq *0x20(%rax)
leaq 0x28(%rsp), %rsi
movq %r14, %rdi
callq 0x4270
movq %rax, %rdi
callq 0x41c0
leaq 0x28(%rsp), %rdi
callq 0x4558
leaq 0x5974(%rip), %rdi      # 0x14812
callq 0x4250
pushq $0x1
jmp 0xee0a
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x4558
jmp 0xeebe
jmp 0xeebb
movq %rax, %rbx
callq 0x4470
jmp 0xeed0
movq %rax, %rdi
callq 0x6194
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x4558
movq %rbx, %rdi
callq 0x44d0