// File: 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 %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 0x19d9e
jmp 0x19dab
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 0x19dd9
movq -0x70(%rbp), %rdi
addq $0x8, %rdi
callq 0x45e0
movb %al, -0x79(%rbp)
jmp 0x19deb
movb -0x79(%rbp), %al
testb $0x1, %al
jne 0x19f56
jmp 0x19df8
movq 0x121f1(%rip), %rdi     # 0x2bff0
leaq 0x9f1b(%rip), %rsi      # 0x23d21
callq 0x4310
movq %rax, -0x88(%rbp)
jmp 0x19e14
movq -0x88(%rbp), %rdi
movq -0x70(%rbp), %rsi
addq $0x218, %rsi            # imm = 0x218
callq 0x42e0
movq %rax, -0x90(%rbp)
jmp 0x19e34
movq -0x90(%rbp), %rdi
leaq 0x9712(%rip), %rsi      # 0x23554
callq 0x4310
movq %rax, -0x98(%rbp)
jmp 0x19e50
movq -0x98(%rbp), %rdi
movq 0x12152(%rip), %rsi     # 0x2bfb0
callq 0x4350
jmp 0x19e65
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 0x1a121
movq -0x18(%rbp), %rdi
callq 0x4130
movq %rax, -0x28(%rbp)
movq 0x12151(%rip), %rdi     # 0x2bff0
leaq 0x9e9d(%rip), %rsi      # 0x23d43
callq 0x4310
movq %rax, -0xa0(%rbp)
jmp 0x19eb4
movq -0xa0(%rbp), %rdi
movq -0x70(%rbp), %rsi
addq $0x218, %rsi            # imm = 0x218
callq 0x42e0
movq %rax, -0xa8(%rbp)
jmp 0x19ed4
movq -0xa8(%rbp), %rdi
leaq 0x9b03(%rip), %rsi      # 0x239e5
callq 0x4310
movq %rax, -0xb0(%rbp)
jmp 0x19ef0
movq -0x28(%rbp), %rdi
callq 0x1ee90
movq %rax, %rsi
leaq -0x48(%rbp), %rdi
callq 0x1eeb0
jmp 0x19f07
movq -0xb0(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x42e0
movq %rax, -0xb8(%rbp)
jmp 0x19f20
movq -0xb8(%rbp), %rdi
movq 0x1209a(%rip), %rsi     # 0x2bfc8
callq 0x4350
jmp 0x19f35
leaq -0x48(%rbp), %rdi
callq 0x46d8
leaq 0x98b5(%rip), %rdi      # 0x237fa
callq 0x42a0
jmp 0x19f4c
movl $0x1, %edi
callq 0x4400
jmp 0x19f87
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x19f7b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x46d8
callq 0x4580
jmp 0x19f82
jmp 0x1a121
movq $0xa00000, -0x50(%rbp)  # imm = 0xA00000
movl $0xa00000, %edi         # imm = 0xA00000
callq 0x4030
movq %rax, -0xc0(%rbp)
jmp 0x19fa2
movq -0xc0(%rbp), %rax
movq %rax, -0x58(%rbp)
jmp 0x1a053
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 0x1a121
movq -0x18(%rbp), %rdi
callq 0x4130
movq %rax, -0x60(%rbp)
movq 0x1200e(%rip), %rdi     # 0x2bff0
leaq 0x9c85(%rip), %rsi      # 0x23c6e
callq 0x4310
movq %rax, -0xc8(%rbp)
jmp 0x19ff7
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 0x1a01c
movq -0xd0(%rbp), %rdi
movq 0x11f86(%rip), %rsi     # 0x2bfb0
callq 0x4350
jmp 0x1a031
movl $0x4, %edi
callq 0x4400
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
callq 0x4580
jmp 0x1a04e
jmp 0x1a121
jmp 0x1a055
movq -0x70(%rbp), %rax
movq %rax, %rdi
addq $0x8, %rdi
movq 0x8(%rax), %rax
addq -0x18(%rax), %rdi
callq 0x4440
testb $0x1, %al
jne 0x1a073
jmp 0x1a0ea
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 0x1a0e5
movq -0x58(%rbp), %rax
movq -0x68(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0xa, %eax
jne 0x1a0d5
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0x1a0d7
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
jmp 0x1a091
jmp 0x1a055
movq -0x70(%rbp), %rdi
addq $0x8, %rdi
callq 0x4060
movq -0x58(%rbp), %rax
movq %rax, -0xe0(%rbp)
cmpq $0x0, %rax
je 0x1a114
movq -0xe0(%rbp), %rdi
callq 0x4480
movq -0x10(%rbp), %rax
addq $0xe0, %rsp
popq %rbp
retq
movq -0x18(%rbp), %rdi
callq 0x4610
movq %rax, %rdi
callq 0x82c0
nopw %cs:(%rax,%rax)