// File: /workspace/github_cpp_makefile_star2_O3/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 0x11a4d
movq %r8, %rbx
movq %rdx, %r14
movq %rsi, %rbp
movq %rdi, %r13
movq 0x8(%r8), %rax
cmpq (%r8), %rax
je 0x119a5
movq %rbx, %rdi
xorl %esi, %esi
callq 0x168dc
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 0x11ffd
movq 0x8(%rsp), %r12
cmpq (%rbp), %r12
jae 0x11aa0
movq 0xe5f9(%rip), %rbx      # 0x1fff0
leaq 0x6bf8(%rip), %rsi      # 0x185f6
movl $0x1d, %edx
movq %rbx, %rdi
callq 0x42f0
movq (%rbp), %rsi
movq %rbx, %rdi
callq 0x41a0
movq %rax, %rbx
leaq 0x6bf3(%rip), %rsi      # 0x18614
movl $0x2f, %edx
movq %rax, %rdi
callq 0x42f0
movq %rbx, %rdi
movq %r12, %rsi
callq 0x41a0
movq %rax, %rbx
leaq 0x6c01(%rip), %rsi      # 0x18644
movl $0x14, %edx
movq %rax, %rdi
jmp 0x11a63
movq 0xe59c(%rip), %rbx      # 0x1fff0
leaq 0x71b2(%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 0x11b77
movq 0xe543(%rip), %r15      # 0x1fff0
leaq 0x6ba5(%rip), %rsi      # 0x18659
movl $0x16, %edx
movq %r15, %rdi
callq 0x42f0
movq (%rbp), %rsi
movq %r15, %rdi
callq 0x41a0
movq %rax, %r15
leaq 0x6b99(%rip), %rsi      # 0x18670
movl $0x22, %edx
movq %rax, %rdi
callq 0x42f0
movq %r15, %rdi
movq 0x8(%rsp), %rsi
callq 0x41a0
movq %rax, %r15
leaq 0x6b98(%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 0x11d0f
cmpb $0x1, (%r14)
movq (%rsp), %rcx
jne 0x11bcc
movabsq $0x7fffffffffffffff, %rsi # imm = 0x7FFFFFFFFFFFFFFF
movq %rcx, %rdi
movl $0xa, %edx
callq 0x4190
jmp 0x11d0f
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 0x11e4e
cmpb $0x1, (%r14)
jne 0x11c5c
movabsq $0x7fffffffffffffff, %rsi # imm = 0x7FFFFFFFFFFFFFFF
movq (%rsp), %rdi
movl $0xa, %edx
callq 0x4190
jmp 0x11e4e
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 0x11cda
movq 0x30(%rsp), %rax
movsbl (%rax), %edx
movq %r15, %rdi
movq %r12, %rsi
callq 0x4500
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1690c
jmp 0x11c25
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 0x11e30
movq 0x30(%rsp), %rax
movsbl (%rax), %edx
movq %r15, %rdi
movq %r12, %rsi
callq 0x4500
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1690c
jmp 0x11ca3
movq 0xe2cf(%rip), %rsi      # 0x1ffb0
leaq 0x70(%rsp), %rdi
callq 0x4200
leaq 0xf0(%rsp), %rdi
callq 0x40f0
movq 0x10(%rsp), %rdi
cmpq %r13, %rdi
je 0x11d0f
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 0x11de2
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 0x11db1
movq 0x30(%rsp), %rax
movsbl (%rax), %edx
movq %rbp, %rdi
movq %r12, %rsi
callq 0x4500
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1690c
jmp 0x11d7e
movq %rbp, %rdi
movq 0xe1f5(%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 0x11d55
movq (%rsp), %rdi
callq 0x4060
movq 0x10(%rsp), %rdi
cmpq %r15, %rdi
je 0x11e02
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x42d0
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x11e1e
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 0xe179(%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 0x172de
movq 0x8(%rsp), %r12
testq %r13, %r13
je 0x11fbc
movq %r13, %rax
leaq 0x70(%rsp), %rbp
leaq 0x10(%rsp), %r13
movq (%rsp), %r14
movq %rax, 0x60(%rsp)
movq %rax, %xmm0
movq 0x6606(%rip), %xmm2     # 0x184a0
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
movapd 0x660a(%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 0x175fe
movq %rax, %r12
movq %rax, %r15
testq %rax, %rax
je 0x11f1a
movq (%rsp), %rdi
movabsq $0x7fffffffffffffff, %rsi # imm = 0x7FFFFFFFFFFFFFFF
movl $0xa, %edx
callq 0x4190
decq %r15
jne 0x11efd
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 0x11f92
movq 0x30(%rsp), %rax
movsbl (%rax), %edx
movq %rbp, %rdi
movq %r13, %rsi
callq 0x4500
movq %rbx, %rdi
movq %r13, %rsi
callq 0x1690c
jmp 0x11f5f
movq %rbp, %rdi
movq 0xe014(%rip), %rsi      # 0x1ffb0
callq 0x4200
leaq 0xf0(%rsp), %rdi
callq 0x40f0
movq 0x60(%rsp), %rax
decq %rax
jne 0x11e88
movq (%rsp), %rdi
callq 0x4060
movq 0x58(%rsp), %rbx
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x11fd8
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 0x11df5
jmp 0x11e02
movq 0xdfec(%rip), %rdi      # 0x1fff0
leaq 0x6545(%rip), %rsi      # 0x18550
movl $0x1b, %edx
callq 0x42f0
movq 0x218(%r13), %rsi
movq 0x220(%r13), %rdx
movq 0xdfc6(%rip), %rdi      # 0x1fff0
callq 0x42f0
movq %rax, %rbx
leaq 0x6533(%rip), %rsi      # 0x1856c
movl $0xa, %edx
movq %rax, %rdi
callq 0x42f0
movq %rbx, %rdi
callq 0x4130
movl $0x2, %edi
callq 0x4320
jmp 0x122f2
movq %rax, %rbx
jmp 0x1222b
jmp 0x122f2
movq %rax, %rbx
jmp 0x1235c
jmp 0x122f2
jmp 0x122eb
movq %rdx, %r14
movq %rax, %rbx
movl $0x8, %esi
movq 0x58(%rsp), %rdi
callq 0x42d0
jmp 0x12099
movq %rdx, %r14
movq %rax, %rbx
cmpl $0x2, %r14d
jne 0x12340
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 0x76e4
movq %rbx, %rdi
callq 0x4110
movq 0xdf16(%rip), %rdi      # 0x1fff0
leaq 0x6644(%rip), %rsi      # 0x18725
movl $0x7, %edx
callq 0x42f0
movq 0x70(%rsp), %rsi
movq 0x78(%rsp), %rdx
movq 0xdef4(%rip), %rdi      # 0x1fff0
callq 0x42f0
movq %rax, %rdi
callq 0x4130
jmp 0x122b5
movq %rax, %rbx
movq 0x70(%rsp), %rdi
cmpq %r14, %rdi
je 0x1212b
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x42d0
callq 0x4480
jmp 0x12340
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x12378
movq %rbx, %rdi
callq 0x4110
movq %rax, %rbx
movq 0xde9d(%rip), %rdi      # 0x1fff0
leaq 0x6a59(%rip), %rsi      # 0x18bb3
movl $0x1d, %edx
callq 0x42f0
movq 0x218(%r13), %rsi
movq 0x220(%r13), %rdx
movq 0xde77(%rip), %rdi      # 0x1fff0
callq 0x42f0
movq %rax, %r14
leaq 0x6875(%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 0x121f6
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x42d0
jmp 0x121f6
jmp 0x121f3
movq %rax, %rbx
callq 0x4480
jmp 0x12378
jmp 0x122eb
jmp 0x1231f
movq %rax, %rbx
movq 0xdd9c(%rip), %rsi      # 0x1ffb0
leaq 0x70(%rsp), %rdi
callq 0x4200
leaq 0xf0(%rsp), %rdi
callq 0x40f0
movq 0x10(%rsp), %rdi
cmpq %r13, %rdi
jne 0x1234f
jmp 0x1235c
jmp 0x122f2
movq %rax, %rbx
cmpl $0x2, %edx
jne 0x12340
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 0x76e4
movq %rbx, %rdi
callq 0x4110
movq 0xdd6a(%rip), %rdi      # 0x1fff0
leaq 0x6498(%rip), %rsi      # 0x18725
movl $0x7, %edx
callq 0x42f0
movq 0x70(%rsp), %rsi
movq 0x78(%rsp), %rdx
movq 0xdd48(%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 0x122dc
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x42d0
callq 0x4480
jmp 0x12340
movq %rax, %rdi
callq 0x76d8
movq %rax, %rbx
jmp 0x12313
jmp 0x122f2
movq %rax, %rbx
jmp 0x12340
movq %rax, %rbx
movq 0xdcaf(%rip), %rsi      # 0x1ffb0
leaq 0x70(%rsp), %rdi
callq 0x4200
movq %r14, %rdi
callq 0x40f0
movq 0x10(%rsp), %rdi
cmpq %r15, %rdi
jne 0x1234f
jmp 0x1235c
movq %rax, %rbx
movq 0xdc87(%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 0x1235c
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x42d0
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x12378
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x42d0
movq %rbx, %rdi
callq 0x44e0