// File: /workspace/github_cpp_makefile_star2_O1/adrianphoulady[P]weighted-tsetlin-machine-cpp/./utils.h
// Function: load_file(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, array2d<unsigned int>*&, array1d<int>*&)
int load_file(std::string const &fname, array2d<word> *&x, array1d<int> *&y) {
    std::ifstream fin(fname);
    std::vector<std::vector<int>> data;
    if (!fin) {
        printf("File %s is missing!\n", fname.c_str());
        exit(1);
    }
    for (std::string line; std::getline(fin, line); ) {
        std::istringstream iss{line};
        data.emplace_back(std::vector<int>{});
        std::copy(std::istream_iterator<int>(iss), std::istream_iterator<int>(), std::back_inserter(data.back()));
    }
    fin.close();

    int features = data[0].size() - 1, samples = data.size(), literal_words = (2 * features + word_bits - 1) / word_bits;
    x = new array2d<word>{samples, literal_words};
    y = new array1d<int>{samples};
    std::fill((*x)(0), (*x)(samples), 0);
    for (int s = 0; s < samples; ++s) {
        if (data[s].size() != features + 1u) {
            printf("Inconsistent sample at line %d of %s!", s + 1, fname.c_str());
            exit(2);
        }
        for (int f = 0; f < features; ++f) {
            int l = f + !data[s][f] * features;
            (*x)(s, l / word_bits) |= (word) 1 << l % word_bits;
        }
        (*y)(s) = data[s].back();
    }

    return features;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x428, %rsp            # imm = 0x428
movq %rdx, 0x68(%rsp)
movq %rsi, 0x8(%rsp)
movq %rdi, %rsi
leaq 0xa0(%rsp), %r12
movq %r12, %rdi
movq %rsi, (%rsp)
movl $0x8, %edx
callq 0x22c0
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movq $0x0, 0x50(%rsp)
movq (%r12), %rax
movq -0x18(%rax), %rax
testb $0x5, 0xc0(%rsp,%rax)
jne 0x2a5e
leaq 0x90(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x80(%rsp), %rbp
leaq 0x2a8(%rsp), %rbx
leaq 0x20(%rsp), %r14
leaq 0x70(%rsp), %r15
movq 0x582e(%rip), %r13      # 0x7fe0
movq 0xa0(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %edx
movq %r12, %rdi
movq %rbp, %rsi
callq 0x2320
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x289f
movq %rbx, %rdi
movq %rbp, %rsi
movl $0x8, %edx
callq 0x22e0
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
leaq 0x40(%rsp), %rdi
movq %r14, %rsi
callq 0x355c
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x2828
callq 0x21b0
movq %rbx, 0x10(%rsp)
movb $0x1, 0x1c(%rsp)
leaq 0x10(%rsp), %rdi
callq 0x4ad6
movq 0x48(%rsp), %rdx
addq $-0x18, %rdx
movq 0x10(%rsp), %rax
movl 0x18(%rsp), %ecx
movb 0x1c(%rsp), %sil
movq %rax, 0x20(%rsp)
movl %ecx, 0x28(%rsp)
movb %sil, 0x2c(%rsp)
movq $0x0, 0x70(%rsp)
movl $0x0, 0x78(%rsp)
movb $0x0, 0x7c(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x4b06
movq %rbx, %rdi
movq %r13, %rsi
callq 0x2270
leaq 0x320(%rsp), %rdi
callq 0x20b0
jmp 0x27b2
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x28b9
callq 0x21b0
leaq 0xa0(%rsp), %rdi
callq 0x2070
movq 0x40(%rsp), %r15
movq 0x48(%rsp), %rbx
movq 0x8(%r15), %rbp
subq (%r15), %rbp
movl $0x10, %edi
callq 0x21d0
movq %rax, %r14
sarq $0x2, %rbp
leal -0x1(%rbp), %r12d
subq %r15, %rbx
sarq $0x3, %rbx
movabsq $-0x5555555555555555, %r13 # imm = 0xAAAAAAAAAAAAAAAB
imulq %rbx, %r13
leal 0x1f(,%r12,2), %eax
leal 0x3e(,%r12,2), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
sarl $0x5, %ecx
movl %r13d, (%r14)
movl %ecx, 0x4(%r14)
imull %r13d, %ecx
movslq %ecx, %rdi
shlq $0x2, %rdi
callq 0x2030
movq %rax, 0x8(%r14)
movq 0x8(%rsp), %rax
movq %r14, (%rax)
movl $0x10, %edi
callq 0x21d0
movq %rax, %r14
movq %rbp, 0x60(%rsp)
movl %r13d, (%rax)
movslq %r13d, %rdi
shlq $0x2, %rdi
callq 0x2030
movq %rax, %rbx
movq %rax, 0x8(%r14)
movq 0x68(%rsp), %rax
movq %r14, (%rax)
movq 0x8(%rsp), %rax
movq (%rax), %rbp
movq 0x8(%rbp), %r14
movslq 0x4(%rbp), %rax
movslq %r13d, %rdx
imulq %rax, %rdx
testl %edx, %edx
je 0x2995
shlq $0x2, %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x2110
testl %r13d, %r13d
jle 0x2a11
movl 0x60(%rsp), %eax
andl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
movl %r12d, %edx
xorl %esi, %esi
leaq (%rsi,%rsi,2), %rcx
movq (%r15,%rcx,8), %r8
movq 0x8(%r15,%rcx,8), %rdi
movq %rdi, %rcx
subq %r8, %rcx
sarq $0x2, %rcx
cmpq %rax, %rcx
jne 0x2a3d
testl %r12d, %r12d
jle 0x2a03
xorl %r9d, %r9d
cmpl $0x0, (%r8,%r9,4)
movl %r12d, %ecx
je 0x29da
xorl %ecx, %ecx
addl %r9d, %ecx
movl $0x1, %r10d
shll %cl, %r10d
shrl $0x5, %ecx
movl 0x4(%rbp), %r11d
imull %esi, %r11d
addl %ecx, %r11d
movslq %r11d, %rcx
orl %r10d, (%r14,%rcx,4)
incq %r9
cmpq %r9, %rdx
jne 0x29ce
movl -0x4(%rdi), %ecx
movl %ecx, (%rbx,%rsi,4)
incq %rsi
cmpq %r13, %rsi
jne 0x29aa
leaq 0x40(%rsp), %rdi
callq 0x3590
leaq 0xa0(%rsp), %rdi
callq 0x2090
movl %r12d, %eax
addq $0x428, %rsp            # imm = 0x428
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
incl %esi
movq (%rsp), %rax
movq (%rax), %rdx
leaq 0x26f4(%rip), %rdi      # 0x5141
xorl %eax, %eax
callq 0x2040
movl $0x2, %edi
callq 0x2200
movq (%rsp), %rax
movq (%rax), %rsi
leaq 0x26c0(%rip), %rdi      # 0x512c
xorl %eax, %eax
callq 0x2040
movl $0x1, %edi
callq 0x2200
jmp 0x2a7f
movq %rax, %rbx
movq %r14, %rdi
jmp 0x2ae2
jmp 0x2a89
movq %rax, %rbx
jmp 0x2ae7
jmp 0x2aca
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x2aa7
callq 0x21b0
jmp 0x2aa7
movq %rax, %rbx
movq 0x5532(%rip), %rsi      # 0x7fe0
leaq 0x2a8(%rsp), %rdi
callq 0x2270
leaq 0x320(%rsp), %rdi
callq 0x20b0
jmp 0x2acd
movq %rax, %rbx
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x2ae7
callq 0x21b0
leaq 0x40(%rsp), %rdi
callq 0x3590
leaq 0xa0(%rsp), %rdi
callq 0x2090
movq %rbx, %rdi
callq 0x22f0