// File: /workspace/github_cpp_makefile_star2_O1/tonymugen[P]sampleSNPs/varfiles.cpp
// Function: sampFiles::TpedFileI::_famLines(std::basic_fstream<char, std::char_traits<char>>&)
uint64_t TpedFileI::_famLines(fstream &fam){
	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);
    }
    if (!fam.is_open()) {
        throw string("Output .fam filestream not open");
    }
    const size_t bufSize = BUF_SIZE;
    char *buf;
    try {
        buf = new char[bufSize];
    } catch (bad_alloc& error) {
        cerr << "ERROR: failed to allocate buffer in TpedFile::_famLines(): " << 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++;
            }
        }
        fam.write(buf, _tfamFile.gcount());
    }
    _tfamFile.close();
    fam.close();
    delete [] buf;

	return N;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %rbx
movq %rdi, %r15
leaq 0x240(%rdi), %r14
leaq 0x2c0(%rdi), %r12
movq %r12, %rdi
callq 0x40a0
testb %al, %al
je 0x12a3e
movq %r14, %rdi
callq 0x4060
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
movq 0x450(%r15), %rsi
movq 0x458(%r15), %rdx
addq %rsi, %rdx
leaq 0x8(%rsp), %r13
movq %r13, %rdi
callq 0x7720
leaq 0x61d3(%rip), %rsi      # 0x18c3f
movq %r13, %rdi
callq 0x4530
movq 0x8(%rsp), %rsi
movq %r14, %rdi
movl $0x8, %edx
callq 0x4270
movq %r12, %rdi
callq 0x40a0
testb %al, %al
je 0x12b5b
leaq 0x80(%rbx), %rdi
callq 0x40a0
testb %al, %al
je 0x12bb2
movl $0xa00000, %edi         # imm = 0xA00000
callq 0x4030
movq %rax, %r13
leaq 0x10(%rbx), %rbp
xorl %r12d, %r12d
movq 0x240(%r15), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x260(%r15,%rax)
jne 0x12b15
movl $0xa00000, %edx         # imm = 0xA00000
movq %r14, %rdi
movq %r13, %rsi
callq 0x4350
movq 0x248(%r15), %rdx
testq %rdx, %rdx
je 0x12b08
xorl %eax, %eax
xorl %ecx, %ecx
cmpb $0xa, (%r13,%rax)
sete %cl
addq %rcx, %r12
incq %rax
cmpq %rax, %rdx
jne 0x12af2
movq %rbp, %rdi
movq %r13, %rsi
callq 0x4390
jmp 0x12abe
movq %r14, %rdi
callq 0x4060
movq %rbx, %rdi
callq 0x4060
movq %r13, %rdi
callq 0x4380
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x12b49
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x42d0
movq %r12, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xd48e(%rip), %rdi      # 0x1fff0
leaq 0x60dc(%rip), %rsi      # 0x18c45
movl $0x21, %edx
callq 0x42f0
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq 0xd46c(%rip), %rdi      # 0x1fff0
callq 0x42f0
movq %rax, %rbx
leaq 0x59d9(%rip), %rsi      # 0x1856c
movl $0xa, %edx
movq %rax, %rdi
callq 0x42f0
movq %rbx, %rdi
callq 0x4130
movl $0x2, %edi
callq 0x4320
movl $0x20, %edi
callq 0x4140
movq %rax, %r14
addq $0x10, %rax
movq %rax, (%r14)
movb $0x1, %bpl
leaq 0x5c44(%rip), %rsi      # 0x18814
leaq 0x5c5c(%rip), %rdx      # 0x18833
movq %r14, %rdi
callq 0x7b72
xorl %ebp, %ebp
leaq 0xccd8(%rip), %rsi      # 0x1f8c0
movq 0xd3d1(%rip), %rdx      # 0x1ffc0
movq %r14, %rdi
callq 0x44b0
movq %rax, %rbx
cmpl $0x2, %edx
jne 0x12d46
movq %rbx, %rdi
callq 0x4110
movq %rax, %rbx
movq 0xd3db(%rip), %rdi      # 0x1fff0
leaq 0x60a6(%rip), %rsi      # 0x18cc2
movl $0x3b, %edx
callq 0x42f0
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movq 0xd3ba(%rip), %rdi      # 0x1fff0
movq %rax, %rsi
callq 0x42a0
movq %rax, %rdi
callq 0x4130
movl $0x4, %edi
callq 0x4320
movq %rax, %rbx
callq 0x4480
jmp 0x12d46
movq %rax, %rbx
testb %bpl, %bpl
je 0x12d46
movq %r14, %rdi
callq 0x41f0
jmp 0x12d46
jmp 0x12d43
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x12d46
movq %rbx, %rdi
callq 0x4110
movq %rax, %rbx
movq 0xd357(%rip), %rdi      # 0x1fff0
leaq 0x5fc7(%rip), %rsi      # 0x18c67
movl $0x1e, %edx
callq 0x42f0
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq 0xd335(%rip), %rdi      # 0x1fff0
callq 0x42f0
movq %rax, %r14
leaq 0x5d33(%rip), %rsi      # 0x189fd
movl $0xc, %edx
movq %rax, %rdi
callq 0x42f0
movq 0x18(%rbx), %rsi
movl 0x10(%rbx), %edx
movq (%rsi), %rax
leaq 0x28(%rsp), %rdi
callq *0x20(%rax)
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
movq %r14, %rdi
callq 0x42f0
movq %rax, %rdi
callq 0x41b0
leaq 0x28(%rsp), %rdi
callq 0x494d
movq %rax, %rbx
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x12d32
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x42d0
jmp 0x12d32
jmp 0x12d2f
movq %rax, %rbx
callq 0x4480
jmp 0x12d46
movq %rax, %rdi
callq 0x7714
jmp 0x12d43
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x12d62
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x42d0
movq %rbx, %rdi
callq 0x44e0