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

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

    }
    // skip header line if present.
    string trash;
    if (_head) {
        getline(_varFile, trash);
    }

    const size_t bufSize = BUF_SIZE;
    char *buf;
    try {
        buf = new char[bufSize];
    } catch (bad_alloc& error) {
        cerr << "ERROR: failed to allocate buffer in HmpFileI::_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 $0x120, %rsp            # imm = 0x120
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x90(%rbp)
movq $0x0, -0x10(%rbp)
addq $0x8, %rdi
callq 0x45e0
testb $0x1, %al
jne 0x1dc41
jmp 0x1dc51
movq -0x90(%rbp), %rdi
addq $0x8, %rdi
callq 0x4060
movq -0x90(%rbp), %rdi
movq %rdi, %rax
addq $0x8, %rax
movq %rax, -0x98(%rbp)
addq $0x218, %rdi            # imm = 0x218
callq 0x4140
movq -0x98(%rbp), %rdi
movq %rax, %rsi
movl $0x8, %edx
callq 0x42f0
jmp 0x1dc88
movq -0x90(%rbp), %rdi
addq $0x8, %rdi
callq 0x45e0
movb %al, -0x99(%rbp)
jmp 0x1dca0
movb -0x99(%rbp), %al
testb $0x1, %al
jne 0x1de14
jmp 0x1dcb0
movq 0xe339(%rip), %rdi      # 0x2bff0
leaq 0x6198(%rip), %rsi      # 0x23e56
callq 0x4310
movq %rax, -0xa8(%rbp)
jmp 0x1dccc
movq -0xa8(%rbp), %rdi
movq -0x90(%rbp), %rsi
addq $0x218, %rsi            # imm = 0x218
callq 0x42e0
movq %rax, -0xb0(%rbp)
jmp 0x1dcef
movq -0xb0(%rbp), %rdi
leaq 0x5857(%rip), %rsi      # 0x23554
callq 0x4310
movq %rax, -0xb8(%rbp)
jmp 0x1dd0b
movq -0xb8(%rbp), %rdi
movq 0xe297(%rip), %rsi      # 0x2bfb0
callq 0x4350
jmp 0x1dd20
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 0x1e07c
movq -0x18(%rbp), %rdi
callq 0x4130
movq %rax, -0x28(%rbp)
movq 0xe296(%rip), %rdi      # 0x2bff0
leaq 0x6115(%rip), %rsi      # 0x23e76
callq 0x4310
movq %rax, -0xc0(%rbp)
jmp 0x1dd6f
movq -0xc0(%rbp), %rdi
movq -0x90(%rbp), %rsi
addq $0x218, %rsi            # imm = 0x218
callq 0x42e0
movq %rax, -0xc8(%rbp)
jmp 0x1dd92
movq -0xc8(%rbp), %rdi
leaq 0x5c45(%rip), %rsi      # 0x239e5
callq 0x4310
movq %rax, -0xd0(%rbp)
jmp 0x1ddae
movq -0x28(%rbp), %rdi
callq 0x1ee90
movq %rax, %rsi
leaq -0x48(%rbp), %rdi
callq 0x1eeb0
jmp 0x1ddc5
movq -0xd0(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x42e0
movq %rax, -0xd8(%rbp)
jmp 0x1ddde
movq -0xd8(%rbp), %rdi
movq 0xe1dc(%rip), %rsi      # 0x2bfc8
callq 0x4350
jmp 0x1ddf3
leaq -0x48(%rbp), %rdi
callq 0x46d8
leaq 0x59f7(%rip), %rdi      # 0x237fa
callq 0x42a0
jmp 0x1de0a
movl $0x1, %edi
callq 0x4400
jmp 0x1de45
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x1de39
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x46d8
callq 0x4580
jmp 0x1de40
jmp 0x1e07c
leaq -0x68(%rbp), %rdi
callq 0x44d0
movq -0x90(%rbp), %rax
testb $0x1, 0x238(%rax)
je 0x1de87
movq -0x90(%rbp), %rdi
addq $0x8, %rdi
leaq -0x68(%rbp), %rsi
callq 0x4080
jmp 0x1de74
jmp 0x1de87
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x1e073
movq $0xa00000, -0x70(%rbp)  # imm = 0xA00000
movl $0xa00000, %edi         # imm = 0xA00000
callq 0x4030
movq %rax, -0xe0(%rbp)
jmp 0x1dea2
movq -0xe0(%rbp), %rax
movq %rax, -0x78(%rbp)
jmp 0x1df53
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 0x1e073
movq -0x18(%rbp), %rdi
callq 0x4130
movq %rax, -0x80(%rbp)
movq 0xe10e(%rip), %rdi      # 0x2bff0
leaq 0x5faa(%rip), %rsi      # 0x23e93
callq 0x4310
movq %rax, -0xe8(%rbp)
jmp 0x1def7
movq -0x80(%rbp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movq -0xe8(%rbp), %rdi
movq %rax, %rsi
callq 0x4310
movq %rax, -0xf0(%rbp)
jmp 0x1df1c
movq -0xf0(%rbp), %rdi
movq 0xe086(%rip), %rsi      # 0x2bfb0
callq 0x4350
jmp 0x1df31
movl $0x4, %edi
callq 0x4400
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
callq 0x4580
jmp 0x1df4e
jmp 0x1e073
jmp 0x1df55
movq -0x90(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x18(%rcx), %rcx
leaq 0x8(%rax,%rcx), %rdi
callq 0x4440
movb %al, -0xf1(%rbp)
jmp 0x1df76
movb -0xf1(%rbp), %al
testb $0x1, %al
jne 0x1df85
jmp 0x1e020
movq -0x90(%rbp), %rdi
addq $0x8, %rdi
movq -0x78(%rbp), %rsi
movl $0xa00000, %edx         # imm = 0xA00000
callq 0x4450
jmp 0x1dfa0
movq $0x0, -0x88(%rbp)
movq -0x90(%rbp), %rdi
movq -0x88(%rbp), %rax
movq %rax, -0x108(%rbp)
addq $0x8, %rdi
callq 0x46c0
movq %rax, -0x100(%rbp)
jmp 0x1dfd2
movq -0x108(%rbp), %rax
movq -0x100(%rbp), %rcx
cmpq %rcx, %rax
jae 0x1e01b
movq -0x78(%rbp), %rax
movq -0x88(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0xa, %eax
jne 0x1e005
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0x1e007
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0x1dfab
jmp 0x1df55
movq -0x90(%rbp), %rdi
addq $0x8, %rdi
callq 0x4060
jmp 0x1e032
movq -0x78(%rbp), %rax
movq %rax, -0x110(%rbp)
cmpq $0x0, %rax
je 0x1e04f
movq -0x110(%rbp), %rdi
callq 0x4480
movq -0x10(%rbp), %rax
movq %rax, -0x118(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x46d8
movq -0x118(%rbp), %rax
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
leaq -0x68(%rbp), %rdi
callq 0x46d8
movq -0x18(%rbp), %rdi
callq 0x4610
movq %rax, %rdi
callq 0x82c0
nopl (%rax)