// File: 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 %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x90(%rbp)
movq $0x0, -0x10(%rbp)
addq $0x240, %rdi            # imm = 0x240
callq 0x45e0
testb $0x1, %al
jne 0x18e84
jmp 0x18e97
movq -0x90(%rbp), %rdi
addq $0x240, %rdi            # imm = 0x240
callq 0x4060
movq -0x90(%rbp), %rsi
addq $0x450, %rsi            # imm = 0x450
leaq 0xad7b(%rip), %rdx      # 0x23c27
leaq -0x30(%rbp), %rdi
movq %rdi, -0xa0(%rbp)
callq 0x7920
movq -0x90(%rbp), %rax
movq -0xa0(%rbp), %rdi
addq $0x240, %rax            # imm = 0x240
movq %rax, -0x98(%rbp)
callq 0x4140
movq -0x98(%rbp), %rdi
movq %rax, %rsi
movl $0x8, %edx
callq 0x42f0
jmp 0x18ef2
movq -0x90(%rbp), %rdi
addq $0x240, %rdi            # imm = 0x240
callq 0x45e0
movb %al, -0xa1(%rbp)
jmp 0x18f0d
movb -0xa1(%rbp), %al
testb $0x1, %al
jne 0x1906d
jmp 0x18f1d
movq 0x130cc(%rip), %rdi     # 0x2bff0
leaq 0xad02(%rip), %rsi      # 0x23c2d
callq 0x4310
movq %rax, -0xb0(%rbp)
jmp 0x18f39
movq -0xb0(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x42e0
movq %rax, -0xb8(%rbp)
jmp 0x18f52
movq -0xb8(%rbp), %rdi
leaq 0xa5f4(%rip), %rsi      # 0x23554
callq 0x4310
movq %rax, -0xc0(%rbp)
jmp 0x18f6e
movq -0xc0(%rbp), %rdi
movq 0x13034(%rip), %rsi     # 0x2bfb0
callq 0x4350
jmp 0x18f83
movl $0x2, %edi
callq 0x4400
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x192ac
movq -0x38(%rbp), %rdi
callq 0x4130
movq %rax, -0x48(%rbp)
movq 0x13033(%rip), %rdi     # 0x2bff0
leaq 0xac8b(%rip), %rsi      # 0x23c4f
callq 0x4310
movq %rax, -0xc8(%rbp)
jmp 0x18fd2
movq -0xc8(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x42e0
movq %rax, -0xd0(%rbp)
jmp 0x18feb
movq -0xd0(%rbp), %rdi
leaq 0xa9ec(%rip), %rsi      # 0x239e5
callq 0x4310
movq %rax, -0xd8(%rbp)
jmp 0x19007
movq -0x48(%rbp), %rdi
callq 0x1ee90
movq %rax, %rsi
leaq -0x68(%rbp), %rdi
callq 0x1eeb0
jmp 0x1901e
movq -0xd8(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x42e0
movq %rax, -0xe0(%rbp)
jmp 0x19037
movq -0xe0(%rbp), %rdi
movq 0x12f83(%rip), %rsi     # 0x2bfc8
callq 0x4350
jmp 0x1904c
leaq -0x68(%rbp), %rdi
callq 0x46d8
leaq 0xa79e(%rip), %rdi      # 0x237fa
callq 0x42a0
jmp 0x19063
movl $0x1, %edi
callq 0x4400
jmp 0x1909e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x19092
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x46d8
callq 0x4580
jmp 0x19099
jmp 0x192ac
movq $0xa00000, -0x70(%rbp)  # imm = 0xA00000
movl $0xa00000, %edi         # imm = 0xA00000
callq 0x4030
movq %rax, -0xe8(%rbp)
jmp 0x190b9
movq -0xe8(%rbp), %rax
movq %rax, -0x78(%rbp)
jmp 0x1916a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movl $0x2, %ecx
cmpl %ecx, %eax
jne 0x192ac
movq -0x38(%rbp), %rdi
callq 0x4130
movq %rax, -0x80(%rbp)
movq 0x12ef7(%rip), %rdi     # 0x2bff0
leaq 0xab6e(%rip), %rsi      # 0x23c6e
callq 0x4310
movq %rax, -0xf0(%rbp)
jmp 0x1910e
movq -0x80(%rbp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movq -0xf0(%rbp), %rdi
movq %rax, %rsi
callq 0x4310
movq %rax, -0xf8(%rbp)
jmp 0x19133
movq -0xf8(%rbp), %rdi
movq 0x12e6f(%rip), %rsi     # 0x2bfb0
callq 0x4350
jmp 0x19148
movl $0x4, %edi
callq 0x4400
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
callq 0x4580
jmp 0x19165
jmp 0x192ac
jmp 0x1916c
movq -0x90(%rbp), %rax
movq 0x240(%rax), %rcx
movq -0x18(%rcx), %rcx
leaq 0x240(%rax,%rcx), %rdi
callq 0x4440
movb %al, -0xf9(%rbp)
jmp 0x19193
movb -0xf9(%rbp), %al
testb $0x1, %al
jne 0x191a2
jmp 0x19256
movq -0x90(%rbp), %rdi
addq $0x240, %rdi            # imm = 0x240
movq -0x78(%rbp), %rsi
movl $0xa00000, %edx         # imm = 0xA00000
callq 0x4450
jmp 0x191c0
movq $0x0, -0x88(%rbp)
movq -0x90(%rbp), %rdi
movq -0x88(%rbp), %rax
movq %rax, -0x110(%rbp)
addq $0x240, %rdi            # imm = 0x240
callq 0x46c0
movq %rax, -0x108(%rbp)
jmp 0x191f5
movq -0x110(%rbp), %rax
movq -0x108(%rbp), %rcx
cmpq %rcx, %rax
jae 0x19251
movq -0x78(%rbp), %rax
movq -0x88(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0xa, %eax
jne 0x19238
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0x19238
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x192ac
jmp 0x1923a
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0x191cb
jmp 0x1916c
movq -0x78(%rbp), %rax
movq %rax, -0x118(%rbp)
cmpq $0x0, %rax
je 0x19273
movq -0x118(%rbp), %rdi
callq 0x4480
movq -0x90(%rbp), %rdi
addq $0x240, %rdi            # imm = 0x240
callq 0x4060
jmp 0x19288
movq -0x10(%rbp), %rax
movq %rax, -0x120(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x46d8
movq -0x120(%rbp), %rax
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
leaq -0x30(%rbp), %rdi
callq 0x46d8
movq -0x38(%rbp), %rdi
callq 0x4610
movq %rax, %rdi
callq 0x82c0
nopw %cs:(%rax,%rax)