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

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

    }
	string trash;
	// skip header lines. Will also read the one after the last header line.
	while (1) {
		getline(_varFile, trash);
		if (trash[0] != '#') {
			break;
		}
	}

	const size_t bufSize = BUF_SIZE;
	char *buf;
	try {
		buf = new char[bufSize];
	} catch (bad_alloc& error) {
		cerr << "ERROR: failed to allocate buffer in VcfFileI::_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 + 1; // adding 1 for the line immediately after the header
}

// 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 0x1c0a1
jmp 0x1c0b1
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 0x1c0e8
movq -0x90(%rbp), %rdi
addq $0x8, %rdi
callq 0x45e0
movb %al, -0x99(%rbp)
jmp 0x1c100
movb -0x99(%rbp), %al
testb $0x1, %al
jne 0x1c274
jmp 0x1c110
movq 0xfed9(%rip), %rdi      # 0x2bff0
leaq 0x7c62(%rip), %rsi      # 0x23d80
callq 0x4310
movq %rax, -0xa8(%rbp)
jmp 0x1c12c
movq -0xa8(%rbp), %rdi
movq -0x90(%rbp), %rsi
addq $0x218, %rsi            # imm = 0x218
callq 0x42e0
movq %rax, -0xb0(%rbp)
jmp 0x1c14f
movq -0xb0(%rbp), %rdi
leaq 0x73f7(%rip), %rsi      # 0x23554
callq 0x4310
movq %rax, -0xb8(%rbp)
jmp 0x1c16b
movq -0xb8(%rbp), %rdi
movq 0xfe37(%rip), %rsi      # 0x2bfb0
callq 0x4350
jmp 0x1c180
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 0x1c4f9
movq -0x18(%rbp), %rdi
callq 0x4130
movq %rax, -0x28(%rbp)
movq 0xfe36(%rip), %rdi      # 0x2bff0
leaq 0x7be0(%rip), %rsi      # 0x23da1
callq 0x4310
movq %rax, -0xc0(%rbp)
jmp 0x1c1cf
movq -0xc0(%rbp), %rdi
movq -0x90(%rbp), %rsi
addq $0x218, %rsi            # imm = 0x218
callq 0x42e0
movq %rax, -0xc8(%rbp)
jmp 0x1c1f2
movq -0xc8(%rbp), %rdi
leaq 0x77e5(%rip), %rsi      # 0x239e5
callq 0x4310
movq %rax, -0xd0(%rbp)
jmp 0x1c20e
movq -0x28(%rbp), %rdi
callq 0x1ee90
movq %rax, %rsi
leaq -0x48(%rbp), %rdi
callq 0x1eeb0
jmp 0x1c225
movq -0xd0(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x42e0
movq %rax, -0xd8(%rbp)
jmp 0x1c23e
movq -0xd8(%rbp), %rdi
movq 0xfd7c(%rip), %rsi      # 0x2bfc8
callq 0x4350
jmp 0x1c253
leaq -0x48(%rbp), %rdi
callq 0x46d8
leaq 0x7597(%rip), %rdi      # 0x237fa
callq 0x42a0
jmp 0x1c26a
movl $0x1, %edi
callq 0x4400
jmp 0x1c2a5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x1c299
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x46d8
callq 0x4580
jmp 0x1c2a0
jmp 0x1c4f9
leaq -0x68(%rbp), %rdi
callq 0x44d0
jmp 0x1c2b0
movq -0x90(%rbp), %rdi
addq $0x8, %rdi
leaq -0x68(%rbp), %rsi
callq 0x4080
jmp 0x1c2c6
xorl %eax, %eax
movl %eax, %esi
leaq -0x68(%rbp), %rdi
callq 0x46b0
movq %rax, -0xe0(%rbp)
jmp 0x1c2dc
movq -0xe0(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x23, %eax
je 0x1c2fe
jmp 0x1c300
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x1c4f0
jmp 0x1c2ae
movq $0xa00000, -0x70(%rbp)  # imm = 0xA00000
movl $0xa00000, %edi         # imm = 0xA00000
callq 0x4030
movq %rax, -0xe8(%rbp)
jmp 0x1c31b
movq -0xe8(%rbp), %rax
movq %rax, -0x78(%rbp)
jmp 0x1c3cc
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 0x1c4f0
movq -0x18(%rbp), %rdi
callq 0x4130
movq %rax, -0x80(%rbp)
movq 0xfc95(%rip), %rdi      # 0x2bff0
leaq 0x7a5d(%rip), %rsi      # 0x23dbf
callq 0x4310
movq %rax, -0xf0(%rbp)
jmp 0x1c370
movq -0x80(%rbp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movq -0xf0(%rbp), %rdi
movq %rax, %rsi
callq 0x4310
movq %rax, -0xf8(%rbp)
jmp 0x1c395
movq -0xf8(%rbp), %rdi
movq 0xfc0d(%rip), %rsi      # 0x2bfb0
callq 0x4350
jmp 0x1c3aa
movl $0x4, %edi
callq 0x4400
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
callq 0x4580
jmp 0x1c3c7
jmp 0x1c4f0
jmp 0x1c3ce
movq -0x90(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x18(%rcx), %rcx
leaq 0x8(%rax,%rcx), %rdi
callq 0x4440
movb %al, -0xf9(%rbp)
jmp 0x1c3ef
movb -0xf9(%rbp), %al
testb $0x1, %al
jne 0x1c3fe
jmp 0x1c499
movq -0x90(%rbp), %rdi
addq $0x8, %rdi
movq -0x78(%rbp), %rsi
movl $0xa00000, %edx         # imm = 0xA00000
callq 0x4450
jmp 0x1c419
movq $0x0, -0x88(%rbp)
movq -0x90(%rbp), %rdi
movq -0x88(%rbp), %rax
movq %rax, -0x110(%rbp)
addq $0x8, %rdi
callq 0x46c0
movq %rax, -0x108(%rbp)
jmp 0x1c44b
movq -0x110(%rbp), %rax
movq -0x108(%rbp), %rcx
cmpq %rcx, %rax
jae 0x1c494
movq -0x78(%rbp), %rax
movq -0x88(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0xa, %eax
jne 0x1c47e
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0x1c480
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0x1c424
jmp 0x1c3ce
movq -0x90(%rbp), %rdi
addq $0x8, %rdi
callq 0x4060
jmp 0x1c4ab
movq -0x78(%rbp), %rax
movq %rax, -0x118(%rbp)
cmpq $0x0, %rax
je 0x1c4c8
movq -0x118(%rbp), %rdi
callq 0x4480
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x120(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x46d8
movq -0x120(%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
nopw (%rax,%rax)