// File: /workspace/github_cpp_makefile_star2_O3/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 0x128a6
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 0x76e4
leaq 0x636b(%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 0x129c3
leaq 0x80(%rbx), %rdi
callq 0x40a0
testb %al, %al
je 0x12a1a
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 0x1297d
movl $0xa00000, %edx         # imm = 0xA00000
movq %r14, %rdi
movq %r13, %rsi
callq 0x4350
movq 0x248(%r15), %rdx
testq %rdx, %rdx
je 0x12970
xorl %eax, %eax
xorl %ecx, %ecx
cmpb $0xa, (%r13,%rax)
sete %cl
addq %rcx, %r12
incq %rax
cmpq %rax, %rdx
jne 0x1295a
movq %rbp, %rdi
movq %r13, %rsi
callq 0x4390
jmp 0x12926
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 0x129b1
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 0xd626(%rip), %rdi      # 0x1fff0
leaq 0x6274(%rip), %rsi      # 0x18c45
movl $0x21, %edx
callq 0x42f0
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq 0xd604(%rip), %rdi      # 0x1fff0
callq 0x42f0
movq %rax, %rbx
leaq 0x5b71(%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)
leaq 0x5ddf(%rip), %rsi      # 0x18814
leaq 0x5df7(%rip), %rdx      # 0x18833
movq %r14, %rdi
callq 0x7b0a
leaq 0xce75(%rip), %rsi      # 0x1f8c0
movq 0xd56e(%rip), %rdx      # 0x1ffc0
movq %r14, %rdi
callq 0x44b0
jmp 0x12ba2
movq %rax, %rbx
movq %r14, %rdi
callq 0x41f0
jmp 0x12ba5
movq %rax, %rbx
cmpl $0x2, %edx
jne 0x12ba5
movq %rbx, %rdi
callq 0x4110
movq %rax, %rbx
movq 0xd563(%rip), %rdi      # 0x1fff0
leaq 0x622e(%rip), %rsi      # 0x18cc2
movl $0x3b, %edx
callq 0x42f0
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movq 0xd542(%rip), %rdi      # 0x1fff0
movq %rax, %rsi
callq 0x42a0
movq %rax, %rdi
callq 0x4130
movl $0x4, %edi
callq 0x4320
movq %rax, %rbx
callq 0x4480
jmp 0x12ba5
jmp 0x12ba2
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x12ba5
movq %rbx, %rdi
callq 0x4110
movq %rax, %rbx
movq 0xd4f8(%rip), %rdi      # 0x1fff0
leaq 0x6168(%rip), %rsi      # 0x18c67
movl $0x1e, %edx
callq 0x42f0
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq 0xd4d6(%rip), %rdi      # 0x1fff0
callq 0x42f0
movq %rax, %r14
leaq 0x5ed4(%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 0x12b91
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x42d0
jmp 0x12b91
jmp 0x12b8e
movq %rax, %rbx
callq 0x4480
jmp 0x12ba5
movq %rax, %rdi
callq 0x76d8
jmp 0x12ba2
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x12bc1
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x42d0
movq %rbx, %rdi
callq 0x44e0
nop