// File: 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
movq %rsp, %rbp
subq $0x2a0, %rsp            # imm = 0x2A0
movq %rdi, -0x1d0(%rbp)
movq %rdi, %rax
movq %rax, -0x1e0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x1d8(%rbp)
movb $0x0, -0x19(%rbp)
callq 0x181a0
movq -0x1d0(%rbp), %rdi
movb $0x1, (%rdi)
movq -0x18(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0x10a60
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rdi
callq 0x10a90
movq %rax, -0x38(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x18120
testb $0x1, %al
jne 0x17a6e
jmp 0x17da7
leaq -0x30(%rbp), %rdi
callq 0x18160
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rsi
shrq %rsi
leaq -0x48(%rbp), %rdi
callq 0xca60
movq -0x40(%rbp), %rsi
andq $0x1, %rsi
leaq -0x50(%rbp), %rdi
callq 0x181e0
leaq -0x48(%rbp), %rdi
callq 0xcab0
movq %rax, %rcx
xorl %eax, %eax
cmpq $0x0, %rcx
movb %al, -0x1e1(%rbp)
jne 0x17ada
leaq -0x58(%rbp), %rdi
movl $0x1, %esi
callq 0x181e0
leaq -0x50(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x18230
movb %al, -0x1e1(%rbp)
movb -0x1e1(%rbp), %al
testb $0x1, %al
jne 0x17ae6
jmp 0x17b37
movq 0x2e4c3(%rip), %rdi     # 0x45fb0
leaq 0x1b6fe(%rip), %rsi     # 0x331f2
callq 0x6570
movq %rax, -0x1f0(%rbp)
jmp 0x17b02
movq -0x1f0(%rbp), %rdi
movq 0x2e458(%rip), %rsi     # 0x45f68
callq 0x65b0
jmp 0x17b17
movq -0x1d0(%rbp), %rax
movb $0x0, (%rax)
jmp 0x17da7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x1807e
leaq -0x48(%rbp), %rdi
callq 0xcab0
movq %rax, %rcx
xorl %eax, %eax
cmpq $0x1, %rcx
movb %al, -0x1f1(%rbp)
jne 0x17b71
leaq -0x70(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x181e0
leaq -0x50(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x18230
movb %al, -0x1f1(%rbp)
movb -0x1f1(%rbp), %al
testb $0x1, %al
jne 0x17b7d
jmp 0x17bf9
movq -0x1d8(%rbp), %rdi
movq -0x1d0(%rbp), %rax
addq $0x38, %rax
movq %rax, -0x208(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rsi
callq 0x17700
movq %rax, -0x200(%rbp)
jmp 0x17bb0
movq -0x208(%rbp), %rdi
movq -0x200(%rbp), %rax
movq %rax, -0x78(%rbp)
leaq -0x78(%rbp), %rsi
callq 0x18260
movb %dl, -0x211(%rbp)
movq %rax, -0x210(%rbp)
jmp 0x17bda
movb -0x211(%rbp), %al
movq -0x210(%rbp), %rcx
movq %rcx, -0x90(%rbp)
movb %al, -0x88(%rbp)
jmp 0x17d95
leaq -0x48(%rbp), %rdi
callq 0xcab0
movq %rax, %rcx
xorl %eax, %eax
cmpq $0x1, %rcx
movb %al, -0x212(%rbp)
jne 0x17c3a
leaq -0x98(%rbp), %rdi
movl $0x1, %esi
callq 0x181e0
leaq -0x50(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x18230
movb %al, -0x212(%rbp)
movb -0x212(%rbp), %al
testb $0x1, %al
jne 0x17c49
jmp 0x17cd1
movq -0x1d8(%rbp), %rdi
movq -0x1d0(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x228(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rsi
callq 0x17700
movq %rax, -0x220(%rbp)
jmp 0x17c82
movq -0x228(%rbp), %rdi
movq -0x220(%rbp), %rax
movq %rax, -0xa0(%rbp)
leaq -0xa0(%rbp), %rsi
callq 0x18260
movb %dl, -0x231(%rbp)
movq %rax, -0x230(%rbp)
jmp 0x17cb2
movb -0x231(%rbp), %al
movq -0x230(%rbp), %rcx
movq %rcx, -0xb8(%rbp)
movb %al, -0xb0(%rbp)
jmp 0x17d93
leaq -0x48(%rbp), %rdi
callq 0xcab0
cmpq $0x2, %rax
jb 0x17d91
movq -0x1d8(%rbp), %rsi
movq -0x48(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq -0xf0(%rbp), %rdx
leaq -0xe8(%rbp), %rdi
callq 0x17780
jmp 0x17d0b
movq -0x1d0(%rbp), %rax
addq $0x68, %rax
movq %rax, -0x240(%rbp)
leaq -0xe8(%rbp), %rdi
movq %rdi, -0x248(%rbp)
callq 0xcdf0
movq -0x248(%rbp), %rdi
movq %rax, -0xf8(%rbp)
callq 0xce20
movq -0x240(%rbp), %rdi
movq %rax, -0x100(%rbp)
movq -0xf8(%rbp), %rsi
movq -0x100(%rbp), %rdx
callq 0x182b0
jmp 0x17d66
leaq -0xe8(%rbp), %rdi
callq 0xe070
jmp 0x17d91
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0xe070
jmp 0x1807e
jmp 0x17d93
jmp 0x17d95
jmp 0x17d97
jmp 0x17d99
leaq -0x30(%rbp), %rdi
callq 0x18180
jmp 0x17a58
movq -0x1d0(%rbp), %rax
testb $0x1, (%rax)
je 0x18058
leaq -0x130(%rbp), %rdi
movq %rdi, -0x260(%rbp)
callq 0xd190
movq -0x1d0(%rbp), %rdi
addq $0x8, %rdi
movq %rdi, -0x270(%rbp)
callq 0xcdf0
movq -0x270(%rbp), %rdi
movq %rax, -0x138(%rbp)
callq 0xce20
movq -0x1d0(%rbp), %rdi
movq %rax, -0x140(%rbp)
addq $0x38, %rdi
movq %rdi, -0x268(%rbp)
callq 0xcdf0
movq -0x268(%rbp), %rdi
movq %rax, -0x148(%rbp)
callq 0xce20
movq -0x260(%rbp), %rdi
movq %rax, -0x150(%rbp)
callq 0xcdf0
movq -0x260(%rbp), %rdi
movq %rax, -0x168(%rbp)
movq -0x168(%rbp), %rsi
callq 0x18380
movq %rdx, -0x258(%rbp)
movq %rax, -0x250(%rbp)
jmp 0x17e62
movq -0x258(%rbp), %rax
movq -0x250(%rbp), %rcx
movq %rcx, -0x160(%rbp)
movq %rax, -0x158(%rbp)
movq -0x138(%rbp), %rdi
movq -0x140(%rbp), %rsi
movq -0x148(%rbp), %rdx
movq -0x150(%rbp), %rcx
movq -0x160(%rbp), %r8
movq -0x158(%rbp), %r9
callq 0x182f0
movq %rdx, -0x280(%rbp)
movq %rax, -0x278(%rbp)
jmp 0x17ebd
movq -0x280(%rbp), %rax
movq -0x278(%rbp), %rcx
movq %rcx, -0x178(%rbp)
movq %rax, -0x170(%rbp)
leaq -0x130(%rbp), %rax
movq %rax, -0x180(%rbp)
movq -0x180(%rbp), %rdi
callq 0xcdf0
movq %rax, -0x188(%rbp)
movq -0x180(%rbp), %rdi
callq 0xce20
movq %rax, -0x190(%rbp)
leaq -0x188(%rbp), %rdi
leaq -0x190(%rbp), %rsi
callq 0xce50
testb $0x1, %al
jne 0x17f29
jmp 0x1804c
leaq -0x188(%rbp), %rdi
callq 0xce80
movq -0x1d0(%rbp), %rdi
movq (%rax), %rax
movq %rax, -0x198(%rbp)
addq $0x8, %rdi
leaq -0x198(%rbp), %rsi
callq 0x183c0
movq %rax, -0x288(%rbp)
jmp 0x17f5f
movq -0x1d0(%rbp), %rdi
movq -0x288(%rbp), %rax
movq %rax, -0x1a0(%rbp)
addq $0x8, %rdi
movq -0x1a0(%rbp), %rax
movq %rax, -0x1a8(%rbp)
movq -0x1a8(%rbp), %rsi
callq 0x18400
movq %rax, -0x290(%rbp)
jmp 0x17f9b
movq -0x1d0(%rbp), %rdi
movq -0x290(%rbp), %rax
movq %rax, -0x1b0(%rbp)
addq $0x38, %rdi
leaq -0x198(%rbp), %rsi
callq 0x183c0
movq %rax, -0x298(%rbp)
jmp 0x17fc9
movq -0x1d0(%rbp), %rdi
movq -0x298(%rbp), %rax
movq %rax, -0x1b8(%rbp)
movq -0x1b8(%rbp), %rax
movq %rax, -0x1a0(%rbp)
addq $0x38, %rdi
movq -0x1a0(%rbp), %rax
movq %rax, -0x1c0(%rbp)
movq -0x1c0(%rbp), %rsi
callq 0x18400
movq %rax, -0x2a0(%rbp)
jmp 0x18013
movq -0x2a0(%rbp), %rax
movq %rax, -0x1c8(%rbp)
leaq -0x188(%rbp), %rdi
callq 0xceb0
jmp 0x17f0d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x130(%rbp), %rdi
callq 0xe070
jmp 0x1807e
leaq -0x130(%rbp), %rdi
callq 0xe070
movb $0x1, -0x19(%rbp)
testb $0x1, -0x19(%rbp)
jne 0x1806e
movq -0x1d0(%rbp), %rdi
callq 0xcd50
movq -0x1e0(%rbp), %rax
addq $0x2a0, %rsp            # imm = 0x2A0
popq %rbp
retq
movq -0x1d0(%rbp), %rdi
callq 0xcd50
movq -0x60(%rbp), %rdi
callq 0x6950
nopw %cs:(%rax,%rax)
nopl (%rax)