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

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

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

    }

    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::_numLines(): " << error.what() << endl;
        exit(4);
    }

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

    return N;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %r14
leaq 0x8(%rdi), %rbx
leaq 0x88(%rdi), %r12
movq %r12, %rdi
callq 0x40b0
testb %al, %al
je 0xf479
movq %rbx, %rdi
callq 0x4050
leaq 0x218(%r14), %r15
movq 0x218(%r14), %rsi
pushq $0x8
popq %rdx
movq %rbx, %rdi
callq 0x4280
movq %r12, %rdi
callq 0x40b0
testb %al, %al
je 0xf50a
movl $0xa00000, %edi         # imm = 0xA00000
callq 0x4030
movq %rax, %r15
xorl %r12d, %r12d
movq 0x8(%r14), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x28(%r14,%rax)
jne 0xf4eb
movl $0xa00000, %edx         # imm = 0xA00000
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4340
movq 0x10(%r14), %rax
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0xf4ae
xorl %edx, %edx
cmpb $0xa, (%r15,%rcx)
sete %dl
addq %rdx, %r12
incq %rcx
jmp 0xf4d4
movq %rbx, %rdi
callq 0x4050
movq %r15, %rdi
callq 0x4370
movq %r12, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq 0xcadf(%rip), %rdi      # 0x1bff0
leaq 0x5821(%rip), %rsi      # 0x14d39
callq 0x42a0
movq %rax, %rdi
movq %r15, %rsi
callq 0x4270
leaq 0x503d(%rip), %rsi      # 0x1456c
movq %rax, %rdi
callq 0x42a0
movq %rax, %rdi
callq 0x4140
pushq $0x2
jmp 0xf58e
movq %rax, %rbx
cmpl $0x2, %edx
jne 0xf645
movq %rbx, %rdi
callq 0x4110
movq %rax, %rbx
movq 0xca8f(%rip), %rdi      # 0x1bff0
leaq 0x571e(%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 0xf645
movq %rax, %rbx
cmpl $0x1, %edx
jne 0xf645
movq %rbx, %rdi
callq 0x4110
movq %rax, %rbx
movq 0xca31(%rip), %rdi      # 0x1bff0
leaq 0x5795(%rip), %rsi      # 0x14d5b
callq 0x42a0
movq %rax, %rdi
movq %r15, %rsi
callq 0x4270
leaq 0x5420(%rip), %rsi      # 0x149fd
movq %rax, %rdi
callq 0x42a0
movq %rax, %r14
movq 0x18(%rbx), %rsi
movl 0x10(%rbx), %edx
movq (%rsi), %rax
leaq 0x8(%rsp), %rdi
callq *0x20(%rax)
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x4270
movq %rax, %rdi
callq 0x41c0
leaq 0x8(%rsp), %rdi
callq 0x4558
leaq 0x51f2(%rip), %rdi      # 0x14812
callq 0x4250
pushq $0x1
jmp 0xf58e
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x4558
jmp 0xf640
jmp 0xf63d
movq %rax, %rbx
callq 0x4470
movq %rbx, %rdi
callq 0x44d0
movq %rax, %rdi
callq 0x6194
nop