// File: /workspace/github_cpp_makefile_star2_O1/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
movq %rcx, 0x30(%rsp)
cmpq $0x0, (%rsi)
je 0x11bdf
movq %r8, %rbx
movq %rdx, %r14
movq %rsi, %rbp
movq %rdi, %r13
movq 0x8(%r8), %rax
cmpq (%r8), %rax
je 0x11b37
movq %rbx, %rdi
xorl %esi, %esi
callq 0x16a82
movq (%r13), %rax
movq %r13, %rdi
callq *0x10(%rax)
movq %rax, 0x8(%rsp)
leaq 0x8(%r13), %rdi
movq 0x218(%r13), %rsi
movq %rdi, (%rsp)
movl $0x8, %edx
callq 0x4270
leaq 0x88(%r13), %rdi
callq 0x40a0
testb %al, %al
je 0x1218f
movq 0x8(%rsp), %r12
cmpq (%rbp), %r12
jae 0x11c32
movq 0xe467(%rip), %rbx      # 0x1fff0
leaq 0x6a66(%rip), %rsi      # 0x185f6
movl $0x1d, %edx
movq %rbx, %rdi
callq 0x42f0
movq (%rbp), %rsi
movq %rbx, %rdi
callq 0x41a0
movq %rax, %rbx
leaq 0x6a61(%rip), %rsi      # 0x18614
movl $0x2f, %edx
movq %rax, %rdi
callq 0x42f0
movq %rbx, %rdi
movq %r12, %rsi
callq 0x41a0
movq %rax, %rbx
leaq 0x6a6f(%rip), %rsi      # 0x18644
movl $0x14, %edx
movq %rax, %rdi
jmp 0x11bf5
movq 0xe40a(%rip), %rbx      # 0x1fff0
leaq 0x7020(%rip), %rsi      # 0x18c0d
movl $0x31, %edx
movq %rbx, %rdi
callq 0x42f0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4290
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x41b0
jne 0x11d09
movq 0xe3b1(%rip), %r15      # 0x1fff0
leaq 0x6a13(%rip), %rsi      # 0x18659
movl $0x16, %edx
movq %r15, %rdi
callq 0x42f0
movq (%rbp), %rsi
movq %r15, %rdi
callq 0x41a0
movq %rax, %r15
leaq 0x6a07(%rip), %rsi      # 0x18670
movl $0x22, %edx
movq %rax, %rdi
callq 0x42f0
movq %r15, %rdi
movq 0x8(%rsp), %rsi
callq 0x41a0
movq %rax, %r15
leaq 0x6a06(%rip), %rsi      # 0x18693
movl $0x2d, %edx
movq %rax, %rdi
callq 0x42f0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x4290
movsbl %al, %esi
movq %r15, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41b0
leaq 0x48(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
cmpb $0x1, 0x238(%r13)
jne 0x11ea1
cmpb $0x1, (%r14)
movq (%rsp), %rcx
jne 0x11d5e
movabsq $0x7fffffffffffffff, %rsi # imm = 0x7FFFFFFFFFFFFFFF
movq %rcx, %rdi
movl $0xa, %edx
callq 0x4190
jmp 0x11ea1
leaq 0x48(%rsp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x20(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
cmpb $0x1, 0x238(%r13)
jne 0x11fe0
cmpb $0x1, (%r14)
jne 0x11dee
movabsq $0x7fffffffffffffff, %rsi # imm = 0x7FFFFFFFFFFFFFFF
movq (%rsp), %rdi
movl $0xa, %edx
callq 0x4190
jmp 0x11fe0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x4290
movsbl %al, %edx
leaq 0x38(%rsp), %rsi
movq (%rsp), %rdi
callq 0x4500
leaq 0x20(%rsp), %r13
movq %r13, -0x10(%r13)
movq $0x0, -0x8(%r13)
movb $0x0, (%r13)
leaq 0x70(%rsp), %rdi
leaq 0x38(%rsp), %rsi
movl $0x18, %edx
callq 0x4460
leaq 0x70(%rsp), %r15
leaq 0x10(%rsp), %r12
movq 0x70(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x90(%rsp,%rax)
jne 0x11e6c
movq 0x30(%rsp), %rax
movsbl (%rax), %edx
movq %r15, %rdi
movq %r12, %rsi
callq 0x4500
movq %rbx, %rdi
movq %r12, %rsi
callq 0x16ab2
jmp 0x11db7
movq (%rsp), %rcx
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x4290
movsbl %al, %edx
leaq 0x38(%rsp), %rsi
movq (%rsp), %rdi
callq 0x4500
leaq 0x70(%rsp), %rdi
leaq 0x38(%rsp), %rsi
movl $0x18, %edx
callq 0x4460
leaq 0x70(%rsp), %r15
leaq 0x10(%rsp), %r12
movq 0x70(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x90(%rsp,%rax)
jne 0x11fc2
movq 0x30(%rsp), %rax
movsbl (%rax), %edx
movq %r15, %rdi
movq %r12, %rsi
callq 0x4500
movq %rbx, %rdi
movq %r12, %rsi
callq 0x16ab2
jmp 0x11e35
movq 0xe13d(%rip), %rsi      # 0x1ffb0
leaq 0x70(%rsp), %rdi
callq 0x4200
leaq 0xf0(%rsp), %rdi
callq 0x40f0
movq 0x10(%rsp), %rdi
cmpq %r13, %rdi
je 0x11ea1
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x42d0
leaq 0x20(%rsp), %r15
movq %r15, -0x10(%r15)
movq $0x0, -0x8(%r15)
movb $0x0, (%r15)
movq (%rsp), %rcx
movq (%rcx), %rax
movq -0x18(%rax), %rdi
testb $0x5, 0x20(%rcx,%rdi)
jne 0x11f74
addq (%rsp), %rdi
leaq 0xf0(%rsp), %r14
leaq 0x38(%rsp), %r13
leaq 0x70(%rsp), %rbp
leaq 0x10(%rsp), %r12
movl $0xa, %esi
callq 0x4290
movsbl %al, %edx
movq (%rsp), %rdi
movq %r13, %rsi
callq 0x4500
movq %rbp, %rdi
movq %r13, %rsi
movl $0x18, %edx
callq 0x4460
movq 0x70(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x90(%rsp,%rax)
jne 0x11f43
movq 0x30(%rsp), %rax
movsbl (%rax), %edx
movq %rbp, %rdi
movq %r12, %rsi
callq 0x4500
movq %rbx, %rdi
movq %r12, %rsi
callq 0x16ab2
jmp 0x11f10
movq %rbp, %rdi
movq 0xe063(%rip), %rsi      # 0x1ffb0
callq 0x4200
movq %r14, %rdi
callq 0x40f0
movq (%rsp), %rcx
movq (%rcx), %rax
movq -0x18(%rax), %rax
leaq (%rcx,%rax), %rdi
testb $0x5, 0x20(%rcx,%rax)
je 0x11ee7
movq (%rsp), %rdi
callq 0x4060
movq 0x10(%rsp), %rdi
cmpq %r15, %rdi
je 0x11f94
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x42d0
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x11fb0
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x42d0
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xdfe7(%rip), %rsi      # 0x1ffb0
leaq 0x70(%rsp), %rdi
callq 0x4200
leaq 0xf0(%rsp), %rdi
callq 0x40f0
movq (%rbp), %r13
movl $0x8, %edi
callq 0x42c0
movq %rax, 0x58(%rsp)
movq %rax, %rdi
callq 0x174a0
movq 0x8(%rsp), %r12
testq %r13, %r13
je 0x1214e
movq %r13, %rax
leaq 0x70(%rsp), %rbp
leaq 0x10(%rsp), %r13
movq (%rsp), %r14
movq %rax, 0x60(%rsp)
movq %rax, %xmm0
movq 0x6474(%rip), %xmm2     # 0x184a0
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
movapd 0x6478(%rip), %xmm3     # 0x184b0
subpd %xmm3, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movsd %xmm1, 0x70(%rsp)
movq %r12, 0x8(%rsp)
movq %r12, %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 0x58(%rsp), %rdi
movq %rbp, %rsi
leaq 0x68(%rsp), %rdx
callq 0x177c4
movq %rax, %r12
movq %rax, %r15
testq %rax, %rax
je 0x120ac
movq (%rsp), %rdi
movabsq $0x7fffffffffffffff, %rsi # imm = 0x7FFFFFFFFFFFFFFF
movl $0xa, %edx
callq 0x4190
decq %r15
jne 0x1208f
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x4290
leaq 0x38(%rsp), %r15
movsbl %al, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x4500
movq %rbp, %rdi
movq %r15, %rsi
movl $0x18, %edx
callq 0x4460
notq %r12
movq 0x8(%rsp), %rax
addq %r12, %rax
movq %rax, %r12
movq 0x70(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x90(%rsp,%rax)
jne 0x12124
movq 0x30(%rsp), %rax
movsbl (%rax), %edx
movq %rbp, %rdi
movq %r13, %rsi
callq 0x4500
movq %rbx, %rdi
movq %r13, %rsi
callq 0x16ab2
jmp 0x120f1
movq %rbp, %rdi
movq 0xde82(%rip), %rsi      # 0x1ffb0
callq 0x4200
leaq 0xf0(%rsp), %rdi
callq 0x40f0
movq 0x60(%rsp), %rax
decq %rax
jne 0x1201a
movq (%rsp), %rdi
callq 0x4060
movq 0x58(%rsp), %rbx
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x1216a
movq (%rdi), %rax
callq *0x8(%rax)
movl $0x8, %esi
movq %rbx, %rdi
callq 0x42d0
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
jne 0x11f87
jmp 0x11f94
movq 0xde5a(%rip), %rdi      # 0x1fff0
leaq 0x63b3(%rip), %rsi      # 0x18550
movl $0x1b, %edx
callq 0x42f0
movq 0x218(%r13), %rsi
movq 0x220(%r13), %rdx
movq 0xde34(%rip), %rdi      # 0x1fff0
callq 0x42f0
movq %rax, %rbx
leaq 0x63a1(%rip), %rsi      # 0x1856c
movl $0xa, %edx
movq %rax, %rdi
callq 0x42f0
movq %rbx, %rdi
callq 0x4130
movl $0x2, %edi
callq 0x4320
jmp 0x12484
movq %rax, %rbx
jmp 0x123bd
jmp 0x12484
movq %rax, %rbx
jmp 0x124f3
jmp 0x12484
jmp 0x1247d
movq %rdx, %r14
movq %rax, %rbx
movl $0x8, %esi
movq 0x58(%rsp), %rdi
callq 0x42d0
jmp 0x1222b
movq %rdx, %r14
movq %rax, %rbx
cmpl $0x2, %r14d
jne 0x124d7
movq %rbx, %rdi
callq 0x4340
leaq 0x80(%rsp), %r14
movq %r14, -0x10(%r14)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0x70(%rsp), %rdi
callq 0x7720
movq %rbx, %rdi
callq 0x4110
movq 0xdd84(%rip), %rdi      # 0x1fff0
leaq 0x64b2(%rip), %rsi      # 0x18725
movl $0x7, %edx
callq 0x42f0
movq 0x70(%rsp), %rsi
movq 0x78(%rsp), %rdx
movq 0xdd62(%rip), %rdi      # 0x1fff0
callq 0x42f0
movq %rax, %rdi
callq 0x4130
jmp 0x12447
movq %rax, %rbx
movq 0x70(%rsp), %rdi
cmpq %r14, %rdi
je 0x122bd
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x42d0
callq 0x4480
jmp 0x124d7
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x1250f
movq %rbx, %rdi
callq 0x4110
movq %rax, %rbx
movq 0xdd0b(%rip), %rdi      # 0x1fff0
leaq 0x68c7(%rip), %rsi      # 0x18bb3
movl $0x1d, %edx
callq 0x42f0
movq 0x218(%r13), %rsi
movq 0x220(%r13), %rdx
movq 0xdce5(%rip), %rdi      # 0x1fff0
callq 0x42f0
movq %rax, %r14
leaq 0x66e3(%rip), %rsi      # 0x189fd
movl $0xc, %edx
movq %rax, %rdi
callq 0x42f0
movq 0x18(%rbx), %rsi
movl 0x10(%rbx), %edx
movq (%rsi), %rax
leaq 0x70(%rsp), %rdi
callq *0x20(%rax)
movq 0x70(%rsp), %rsi
movq 0x78(%rsp), %rdx
movq %r14, %rdi
callq 0x42f0
movq %rax, %rdi
callq 0x41b0
leaq 0x70(%rsp), %rdi
callq 0x48ff
movq %rax, %rbx
leaq 0x80(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x12388
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x42d0
jmp 0x12388
jmp 0x12385
movq %rax, %rbx
callq 0x4480
jmp 0x1250f
jmp 0x1247d
jmp 0x124b6
movq %rax, %rbx
movq 0xdc0a(%rip), %rsi      # 0x1ffb0
leaq 0x70(%rsp), %rdi
callq 0x4200
leaq 0xf0(%rsp), %rdi
callq 0x40f0
movq 0x10(%rsp), %rdi
cmpq %r13, %rdi
jne 0x124e6
jmp 0x124f3
jmp 0x12484
movq %rax, %rbx
cmpl $0x2, %edx
jne 0x124d7
movq %rbx, %rdi
callq 0x4340
leaq 0x80(%rsp), %r14
movq %r14, -0x10(%r14)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0x70(%rsp), %rdi
callq 0x7720
movq %rbx, %rdi
callq 0x4110
movq 0xdbd8(%rip), %rdi      # 0x1fff0
leaq 0x6306(%rip), %rsi      # 0x18725
movl $0x7, %edx
callq 0x42f0
movq 0x70(%rsp), %rsi
movq 0x78(%rsp), %rdx
movq 0xdbb6(%rip), %rdi      # 0x1fff0
callq 0x42f0
movq %rax, %rdi
callq 0x4130
movl $0x5, %edi
callq 0x4320
movq %rax, %rbx
movq 0x70(%rsp), %rdi
cmpq %r14, %rdi
je 0x1246e
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x42d0
callq 0x4480
jmp 0x124d7
movq %rax, %rdi
callq 0x7714
movq %rax, %rbx
jmp 0x124aa
jmp 0x12484
movq %rax, %rbx
jmp 0x124d7
movq %rax, %rbx
movq 0xdb1d(%rip), %rsi      # 0x1ffb0
leaq 0x70(%rsp), %rdi
callq 0x4200
leaq 0xf0(%rsp), %rdi
callq 0x40f0
movq 0x10(%rsp), %rdi
cmpq %r15, %rdi
jne 0x124e6
jmp 0x124f3
movq %rax, %rbx
movq 0xdaf0(%rip), %rsi      # 0x1ffb0
leaq 0x70(%rsp), %rdi
callq 0x4200
leaq 0xf0(%rsp), %rdi
callq 0x40f0
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x124f3
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x42d0
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x1250f
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x42d0
movq %rbx, %rdi
callq 0x44e0
nop