// File: /workspace/github_cpp_makefile_star2_O1/helchr[P]reMap/solver.cpp
// Function: Solver::getSolution(std::vector<unsigned long, std::allocator<unsigned long>> const&)
Solver::Solution Solver::getSolution(const std::vector<uint64_t> &matrix)
{
    Solution s;
    s.exists = true;
    for(auto row : matrix)
    {
        std::bitset<bitSize> bits(row>>1);
        std::bitset<1> rhs(row&1);
        if(bits.count() == 0 && rhs == 1)
        {
            // all zeros but a one in the last column
            std::cout << "No solution exists" << std::endl;
            s.exists=false;
            break;
        }
        else if(bits.count() == 1 && rhs == 0)
        {
           s.uninvolvedBits.insert(getSetBit(bits));
        }
        else if(bits.count() == 1 && rhs == 1)
        {
           s.involvedBits.insert(getSetBit(bits));
        }
        else if(bits.count() >= 2)
        {
            auto setBits = getSetBits(bits);
            s.unknownBits.insert(setBits.begin(),setBits.end());
        }
    }
    if(s.exists)
    {
        std::set<uint64_t> common;
        std::set_intersection(s.involvedBits.begin(),s.involvedBits.end(),
                              s.uninvolvedBits.begin(),s.uninvolvedBits.end(),
                              std::inserter(common,common.begin()));
        for(auto c : common)
        {
            auto it = s.involvedBits.find(c);
            s.involvedBits.erase(it);
            it = s.uninvolvedBits.find(c);
            s.uninvolvedBits.erase(it);
        }
    }
    return s;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %rbx
leaq 0x10(%rdi), %r14
xorl %eax, %eax
movl %eax, 0x10(%rdi)
movq %rax, 0x18(%rdi)
movq %r14, 0x20(%rdi)
movq %r14, 0x28(%rdi)
movq %rax, 0x30(%rdi)
leaq 0x40(%rdi), %r15
movl %eax, 0x40(%rdi)
movq %rax, 0x48(%rdi)
movq %r15, 0x50(%rdi)
movq %r15, 0x58(%rdi)
movq %rax, 0x60(%rdi)
leaq 0x70(%rdi), %rcx
movl %eax, 0x70(%rdi)
movq %rax, 0x78(%rdi)
movq %rcx, 0x80(%rdi)
movq %rcx, 0x88(%rdi)
movq %rax, 0x90(%rdi)
movb $0x1, (%rdi)
movq (%rdx), %r13
movq 0x8(%rdx), %r12
cmpq %r12, %r13
je 0xc70a
leaq 0x68(%rbx), %rax
movq %rax, (%rsp)
leaq 0x8(%rbx), %rax
movq %rax, 0x38(%rsp)
leaq 0x38(%rbx), %rax
movq %rax, 0x40(%rsp)
movabsq $0x3333333333333333, %rbp # imm = 0x3333333333333333
movq (%r13), %rax
cmpq $0x1, %rax
je 0xc6c0
movq %rax, %rdx
shrq %rdx
movq %rax, %rcx
shrq $0x2, %rcx
movabsq $0x1555555555555555, %rsi # imm = 0x1555555555555555
andq %rsi, %rcx
movq %rdx, %rsi
subq %rcx, %rsi
movq %rsi, %rcx
andq %rbp, %rcx
shrq $0x2, %rsi
andq %rbp, %rsi
addq %rcx, %rsi
movq %rsi, %rcx
shrq $0x4, %rcx
addq %rsi, %rcx
movabsq $0xf0f0f0f0f0f0f0f, %rsi # imm = 0xF0F0F0F0F0F0F0F
andq %rsi, %rcx
movabsq $0x101010101010101, %rsi # imm = 0x101010101010101
imulq %rsi, %rcx
shrq $0x38, %rcx
cmpl $0x1, %ecx
jne 0xc685
testb $0x1, %al
jne 0xc652
xorl %eax, %eax
btq %rax, %rdx
jb 0xc63c
incq %rax
cmpq $0x40, %rax
jne 0xc626
movq $-0x1, %rax
movq %rax, 0x8(%rsp)
movq 0x40(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0xc854
jmp 0xc6b1
cmpl $0x1, %ecx
jne 0xc685
xorl %eax, %eax
btq %rax, %rdx
jb 0xc66f
incq %rax
cmpq $0x40, %rax
jne 0xc659
movq $-0x1, %rax
movq %rax, 0x8(%rsp)
movq 0x38(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0xc854
jmp 0xc6b1
cmpl $0x2, %ecx
jb 0xc6b1
leaq 0x8(%rsp), %rdi
callq 0xc3a0
movq 0x20(%rsp), %rsi
movq (%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0xc8fe
leaq 0x8(%rsp), %rdi
callq 0xb0c8
addq $0x8, %r13
cmpq %r12, %r13
jne 0xc5b4
jmp 0xc70a
movq 0x1f8e9(%rip), %r12     # 0x2bfb0
leaq 0x15ad4(%rip), %rsi     # 0x221a2
movl $0x12, %edx
movq %r12, %rdi
callq 0x54c0
movq (%r12), %rax
addq -0x18(%rax), %r12
movq %r12, %rdi
movl $0xa, %esi
callq 0x5440
movsbl %al, %esi
movq 0x1f8b6(%rip), %rdi     # 0x2bfb0
callq 0x5030
movq %rax, %rdi
callq 0x5350
movb $0x0, (%rbx)
cmpb $0x1, (%rbx)
jne 0xc815
leaq 0x10(%rsp), %r12
movl $0x0, (%r12)
xorl %eax, %eax
movq %rax, 0x8(%r12)
movq %r12, 0x10(%r12)
movq %r12, 0x18(%r12)
movq %rax, 0x20(%r12)
movq 0x20(%rbx), %rdi
movq 0x50(%rbx), %rdx
leaq 0x8(%rsp), %r8
movq %r14, %rsi
movq %r15, %rcx
movq %r12, %r9
callq 0xca48
movq 0x20(%rsp), %r13
cmpq %r12, %r13
je 0xc80b
leaq 0x8(%rbx), %rax
movq %rax, (%rsp)
leaq 0x38(%rbx), %r12
movq 0x20(%r13), %rbp
movq 0x18(%rbx), %rcx
movq %r14, %rax
testq %rcx, %rcx
je 0xc795
movq %r14, %rax
xorl %edx, %edx
cmpq %rbp, 0x20(%rcx)
setb %dl
cmovaeq %rcx, %rax
movq 0x10(%rcx,%rdx,8), %rcx
testq %rcx, %rcx
jne 0xc77e
movq %r14, %rsi
cmpq %r14, %rax
je 0xc7a8
cmpq 0x20(%rax), %rbp
cmovbq %r14, %rax
movq %rax, %rsi
movq (%rsp), %rdi
callq 0xcaea
movq 0x48(%rbx), %rcx
movq %r15, %rax
testq %rcx, %rcx
je 0xc7d7
movq %r15, %rax
xorl %edx, %edx
cmpq %rbp, 0x20(%rcx)
setb %dl
cmovaeq %rcx, %rax
movq 0x10(%rcx,%rdx,8), %rcx
testq %rcx, %rcx
jne 0xc7c0
movq %r15, %rsi
cmpq %r15, %rax
je 0xc7ea
cmpq 0x20(%rax), %rbp
cmovbq %r15, %rax
movq %rax, %rsi
movq %r12, %rdi
callq 0xcaea
movq %r13, %rdi
callq 0x54e0
movq %rax, %r13
leaq 0x10(%rsp), %rax
cmpq %rax, %r13
jne 0xc76b
leaq 0x8(%rsp), %rdi
callq 0xb0c8
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xc836
jmp 0xc831
jmp 0xc831
jmp 0xc831
jmp 0xc836
movq %rax, %r14
jmp 0xc843
movq %rax, %r14
leaq 0x8(%rsp), %rdi
callq 0xb0c8
movq %rbx, %rdi
callq 0xa5d8
movq %r14, %rdi
callq 0x5790
nop