// File: /workspace/github_cpp_makefile_star2_O2/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, 0x8(%rsp)
movq %rsi, (%rsp)
movq %rdi, %rsi
leaq 0xa0(%rsp), %rbx
pushq $0x8
popq %rdx
movq %rbx, %rdi
movq %rsi, 0x30(%rsp)
callq 0x22a0
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
andq $0x0, 0x20(%rsp)
movq (%rbx), %rax
movq -0x18(%rax), %rax
testb $0x5, 0xc0(%rsp,%rax)
jne 0x2941
leaq 0x80(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x70(%rsp), %r13
leaq 0x2a8(%rsp), %rbp
leaq 0x10(%rsp), %r15
leaq 0x50(%rsp), %r14
leaq 0x90(%rsp), %rbx
leaq 0x40(%rsp), %r12
leaq 0xa0(%rsp), %rdi
movq %r13, %rsi
callq 0x2070
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x278f
movq %rbp, %rdi
movq %r13, %rsi
pushq $0x8
popq %rdx
callq 0x22c0
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
andq $0x0, 0x60(%rsp)
movq %r15, %rdi
movq %r14, %rsi
callq 0x3194
movq %r14, %rdi
callq 0x40f0
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x3204
andq $0x0, 0x40(%rsp)
andl $0x0, 0x48(%rsp)
movb $0x0, 0x4c(%rsp)
movq 0x18(%rsp), %rdx
addq $-0x18, %rdx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x31c4
movq %rbp, %rdi
callq 0x2130
jmp 0x2706
leaq 0x70(%rsp), %rdi
callq 0x2120
leaq 0xa0(%rsp), %rdi
callq 0x2080
movq 0x10(%rsp), %rcx
movq 0x18(%rsp), %rax
movq 0x8(%rcx), %r15
subq (%rcx), %r15
subq %rcx, %rax
pushq $0x18
popq %rcx
cqto
idivq %rcx
movq %rax, %r12
pushq $0x10
popq %rdi
callq 0x21c0
movq %rax, %r14
sarq $0x2, %r15
leal -0x1(%r15), %r13d
leal 0x1f(,%r13,2), %eax
pushq $0x20
popq %rbx
cltd
idivl %ebx
movq %r14, %rdi
movl %r12d, %esi
movl %eax, %edx
callq 0x3210
movq (%rsp), %rax
movq %r14, (%rax)
pushq $0x10
popq %rdi
callq 0x21c0
movq %rax, %r14
movq %rax, %rdi
movl %r12d, %esi
callq 0x322e
movq 0x8(%rsp), %rax
movq %r14, (%rax)
movq (%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rsi), %rdi
movslq 0x4(%rsi), %rcx
movslq %r12d, %rax
imulq %rcx, %rax
shlq $0x2, %rax
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x2843
andl $0x0, (%rdi,%rcx)
addq $0x4, %rcx
jmp 0x2834
movq 0x10(%rsp), %rax
movq %rax, (%rsp)
movl %r15d, %eax
movq %rax, 0x8(%rsp)
xorl %r9d, %r9d
testl %r13d, %r13d
movl $0x0, %r11d
cmovgl %r13d, %r11d
testl %r12d, %r12d
cmovlel %r9d, %r12d
pushq $0x1
popq %r10
movq %r12, 0x38(%rsp)
cmpq %r12, %r9
je 0x28f3
imulq $0x18, %r9, %rax
movq (%rsp), %rcx
movq (%rcx,%rax), %r12
movq 0x8(%rcx,%rax), %r15
movq %r15, %rax
subq %r12, %rax
sarq $0x2, %rax
cmpq 0x8(%rsp), %rax
jne 0x291f
movq %r14, %r8
xorl %ebp, %ebp
cmpq %rbp, %r11
je 0x28da
cmpl $0x0, (%r12,%rbp,4)
movl $0x0, %eax
cmovel %r13d, %eax
addq %rbp, %rax
movl %r10d, %r14d
movl %eax, %ecx
shll %cl, %r14d
cltd
idivl %ebx
movl 0x4(%rsi), %ecx
imull %r9d, %ecx
addl %eax, %ecx
movslq %ecx, %rax
orl %r14d, (%rdi,%rax,4)
incq %rbp
jmp 0x28a4
movl -0x4(%r15), %eax
movq %r8, %r14
movq 0x8(%r8), %rcx
movl %eax, (%rcx,%r9,4)
incq %r9
movq 0x38(%rsp), %r12
jmp 0x2874
leaq 0x10(%rsp), %rdi
callq 0x3246
leaq 0xa0(%rsp), %rdi
callq 0x20a0
movl %r13d, %eax
addq $0x428, %rsp            # imm = 0x428
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leal 0x1(%r9), %esi
movq 0x30(%rsp), %rax
movq (%rax), %rdx
leaq 0x27bd(%rip), %rdi      # 0x50ef
xorl %eax, %eax
callq 0x2040
pushq $0x2
popq %rdi
callq 0x21f0
movq 0x30(%rsp), %rax
movq (%rax), %rsi
leaq 0x278a(%rip), %rdi      # 0x50da
xorl %eax, %eax
callq 0x2040
pushq $0x1
jmp 0x293b
jmp 0x295d
movq %rax, %rbx
movq %r14, %rdi
callq 0x21b0
jmp 0x29a1
jmp 0x296c
movq %rax, %rbx
jmp 0x29a1
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x40f0
jmp 0x298a
jmp 0x2982
movq %rax, %rbx
jmp 0x2997
movq %rax, %rbx
leaq 0x2a8(%rsp), %rdi
callq 0x2130
leaq 0x70(%rsp), %rdi
callq 0x2120
leaq 0x10(%rsp), %rdi
callq 0x3246
leaq 0xa0(%rsp), %rdi
callq 0x20a0
movq %rbx, %rdi
callq 0x22d0