// File: 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 %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x70(%rbp)
movq $0x0, -0x10(%rbp)
addq $0x8, %rdi
callq 0x45e0
testb $0x1, %al
jne 0x16f7e
jmp 0x16f8b
movq -0x70(%rbp), %rdi
addq $0x8, %rdi
callq 0x4060
movq -0x70(%rbp), %rdi
movq %rdi, %rax
addq $0x8, %rax
movq %rax, -0x78(%rbp)
addq $0x218, %rdi            # imm = 0x218
callq 0x4140
movq -0x78(%rbp), %rdi
movq %rax, %rsi
movl $0x8, %edx
callq 0x42f0
jmp 0x16fb9
movq -0x70(%rbp), %rdi
addq $0x8, %rdi
callq 0x45e0
movb %al, -0x79(%rbp)
jmp 0x16fcb
movb -0x79(%rbp), %al
testb $0x1, %al
jne 0x17136
jmp 0x16fd8
movq 0x15011(%rip), %rdi     # 0x2bff0
leaq 0xc552(%rip), %rsi      # 0x23538
callq 0x4310
movq %rax, -0x88(%rbp)
jmp 0x16ff4
movq -0x88(%rbp), %rdi
movq -0x70(%rbp), %rsi
addq $0x218, %rsi            # imm = 0x218
callq 0x42e0
movq %rax, -0x90(%rbp)
jmp 0x17014
movq -0x90(%rbp), %rdi
leaq 0xc532(%rip), %rsi      # 0x23554
callq 0x4310
movq %rax, -0x98(%rbp)
jmp 0x17030
movq -0x98(%rbp), %rdi
movq 0x14f72(%rip), %rsi     # 0x2bfb0
callq 0x4350
jmp 0x17045
movl $0x2, %edi
callq 0x4400
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x17314
movq -0x18(%rbp), %rdi
callq 0x4130
movq %rax, -0x28(%rbp)
movq 0x14f71(%rip), %rdi     # 0x2bff0
leaq 0xcb15(%rip), %rsi      # 0x23b9b
callq 0x4310
movq %rax, -0xa0(%rbp)
jmp 0x17094
movq -0xa0(%rbp), %rdi
movq -0x70(%rbp), %rsi
addq $0x218, %rsi            # imm = 0x218
callq 0x42e0
movq %rax, -0xa8(%rbp)
jmp 0x170b4
movq -0xa8(%rbp), %rdi
leaq 0xc923(%rip), %rsi      # 0x239e5
callq 0x4310
movq %rax, -0xb0(%rbp)
jmp 0x170d0
movq -0x28(%rbp), %rdi
callq 0x1ee90
movq %rax, %rsi
leaq -0x48(%rbp), %rdi
callq 0x1eeb0
jmp 0x170e7
movq -0xb0(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x42e0
movq %rax, -0xb8(%rbp)
jmp 0x17100
movq -0xb8(%rbp), %rdi
movq 0x14eba(%rip), %rsi     # 0x2bfc8
callq 0x4350
jmp 0x17115
leaq -0x48(%rbp), %rdi
callq 0x46d8
leaq 0xc6d5(%rip), %rdi      # 0x237fa
callq 0x42a0
jmp 0x1712c
movl $0x1, %edi
callq 0x4400
jmp 0x17167
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x1715b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x46d8
callq 0x4580
jmp 0x17162
jmp 0x17314
movq $0xa00000, -0x50(%rbp)  # imm = 0xA00000
movl $0xa00000, %edi         # imm = 0xA00000
callq 0x4030
movq %rax, -0xc0(%rbp)
jmp 0x17182
movq -0xc0(%rbp), %rax
movq %rax, -0x58(%rbp)
jmp 0x17233
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movl $0x2, %ecx
cmpl %ecx, %eax
jne 0x17314
movq -0x18(%rbp), %rdi
callq 0x4130
movq %rax, -0x60(%rbp)
movq 0x14e2e(%rip), %rdi     # 0x2bff0
leaq 0xc9f0(%rip), %rsi      # 0x23bb9
callq 0x4310
movq %rax, -0xc8(%rbp)
jmp 0x171d7
movq -0x60(%rbp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movq -0xc8(%rbp), %rdi
movq %rax, %rsi
callq 0x4310
movq %rax, -0xd0(%rbp)
jmp 0x171fc
movq -0xd0(%rbp), %rdi
movq 0x14da6(%rip), %rsi     # 0x2bfb0
callq 0x4350
jmp 0x17211
movl $0x4, %edi
callq 0x4400
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
callq 0x4580
jmp 0x1722e
jmp 0x17314
jmp 0x17235
movq -0x70(%rbp), %rax
movq %rax, %rdi
addq $0x8, %rdi
movq 0x8(%rax), %rax
addq -0x18(%rax), %rdi
callq 0x4440
testb $0x1, %al
jne 0x17253
jmp 0x172ca
movq -0x70(%rbp), %rdi
addq $0x8, %rdi
movq -0x58(%rbp), %rsi
movl $0xa00000, %edx         # imm = 0xA00000
callq 0x4450
movq $0x0, -0x68(%rbp)
movq -0x70(%rbp), %rdi
movq -0x68(%rbp), %rax
movq %rax, -0xd8(%rbp)
addq $0x8, %rdi
callq 0x46c0
movq %rax, %rcx
movq -0xd8(%rbp), %rax
cmpq %rcx, %rax
jae 0x172c5
movq -0x58(%rbp), %rax
movq -0x68(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0xa, %eax
jne 0x172b5
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0x172b7
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
jmp 0x17271
jmp 0x17235
movq -0x70(%rbp), %rdi
addq $0x8, %rdi
callq 0x4060
movq -0x58(%rbp), %rax
movq %rax, -0xe0(%rbp)
cmpq $0x0, %rax
je 0x172f4
movq -0xe0(%rbp), %rdi
callq 0x4480
movq -0x70(%rbp), %rcx
movq -0x10(%rbp), %rax
movb 0x238(%rcx), %cl
andb $0x1, %cl
movzbl %cl, %ecx
subq %rcx, %rax
addq $0xe0, %rsp
popq %rbp
retq
movq -0x18(%rbp), %rdi
callq 0x4610
movq %rax, %rdi
callq 0x82c0
nopw %cs:(%rax,%rax)