// File: /workspace/github_cpp_makefile_star2_O2/tonymugen[P]sampleSNPs/varfiles.cpp
// Function: sampFiles::GtxtFileI::_numLines()
uint64_t GtxtFileI::_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 file " << _fileName << " for input" << endl;
			exit(2);
		}

    } catch (system_error &error) {
        cerr << "ERROR: cannot open text 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 GtxtFile::_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 - _head; // subtracting 1 for the header if present

}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
leaq 0x8(%rdi), %r14
leaq 0x88(%rdi), %r12
movq %r12, %rdi
callq 0x40b0
testb %al, %al
je 0xdab7
movq %r14, %rdi
callq 0x4050
leaq 0x218(%rbx), %r15
movq 0x218(%rbx), %rsi
pushq $0x8
popq %rdx
movq %r14, %rdi
callq 0x4280
movq %r12, %rdi
callq 0x40b0
testb %al, %al
je 0xdb51
movl $0xa00000, %edi         # imm = 0xA00000
callq 0x4030
movq %rax, %r12
xorl %r15d, %r15d
movq 0x8(%rbx), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x28(%rbx,%rax)
jne 0xdb28
movl $0xa00000, %edx         # imm = 0xA00000
movq %r14, %rdi
movq %r12, %rsi
callq 0x4340
movq 0x10(%rbx), %rax
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0xdaec
xorl %edx, %edx
cmpb $0xa, (%r12,%rcx)
sete %dl
addq %rdx, %r15
incq %rcx
jmp 0xdb11
movq %r14, %rdi
callq 0x4050
movq %r12, %rdi
callq 0x4370
movzbl 0x238(%rbx), %eax
subq %rax, %r15
movq %r15, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq 0xe498(%rip), %rdi      # 0x1bff0
leaq 0x69f1(%rip), %rsi      # 0x14550
callq 0x42a0
movq %rax, %rdi
movq %r15, %rsi
callq 0x4270
leaq 0x69f6(%rip), %rsi      # 0x1456c
movq %rax, %rdi
callq 0x42a0
movq %rax, %rdi
callq 0x4140
pushq $0x2
jmp 0xdbd5
movq %rax, %rbx
cmpl $0x2, %edx
jne 0xdc8c
movq %rbx, %rdi
callq 0x4110
movq %rax, %rbx
movq 0xe448(%rip), %rdi      # 0x1bff0
leaq 0x7022(%rip), %rsi      # 0x14bd1
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 0xdc8c
movq %rax, %rbx
cmpl $0x1, %edx
jne 0xdc8c
movq %rbx, %rdi
callq 0x4110
movq %rax, %rbx
movq 0xe3ea(%rip), %rdi      # 0x1bff0
leaq 0x6fa6(%rip), %rsi      # 0x14bb3
callq 0x42a0
movq %rax, %rdi
movq %r15, %rsi
callq 0x4270
leaq 0x6dd9(%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 0x6bab(%rip), %rdi      # 0x14812
callq 0x4250
pushq $0x1
jmp 0xdbd5
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x4558
jmp 0xdc87
jmp 0xdc84
movq %rax, %rbx
callq 0x4470
movq %rbx, %rdi
callq 0x44d0
movq %rax, %rdi
callq 0x6194