// File: /workspace/github_cpp_makefile_star2_O2/tonymugen[P]sampleSNPs/varfiles.cpp
// Function: sampFiles::GtxtFileI::sample(unsigned long const&, bool const&, char const&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>&)
void GtxtFileI::sample(const uint64_t &n, const bool &headSkip, const char &delim, vector<string> &out){
    if (n == 0) {
        cerr << "WARNING: zero rows requested. Nothing to be done." << endl;
        return;
    }
    if (out.size()) {
        out.resize(0);
    }

    uint64_t N = _numLines(); // Number of rows

    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);
    }

    // Test for potential problems
    if (N < n) {
        cerr << "ERROR: requested a sample of " << n << " rows that is greater than the number of rows (" << N << ") in the input file." << endl;
        return;
    } else if (N == n) {
        cerr << "WARNING: sample size (" << n << ") the same as the number of rows (" << N << ") in the input file. Simply copying the file." << endl;
        string curLine;
        if (_head) {
            if (headSkip) {
                _varFile.ignore(numeric_limits<streamsize>::max(), '\n');
            } else {
                getline(_varFile, curLine);
                string field;
                stringstream lineSS(curLine);
                while (lineSS) {
                    getline(lineSS, field, delim);
                    out.push_back(field);

                }
            }
        }

        // Copy the file
        string field;
        while (_varFile) {
            getline(_varFile, curLine);
            stringstream lineSS(curLine);
            while (lineSS) {
                getline(lineSS, field, delim);
                out.push_back(field);
            }
        }
        _varFile.close();
        return;
    }

    // Passed all the tests, proceed to sampling
    string curLine;
    string field;
    if (_head) {
        if (headSkip) {
            _varFile.ignore(numeric_limits<streamsize>::max(), '\n');
        } else {
            getline(_varFile, curLine);
            stringstream lineSS(curLine);
            while (lineSS) {
                getline(lineSS, field, delim);
                out.push_back(field);

            }
        }
    }

    uint64_t nloc = n; // local copy of n
    uint64_t S;
    RanDraw *snpSamp;  // so that I can catch RanDraw constructor exceptions
    try {
        snpSamp = new RanDraw();
    } catch (string error) {
        cerr << "ERROR: " << error << endl;
        exit(5);
    }
    while (nloc) {
        try {
            S = snpSamp->vitter(nloc, N); // sample the number of SNPs to skip
        } catch (string error) {
            cerr << "ERROR: " << error << endl;
            exit(5);
        }
        N -= S + 1;
        while (S) { // skipping S lines in the HMP file
            _varFile.ignore(numeric_limits<streamsize>::max(), '\n');
            S--;
        }
        getline(_varFile, curLine);
        stringstream lineSS(curLine);
        while (lineSS) {
            getline(lineSS, field, delim);
            out.push_back(field);

        }
        nloc--;

    }
    _varFile.close();
    delete snpSamp;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1f8, %rsp            # imm = 0x1F8
