// File: /workspace/github_cpp_makefile_star2_O2/j-faria[P]cpp-loadtxt/./src/loadtxt.hpp
// Function: loadtxt<double>::operator()()
vector<vector<T>> operator()()
    {
        if (_fname.empty()) {
            string msg = "loadtxt: filename is empty";
            throw invalid_argument(msg);
        }

        ifstream infile( _fname );

        if (infile.fail()) {
            string msg = "loadtxt: could not read file (" + _fname + ")!";
            throw runtime_error(msg);
        }
        
        // ignore first `skiprows` lines
        static const int max_line = 65536;
        for (size_t i = 0; i < _skiprows; i++)
            infile.ignore(max_line, '\n');

        vector<T> record;
        size_t rows_read = 0;

        // read each line
        while (rows_read < _max_rows || _max_rows == 0)
        {
            // clear the record before reading
            record.clear();

            // read the entire line into a string (a record is terminated by a newline)
            string line;
            getline(infile, line);

            if (infile.eof() && line.empty())
                break;
            
            if (line.find(_comments, 0) == 0)
                continue;

            // // use a stringstream to separate the fields out of the line
            // stringstream ss(line);

            size_t found = line.find_first_of(_delimiters);

            while (found != string::npos) {
                string cell = line.substr(0, found);

                if (!cell.empty()) {
                    // convert the field to a double
                    try
                    {
                        T val = convert(cell);
                        record.push_back(val);
                    }
                    catch(const std::invalid_argument& e)
                    {
                        std::cerr << "loadtxt: while reading file \"" << _fname << "\", ";
                        std::cerr << "could not convert field '" << cell << "' to double ";
                        std::cerr << "at row " << rows_read << " column " << record.size() + 1 << "\n";
                        throw;
                    }
                    
                }
                line.erase(0, found + 1);
                found = line.find_first_of(_delimiters);

                if (found == string::npos) {
                    if (line.empty())
                        continue;

                    try
                    {
                        T val = convert(line);
                        record.push_back(val);
                    }
                    catch(const std::invalid_argument& e)
                    {
                        std::cerr << "loadtxt: while reading file \"" << _fname << "\", ";
                        std::cerr << "could not convert field '" << line << "' to double ";
                        std::cerr << "at row " << rows_read << " column " << record.size() + 1 << "\n";
                        // throw;
                    }
                }
            }
            // // convert each field to a double
            // // and add the newly-converted field to the end of the record
            // string cell;
            // double f;

            // while (getline(ss, cell, _delimiters[0])) {
            //     if (cell.empty()) continue;
            //     f = stod(cell);   
            //     record.push_back(f);
            // }

            // while (ss >> f) {
            //         record.push_back(f);
            // }

            _filedata.push_back(record);

            rows_read++;
        }
        
        // complain if something went wrong
        if (rows_read != _max_rows && !infile.eof())
        {
            cout << "loadtxt: could not read file (" << _fname << ")!\n";
            exit(1);
        }

        infile.close();

        size_t nlines = _filedata.size();

        // only read _max_rows of content
        if (_max_rows != 0)
            nlines = min(nlines, _max_rows);

        size_t ncols = _filedata[0].size();

        vector<int> cols;
        if (_usecols.size() == 0)
        {
            data.resize(ncols);
            cols.resize(ncols);
            std::iota(cols.begin(), cols.end(), 0);
        }
        else
        {
            data.resize(_usecols.size());
            cols = _usecols;
            //! usecols starts from 1!
            for (auto& j : cols)
                j--;
        }

        for (size_t i = 0; i < data.size(); i++)
            data[i].reserve(nlines);
        
        for (size_t i = 0; i < nlines; i++)
        {
            int k = 0;
            for (auto j : cols)
            {
                data[k].push_back(_filedata[i][j]);
                k++;
            }
        }
        
        return data;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x298, %rsp            # imm = 0x298
movq %rdi, -0x88(%rbp)
cmpq $0x0, 0x20(%rsi)
je 0x36fc
movq %rsi, %r14
addq $0x18, %rsi
leaq -0x2c0(%rbp), %rbx
pushq $0x8
popq %rdx
movq %rbx, %rdi
movq %rsi, -0x58(%rbp)
callq 0x2270
movq (%rbx), %rax
movq -0x18(%rax), %rax
testb $0x5, -0x2a0(%rbp,%rax)
jne 0x3748
xorl %r12d, %r12d
pushq $0xa
popq %r15
cmpq 0x78(%r14), %r12
jae 0x32ec
movl $0x10000, %esi          # imm = 0x10000
movq %rbx, %rdi
movl %r15d, %edx
callq 0x2120
incq %r12
jmp 0x32d1
xorps %xmm0, %xmm0
leaq -0x70(%rbp), %rax
movaps %xmm0, (%rax)
andq $0x0, 0x10(%rax)
leaq 0x38(%r14), %rax
movq %rax, -0x98(%rbp)
leaq 0x58(%r14), %rbx
leaq 0xa0(%r14), %rax
movq %rax, -0x90(%rbp)
movq $0x0, -0x30(%rbp)
leaq -0x50(%rbp), %r15
leaq -0xb8(%rbp), %r12
movq 0x98(%r14), %rax
leaq -0x1(%rax), %rcx
cmpq -0x30(%rbp), %rcx
jb 0x354c
movq -0x70(%rbp), %rax
cmpq %rax, -0x68(%rbp)
je 0x334e
movq %rax, -0x68(%rbp)
leaq -0x40(%rbp), %rax
movq %rax, -0x50(%rbp)
andq $0x0, -0x48(%rbp)
movb $0x0, -0x40(%rbp)
leaq -0x2c0(%rbp), %rdi
movq %r15, %rsi
callq 0x2050
movq -0x2c0(%rbp), %rax
movq -0x18(%rax), %rax
movb -0x2a0(%rbp,%rax), %al
shrb %al
cmpq $0x0, -0x48(%rbp)
sete %cl
andb %al, %cl
movb %cl, -0x78(%rbp)
jne 0x3533
movq %r15, %rdi
movq -0x98(%rbp), %rsi
xorl %edx, %edx
callq 0x2310
testq %rax, %rax
je 0x3533
movq %r15, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x21b0
movq %rax, %r13
cmpq $-0x1, %r13
je 0x351f
movq %r12, %rdi
movq %r15, %rsi
xorl %edx, %edx
movq %r13, %rcx
callq 0x21f0
cmpq $0x0, -0xb0(%rbp)
je 0x33ff
movq %r12, %rdi
xorl %esi, %esi
callq 0x3e40
movsd %xmm0, -0x80(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x3b9c
incq %r13
movq %r15, %rdi
xorl %esi, %esi
movq %r13, %rdx
callq 0x2070
movq %r15, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x21b0
movq %rax, %r13
cmpq $-0x1, %rax
jne 0x3448
cmpq $0x0, -0x48(%rbp)
je 0x3448
movq %r15, %rdi
xorl %esi, %esi
callq 0x3e40
movsd %xmm0, -0x80(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x3b9c
movq %r12, %rdi
callq 0x20d0
jmp 0x33bf
cmpl $0x1, %edx
jne 0x386f
movq %rax, %rdi
callq 0x20b0
movq 0x4b7b(%rip), %rdi      # 0x7fe8
leaq 0x206f(%rip), %rsi      # 0x54e3
callq 0x21c0
movq %rax, %rdi
movq -0x58(%rbp), %rsi
callq 0x21a0
movq %rax, %rdi
leaq 0x2072(%rip), %rsi      # 0x5501
callq 0x21c0
movq 0x4b4d(%rip), %rdi      # 0x7fe8
leaq 0x2063(%rip), %rsi      # 0x5505
callq 0x21c0
movq %rax, %rdi
movq %r15, %rsi
callq 0x21a0
movq %rax, %rdi
leaq 0x2063(%rip), %rsi      # 0x551f
callq 0x21c0
movq 0x4b20(%rip), %rdi      # 0x7fe8
leaq 0x205d(%rip), %rsi      # 0x552c
callq 0x21c0
movq %rax, %rdi
movq -0x30(%rbp), %rsi
callq 0x2140
movq %rax, %rdi
leaq 0x204a(%rip), %rsi      # 0x5534
callq 0x21c0
movq -0x68(%rbp), %rsi
subq -0x70(%rbp), %rsi
sarq $0x3, %rsi
incq %rsi
movq %rax, %rdi
callq 0x2140
movq %rax, %rdi
leaq 0x202f(%rip), %rsi      # 0x553f
callq 0x21c0
callq 0x22a0
jmp 0x3448
movq -0x90(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x3bc6
incq -0x30(%rbp)
movq %r15, %rdi
callq 0x20d0
cmpb $0x0, -0x78(%rbp)
je 0x332b
movq 0x98(%r14), %rax
cmpq %rax, -0x30(%rbp)
je 0x356b
movq -0x2c0(%rbp), %rax
movq -0x18(%rax), %rax
testb $0x2, -0x2a0(%rbp,%rax)
je 0x37b4
leaq -0x2c0(%rbp), %rdi
callq 0x2060
movq 0xa8(%r14), %rax
movq 0x98(%r14), %rcx
movq 0xa0(%r14), %rsi
subq %rsi, %rax
pushq $0x18
popq %r12
cqto
idivq %r12
cmpq %rax, %rcx
movq %rax, %r13
cmovbq %rcx, %r13
testq %rcx, %rcx
cmoveq %rax, %r13
movq 0x8(%rsi), %r15
subq (%rsi), %r15
xorps %xmm0, %xmm0
andq $0x0, -0x40(%rbp)
movaps %xmm0, -0x50(%rbp)
movq 0x88(%r14), %rsi
subq 0x80(%r14), %rsi
je 0x35fd
sarq $0x2, %rsi
movq %r14, %rdi
callq 0x3c02
leaq 0x80(%r14), %rsi
leaq -0x50(%rbp), %rdi
callq 0x3c7c
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rcx
cmpq %rcx, %rax
je 0x3631
decl (%rax)
addq $0x4, %rax
jmp 0x35f0
sarq $0x3, %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x3c02
leaq -0x50(%rbp), %rdi
movq %r15, %rsi
callq 0x3c44
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rcx
xorl %edx, %edx
cmpq %rcx, %rax
je 0x3631
movl %edx, (%rax)
incl %edx
addq $0x4, %rax
jmp 0x3622
xorl %r15d, %r15d
xorl %ebx, %ebx
movq (%r14), %rdi
movq 0x8(%r14), %rax
subq %rdi, %rax
cqto
idivq %r12
cmpq %rax, %rbx
jae 0x365e
addq %r15, %rdi
movq %r13, %rsi
callq 0x3d50
incq %rbx
addq $0x18, %r15
jmp 0x3636
xorl %eax, %eax
movq %r13, -0x30(%rbp)
cmpq %r13, %rax
je 0x36b6
movq -0x50(%rbp), %r12
movq -0x48(%rbp), %r13
movq %rax, -0x78(%rbp)
imulq $0x18, %rax, %rbx
xorl %r15d, %r15d
cmpq %r13, %r12
je 0x36a9
movslq (%r12), %rsi
movq (%r14), %rdi
addq %r15, %rdi
movq 0xa0(%r14), %rax
shlq $0x3, %rsi
addq (%rax,%rbx), %rsi
callq 0x3b9c
addq $0x4, %r12
addq $0x18, %r15
jmp 0x367c
movq -0x78(%rbp), %rax
incq %rax
movq -0x30(%rbp), %r13
jmp 0x3664
movq -0x88(%rbp), %rdi
movq %r14, %rsi
callq 0x3de6
leaq -0x50(%rbp), %rdi
callq 0x3a20
leaq -0x70(%rbp), %rdi
callq 0x420c
leaq -0x2c0(%rbp), %rdi
callq 0x2080
movq -0x88(%rbp), %rax
addq $0x298, %rsp            # imm = 0x298
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1da3(%rip), %rsi      # 0x54a6
leaq -0x2c0(%rbp), %rdi
leaq -0x50(%rbp), %rdx
callq 0x318c
pushq $0x10
popq %rdi
callq 0x20e0
movq %rax, %rbx
leaq -0x2c0(%rbp), %rsi
movq %rax, %rdi
callq 0x22c0
movq 0x489c(%rip), %rsi      # 0x7fd0
movq 0x4885(%rip), %rdx      # 0x7fc0
movq %rbx, %rdi
callq 0x22b0
jmp 0x394b
leaq 0x1d72(%rip), %rsi      # 0x54c1
leaq -0xb8(%rbp), %rdi
movq -0x58(%rbp), %rdx
callq 0x3b25
leaq 0x1d7a(%rip), %rdx      # 0x54e0
leaq -0x50(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x3afc
leaq -0xb8(%rbp), %rdi
callq 0x20d0
pushq $0x10
popq %rdi
callq 0x20e0
movq %rax, %rbx
leaq -0x50(%rbp), %rsi
movq %rax, %rdi
callq 0x2280
movq 0x4850(%rip), %rsi      # 0x7ff0
movq 0x4809(%rip), %rdx      # 0x7fb0
movq %rbx, %rdi
callq 0x22b0
jmp 0x394b
movq 0x47fd(%rip), %rdi      # 0x7fb8
leaq 0x1cff(%rip), %rsi      # 0x54c1
callq 0x21c0
movq %rax, %rdi
movq -0x58(%rbp), %rsi
callq 0x21a0
leaq 0x1d63(%rip), %rsi      # 0x553d
movq %rax, %rdi
callq 0x21c0
pushq $0x1
popq %rdi
callq 0x2200
jmp 0x386f
movq %rax, %r14
callq 0x22a0
jmp 0x3953
movq %rax, %r14
jmp 0x380c
movq %rax, %r14
movq %rbx, %rdi
callq 0x2160
leaq -0x50(%rbp), %rdi
jmp 0x381c
movq %rax, %r14
leaq -0xb8(%rbp), %rdi
callq 0x20d0
jmp 0x3987
movq %rax, %r14
jmp 0x3836
movq %rax, %r14
movq %rbx, %rdi
callq 0x2160
leaq -0x2c0(%rbp), %rdi
callq 0x20d0
jmp 0x3993
jmp 0x3867
movq %rax, %r14
jmp 0x3993
movq %rax, %r14
jmp 0x397e
jmp 0x3972
jmp 0x3877
jmp 0x3877
jmp 0x3972
movq %rax, %r14
jmp 0x3987
movq %rax, %r14
jmp 0x3953
movq %rax, %r14
jmp 0x395f
movq %rax, %r14
cmpl $0x1, %edx
jne 0x3953
movq %r14, %rdi
callq 0x20b0
movq 0x474e(%rip), %rdi      # 0x7fe8
leaq 0x1c42(%rip), %rsi      # 0x54e3
callq 0x21c0
movq %rax, %rdi
movq -0x58(%rbp), %rsi
callq 0x21a0
leaq 0x1c48(%rip), %rsi      # 0x5501
movq %rax, %rdi
callq 0x21c0
movq 0x4720(%rip), %rdi      # 0x7fe8
leaq 0x1c36(%rip), %rsi      # 0x5505
callq 0x21c0
leaq -0xb8(%rbp), %rsi
movq %rax, %rdi
callq 0x21a0
leaq 0x1c35(%rip), %rsi      # 0x551f
movq %rax, %rdi
callq 0x21c0
movq 0x46ef(%rip), %rdi      # 0x7fe8
leaq 0x1c2c(%rip), %rsi      # 0x552c
callq 0x21c0
movq %rax, %rdi
movq -0x30(%rbp), %rsi
callq 0x2140
leaq 0x1c1c(%rip), %rsi      # 0x5534
movq %rax, %rdi
callq 0x21c0
movq -0x68(%rbp), %rsi
subq -0x70(%rbp), %rsi
sarq $0x3, %rsi
incq %rsi
movq %rax, %rdi
callq 0x2140
leaq 0x1c01(%rip), %rsi      # 0x553f
movq %rax, %rdi
callq 0x21c0
callq 0x2240
movq %rax, %r14
callq 0x22a0
leaq -0xb8(%rbp), %rdi
callq 0x20d0
leaq -0x50(%rbp), %rdi
callq 0x20d0
jmp 0x397e
movq %rax, %rdi
callq 0x3a11
movq %rax, %r14
leaq -0x50(%rbp), %rdi
callq 0x3a20
leaq -0x70(%rbp), %rdi
callq 0x420c
leaq -0x2c0(%rbp), %rdi
callq 0x2080
movq %r14, %rdi
callq 0x22d0
nop