// File: /workspace/github_cpp_makefile_star2_O1/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 %r13
pushq %r12
pushq %rbx
subq $0x40, %rsp
movq %rdi, %r14
leaq 0x240(%rdi), %rbx
leaq 0x2c0(%rdi), %r15
movq %r15, %rdi
callq 0x40a0
testb %al, %al
je 0x1275c
movq %rbx, %rdi
callq 0x4060
leaq 0x10(%rsp), %r13
movq %r13, -0x10(%r13)
movq 0x450(%r14), %rsi
movq 0x458(%r14), %rdx
addq %rsi, %rdx
movq %rsp, %r12
movq %r12, %rdi
callq 0x7720
leaq 0x64b7(%rip), %rsi      # 0x18c3f
movq %r12, %rdi
callq 0x4530
movq (%rsp), %rsi
movq %rbx, %rdi
movl $0x8, %edx
callq 0x4270
movq %r15, %rdi
callq 0x40a0
testb %al, %al
je 0x1285c
movl $0xa00000, %edi         # imm = 0xA00000
callq 0x4030
movq %rax, %r12
movq 0x240(%r14), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x260(%r14,%rax)
je 0x127d9
xorl %r15d, %r15d
jmp 0x12825
xorl %r15d, %r15d
movl $0xa00000, %edx         # imm = 0xA00000
movq %rbx, %rdi
movq %r12, %rsi
callq 0x4350
movq 0x248(%r14), %rax
testq %rax, %rax
je 0x1280f
xorl %ecx, %ecx
xorl %edx, %edx
cmpb $0xa, (%r12,%rcx)
sete %dl
addq %rdx, %r15
incq %rcx
cmpq %rcx, %rax
jne 0x127fa
movq 0x240(%r14), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x260(%r14,%rax)
je 0x127dc
movq %r12, %rdi
callq 0x4380
movq %rbx, %rdi
callq 0x4060
movq (%rsp), %rdi
cmpq %r13, %rdi
je 0x1284b
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x42d0
movq %r15, %rax
addq $0x40, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq 0xd78d(%rip), %rdi      # 0x1fff0
leaq 0x63db(%rip), %rsi      # 0x18c45
movl $0x21, %edx
callq 0x42f0
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq 0xd76c(%rip), %rdi      # 0x1fff0
callq 0x42f0
movq %rax, %rbx
leaq 0x5cd9(%rip), %rsi      # 0x1856c
movl $0xa, %edx
movq %rax, %rdi
callq 0x42f0
movq %rbx, %rdi
callq 0x4130
movl $0x2, %edi
callq 0x4320
jmp 0x129e7
movq %rax, %rbx
cmpl $0x2, %edx
jne 0x129ea
movq %rbx, %rdi
callq 0x4110
movq %rax, %rbx
movq 0xd71b(%rip), %rdi      # 0x1fff0
leaq 0x63aa(%rip), %rsi      # 0x18c86
movl $0x3b, %edx
callq 0x42f0
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movq 0xd6fa(%rip), %rdi      # 0x1fff0
movq %rax, %rsi
callq 0x42a0
movq %rax, %rdi
callq 0x4130
movl $0x4, %edi
callq 0x4320
movq %rax, %rbx
callq 0x4480
jmp 0x129ea
jmp 0x129e7
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x129ea
movq %rbx, %rdi
callq 0x4110
movq %rax, %rbx
movq 0xd6b0(%rip), %rdi      # 0x1fff0
leaq 0x6320(%rip), %rsi      # 0x18c67
movl $0x1e, %edx
callq 0x42f0
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq 0xd68f(%rip), %rdi      # 0x1fff0
callq 0x42f0
movq %rax, %r14
leaq 0x608d(%rip), %rsi      # 0x189fd
movl $0xc, %edx
movq %rax, %rdi
callq 0x42f0
movq 0x18(%rbx), %rsi
movl 0x10(%rbx), %edx
movq (%rsi), %rax
leaq 0x20(%rsp), %rdi
callq *0x20(%rax)
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
movq %r14, %rdi
callq 0x42f0
movq %rax, %rdi
callq 0x41b0
leaq 0x20(%rsp), %rdi
callq 0x4933
movq %rax, %rbx
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x129d8
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x42d0
jmp 0x129d8
jmp 0x129d5
movq %rax, %rbx
callq 0x4480
jmp 0x129ea
movq %rax, %rdi
callq 0x7714
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r13, %rdi
je 0x12a00
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x42d0
movq %rbx, %rdi
callq 0x44e0