cmpq $0x0, (%rsi)
je 0xe47f
movq %r8, %rbx
movq %rcx, %r14
movq %rdx, %r15
movq %rsi, %rbp
movq %rdi, %r13
movq 0x8(%r8), %rax
cmpq (%r8), %rax
je 0xe3ed
movq %rbx, %rdi
xorl %esi, %esi
callq 0x12166
movq (%r13), %rax
movq %r13, %rdi
callq *0x10(%rax)
movq %rax, 0x18(%rsp)
leaq 0x8(%r13), %rdi
leaq 0x218(%r13), %r12
movq 0x218(%r13), %rsi
pushq $0x8
popq %rdx
movq %rdi, 0x8(%rsp)
callq 0x4280
leaq 0x88(%r13), %rdi
callq 0x40b0
testb %al, %al
je 0xe88b
movq 0x18(%rsp), %r12
cmpq (%rbp), %r12
jae 0xe4ab
movq 0xdbaf(%rip), %rdi      # 0x1bff0
leaq 0x61ae(%rip), %rsi      # 0x145f6
callq 0x42a0
movq (%rbp), %rsi
movq %rax, %rdi
callq 0x41b0
leaq 0x61b4(%rip), %rsi      # 0x14614
movq %rax, %rdi
callq 0x42a0
movq %rax, %rdi
movq %r12, %rsi
callq 0x41b0
leaq 0x61ca(%rip), %rsi      # 0x14644
movq %rax, %rdi
jmp 0xe48d
movq 0xdb6a(%rip), %rdi      # 0x1bff0
leaq 0x6780(%rip), %rsi      # 0x14c0d
callq 0x42a0
movq %rax, %rdi
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4140
jne 0xe542
movq 0xdb38(%rip), %rdi      # 0x1bff0
leaq 0x619a(%rip), %rsi      # 0x14659
callq 0x42a0
movq (%rbp), %rsi
movq %rax, %rdi
callq 0x41b0
leaq 0x6199(%rip), %rsi      # 0x14670
movq %rax, %rdi
callq 0x42a0
movq %rax, %rdi
movq %r12, %rsi
callq 0x41b0
leaq 0x61a2(%rip), %rsi      # 0x14693
movq %rax, %rdi
callq 0x42a0
movq %rax, %rdi
callq 0x4140
leaq 0x50(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
cmpb $0x1, 0x238(%r13)
jne 0xe675
cmpb $0x1, (%r15)
jne 0xe598
movabsq $0x7fffffffffffffff, %rsi # imm = 0x7FFFFFFFFFFFFFFF
pushq $0xa
popq %rdx
movq 0x8(%rsp), %rdi
callq 0x41a0
jmp 0xe675
leaq 0x50(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
leaq 0x30(%rsp), %rdx
movq %rdx, -0x10(%rdx)
andq $0x0, -0x8(%rdx)
movb %cl, (%rax)
movb %cl, (%rdx)
cmpb $0x1, 0x238(%r13)
jne 0xe712
cmpb $0x1, (%r15)
jne 0xe603
movabsq $0x7fffffffffffffff, %rsi # imm = 0x7FFFFFFFFFFFFFFF
pushq $0xa
popq %rdx
movq 0x8(%rsp), %rdi
callq 0x41a0
jmp 0xe712
leaq 0x40(%rsp), %rsi
movq 0x8(%rsp), %rdi
callq 0x4060
leaq 0x30(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x70(%rsp), %rdi
leaq 0x40(%rsp), %rsi
pushq $0x18
popq %rdx
callq 0x4440
leaq 0x70(%rsp), %r15
leaq 0x20(%rsp), %r12
movq 0x70(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x90(%rsp,%rax)
jne 0xe661
movsbl (%r14), %edx
movq %r15, %rdi
movq %r12, %rsi
callq 0x44f0
movq %rbx, %rdi
movq %r12, %rsi
callq 0x12196
jmp 0xe5d4
leaq 0x40(%rsp), %rsi
movq 0x8(%rsp), %rdi
callq 0x4060
leaq 0x70(%rsp), %rdi
leaq 0x40(%rsp), %rsi
pushq $0x18
popq %rdx
callq 0x4440
leaq 0x70(%rsp), %r15
leaq 0x20(%rsp), %r12
movq 0x70(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x90(%rsp,%rax)
jne 0xe708
movsbl (%r14), %edx
movq %r15, %rdi
movq %r12, %rsi
callq 0x44f0
movq %rbx, %rdi
movq %r12, %rsi
callq 0x12196
jmp 0xe62e
leaq 0x70(%rsp), %rdi
callq 0x4210
leaq 0x20(%rsp), %rdi
callq 0x4558
leaq 0x30(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x40(%rsp), %r15
leaq 0x70(%rsp), %r12
leaq 0x20(%rsp), %rbp
movq 0x8(%r13), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x28(%r13,%rax)
jne 0xe6f9
movq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x4060
movq %r12, %rdi
movq %r15, %rsi
pushq $0x18
popq %rdx
callq 0x4440
movq 0x70(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x90(%rsp,%rax)
jne 0xe6ef
movsbl (%r14), %edx
movq %r12, %rdi
movq %rbp, %rsi
callq 0x44f0
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x12196
jmp 0xe6c0
movq %r12, %rdi
callq 0x4210
jmp 0xe695
movq 0x8(%rsp), %rdi
callq 0x4050
jmp 0xe865
leaq 0x70(%rsp), %rdi
callq 0x4210
movq (%rbp), %r12
pushq $0x8
popq %rdi
callq 0x42c0
movq %rax, 0x10(%rsp)
movq %rax, %rdi
callq 0x12bf2
leaq 0x70(%rsp), %rbp
leaq 0x20(%rsp), %r13
movq %r12, %rax
subq $0x1, %rax
jb 0xe83d
movq %rax, 0x60(%rsp)
movq %r12, %xmm0
movq 0x5d4c(%rip), %xmm2     # 0x144a0
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
movapd 0x5d50(%rip), %xmm3     # 0x144b0
subpd %xmm3, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movsd %xmm1, 0x70(%rsp)
movq 0x18(%rsp), %r15
movq %r15, %xmm0
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
subpd %xmm3, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movsd %xmm1, 0x68(%rsp)
movq 0x10(%rsp), %rdi
movq %rbp, %rsi
leaq 0x68(%rsp), %rdx
callq 0x12edc
movq %rax, %r12
notq %rax
addq %rax, %r15
movq %r15, 0x18(%rsp)
leaq 0x40(%rsp), %r15
subq $0x1, %r12
jb 0xe7de
movq 0x8(%rsp), %rdi
movabsq $0x7fffffffffffffff, %rsi # imm = 0x7FFFFFFFFFFFFFFF
pushq $0xa
popq %rdx
callq 0x41a0
jmp 0xe7bf
movq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x4060
movq %rbp, %rdi
movq %r15, %rsi
pushq $0x18
popq %rdx
callq 0x4440
movq 0x70(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x90(%rsp,%rax)
jne 0xe828
movsbl (%r14), %edx
movq %rbp, %rdi
movq %r13, %rsi
callq 0x44f0
movq %rbx, %rdi
movq %r13, %rsi
callq 0x12196
jmp 0xe7f9
movq %rbp, %rdi
callq 0x4210
movq 0x60(%rsp), %rax
movq %rax, %r12
jmp 0xe738
movq 0x8(%rsp), %rdi
callq 0x4050
movq 0x10(%rsp), %rbx
movq (%rbx), %rdi
testq %rdi, %rdi
je 0xe85a
movq (%rdi), %rax
callq *0x8(%rax)
pushq $0x8
popq %rsi
movq %rbx, %rdi
callq 0x42d0
leaq 0x20(%rsp), %rdi
callq 0x4558
leaq 0x40(%rsp), %rdi
callq 0x4558
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xd75e(%rip), %rdi      # 0x1bff0
leaq 0x5cb7(%rip), %rsi      # 0x14550
callq 0x42a0
movq %rax, %rdi
movq %r12, %rsi
callq 0x4270
leaq 0x5cbc(%rip), %rsi      # 0x1456c
movq %rax, %rdi
callq 0x42a0
movq %rax, %rdi
callq 0x4140
pushq $0x2
jmp 0xea75
jmp 0xea9b
jmp 0xea9b
jmp 0xea9b
movq %rax, %rbx
jmp 0xeab9
jmp 0xea9b
jmp 0xea9b
movq %rdx, %r14
movq %rax, %rbx
pushq $0x8
popq %rsi
movq 0x10(%rsp), %rdi
callq 0x42d0
jmp 0xe903
movq %rdx, %r14
movq %rax, %rbx
cmpl $0x2, %r14d
jne 0xeaaf
movq %rbx, %rdi
callq 0x4330
leaq 0x70(%rsp), %rdi
movq %rax, %rsi
callq 0x43b0
movq %rbx, %rdi
callq 0x4110
movq 0xd6bf(%rip), %rdi      # 0x1bff0
leaq 0x5ded(%rip), %rsi      # 0x14725
callq 0x42a0
leaq 0x70(%rsp), %rsi
movq %rax, %rdi
callq 0x4270
movq %rax, %rdi
callq 0x4140
jmp 0xea73
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x4558
callq 0x4470
jmp 0xeaaf
movq %rax, %rbx
cmpl $0x1, %edx
jne 0xeac3
movq %rbx, %rdi
callq 0x4110
movq %rax, %rbx
movq 0xd664(%rip), %rdi      # 0x1bff0
leaq 0x6220(%rip), %rsi      # 0x14bb3
callq 0x42a0
movq %rax, %rdi
movq %r12, %rsi
callq 0x4270
leaq 0x6053(%rip), %rsi      # 0x149fd
movq %rax, %rdi
callq 0x42a0
movq %rax, %r14
movq 0x18(%rbx), %rsi
movl 0x10(%rbx), %edx
movq (%rsi), %rax
leaq 0x70(%rsp), %rdi
callq *0x20(%rax)
leaq 0x70(%rsp), %rsi
movq %r14, %rdi
callq 0x4270
movq %rax, %rdi
callq 0x41c0
leaq 0x70(%rsp), %rdi
callq 0x4558
leaq 0x5e25(%rip), %rdi      # 0x14812
callq 0x4250
pushq $0x1
jmp 0xea75
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x4558
jmp 0xea0a
jmp 0xea07
movq %rax, %rbx
callq 0x4470
jmp 0xeac3
jmp 0xeaa2
jmp 0xeaa2
jmp 0xea9b
jmp 0xea9b
movq %rax, %rbx
cmpl $0x2, %edx
jne 0xeaaf
movq %rbx, %rdi
callq 0x4330
leaq 0x70(%rsp), %rdi
movq %rax, %rsi
callq 0x43b0
movq %rbx, %rdi
callq 0x4110
movq 0xd59e(%rip), %rdi      # 0x1bff0
leaq 0x5ccc(%rip), %rsi      # 0x14725
callq 0x42a0
leaq 0x70(%rsp), %rsi
movq %rax, %rdi
callq 0x4270
movq %rax, %rdi
callq 0x4140
pushq $0x5
popq %rdi
callq 0x4310
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x4558
callq 0x4470
jmp 0xeaaf
movq %rax, %rdi
callq 0x6194
jmp 0xea9b
jmp 0xea9b
movq %rax, %rbx
jmp 0xeaaf
jmp 0xeaa2
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x4210
leaq 0x20(%rsp), %rdi
callq 0x4558
leaq 0x40(%rsp), %rdi
callq 0x4558
movq %rbx, %rdi
callq 0x44d0
nop