// File: vsklad[P]cgen/./bal/anf/anf.cpp
// Function: bal::Anf::evaluate(bal::VariablesArray&) const
void Anf::evaluate(VariablesArray& variables) const {
        assert(variables_size() == variables.size());
        
        // pass 1 - gather values from unit clauses
        for (auto i = 0; i < equations_.size(); i++) {
            if (terms_size_(i) == 1 && symbols_size_(equations_[i]) == 1) {
                const literalid_t value = symbols_[terms_[equations_[i]]];
                _assert_level_1(literal_t__is_variable(value));
                variables.data()[literal_t__variable_id(value)] = literal_t__is_negation(value) ? 0b1 : 0b0;
            };
        };
        
        // pass 2 - try to evaluate all equations
        for (auto i = 0; i < equations_.size(); i++) {
            if (!(terms_size_(i) == 1 && symbols_size_(equations_[i]) == 1)) {
                const size_t terms_size = terms_size_(i);
                assert(terms_size >= 2);
                
                // assume the first term is the variable to assign
                // and the constant combined
                assert(symbols_size_(equations_[i]) == 1);
                assert(literal_t__is_variable(symbols_[terms_[equations_[i]]]));
                
                bool value = literal_t__is_negation(symbols_[terms_[equations_[i]]]);
                variableid_t variable_id = literal_t__variable_id(symbols_[terms_[equations_[i]]]);
                assert(variable_id < variables.size());
                
                // calculate variable value from the rest of equation
                for (auto j = equations_[i] + 1; j < equations_[i] + terms_size; j++) {
                    const size_t symbols_size = symbols_size_(j);
                    bool term_value = true;
                    for (auto k = terms_[j]; (k < terms_[j] + symbols_size) && term_value; k++) {
                        // require that all symbols are constants at this point
                        assert(literal_t__is_variable(symbols_[k]));
                        assert(!literal_t__is_negation(symbols_[k]));
                        assert(literal_t__variable_id(symbols_[k]) < variables.size());
                        const literalid_t symbol_value = variables.data()[literal_t__variable_id(symbols_[k])];
                        assert(literal_t__is_constant(symbol_value));
                        term_value &= literal_t__is_constant_1(symbol_value);
                    };
                    value ^= term_value;
                };
                
                variables.data()[variable_id] = literal_t__constant(value);
            };
        };
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x58(%rbp)
movq (%rdi), %rax
callq *0x58(%rax)
movl %eax, -0x50(%rbp)
movq -0x10(%rbp), %rdi
callq 0x102f0
movl %eax, %ecx
movl -0x50(%rbp), %eax
cmpl %ecx, %eax
jne 0xf0c8
jmp 0xf0e7
leaq 0x536ac(%rip), %rdi     # 0x6277b
leaq 0x4bf49(%rip), %rsi     # 0x5b01f
movl $0x129, %edx            # imm = 0x129
leaq 0x4c254(%rip), %rcx     # 0x5b336
callq 0xd1c0
movl $0x0, -0x14(%rbp)
movq -0x58(%rbp), %rdi
movslq -0x14(%rbp), %rax
movq %rax, -0x60(%rbp)
addq $0xa8, %rdi
callq 0xf9f0
movq %rax, %rcx
movq -0x60(%rbp), %rax
cmpq %rcx, %rax
jae 0xf221
movq -0x58(%rbp), %rdi
movslq -0x14(%rbp), %rsi
callq 0xfc30
cmpq $0x1, %rax
jne 0xf211
movq -0x58(%rbp), %rdi
addq $0xa8, %rdi
movslq -0x14(%rbp), %rsi
callq 0x102a0
movq -0x58(%rbp), %rdi
movl (%rax), %eax
movl %eax, %esi
callq 0xfd70
cmpq $0x1, %rax
jne 0xf211
movq -0x58(%rbp), %rdi
movq %rdi, %rax
addq $0x78, %rax
movq %rax, -0x70(%rbp)
movq %rdi, %rax
addq $0x90, %rax
movq %rax, -0x78(%rbp)
addq $0xa8, %rdi
movslq -0x14(%rbp), %rsi
callq 0x102a0
movq -0x78(%rbp), %rdi
movl (%rax), %eax
movl %eax, %esi
callq 0x102a0
movq -0x70(%rbp), %rdi
movl (%rax), %eax
movl %eax, %esi
callq 0x102a0
movl (%rax), %eax
movl %eax, -0x18(%rbp)
xorl %eax, %eax
cmpl $0x1, -0x18(%rbp)
movb %al, -0x61(%rbp)
jbe 0xf1b8
cmpl $-0x2, -0x18(%rbp)
setbe %al
movb %al, -0x61(%rbp)
movb -0x61(%rbp), %al
testb $0x1, %al
jne 0xf1c1
jmp 0xf1c3
jmp 0xf1e2
leaq 0x4c19c(%rip), %rdi     # 0x5b366
leaq 0x4be4e(%rip), %rsi     # 0x5b01f
movl $0x12f, %edx            # imm = 0x12F
leaq 0x4c159(%rip), %rcx     # 0x5b336
callq 0xd1c0
movl -0x18(%rbp), %edx
andl $0x1, %edx
xorl %eax, %eax
movl $0x1, %ecx
cmpl $0x0, %edx
cmovel %ecx, %eax
movl %eax, -0x7c(%rbp)
movq -0x10(%rbp), %rdi
callq 0x10310
movl -0x7c(%rbp), %edx
movl -0x18(%rbp), %ecx
shrl %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movl %edx, (%rax,%rcx,4)
jmp 0xf213
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xf0ee
movl $0x0, -0x1c(%rbp)
movq -0x58(%rbp), %rdi
movslq -0x1c(%rbp), %rax
movq %rax, -0x88(%rbp)
addq $0xa8, %rdi
callq 0xf9f0
movq %rax, %rcx
movq -0x88(%rbp), %rax
cmpq %rcx, %rax
jae 0xf7d4
movq -0x58(%rbp), %rdi
movslq -0x1c(%rbp), %rsi
callq 0xfc30
cmpq $0x1, %rax
jne 0xf294
movq -0x58(%rbp), %rdi
addq $0xa8, %rdi
movslq -0x1c(%rbp), %rsi
callq 0x102a0
movq -0x58(%rbp), %rdi
movl (%rax), %eax
movl %eax, %esi
callq 0xfd70
cmpq $0x1, %rax
je 0xf7c4
movq -0x58(%rbp), %rdi
movslq -0x1c(%rbp), %rsi
callq 0xfc30
movq %rax, -0x28(%rbp)
cmpq $0x2, -0x28(%rbp)
jb 0xf2ae
jmp 0xf2cd
leaq 0x4c0f9(%rip), %rdi     # 0x5b3ae
leaq 0x4bd63(%rip), %rsi     # 0x5b01f
movl $0x138, %edx            # imm = 0x138
leaq 0x4c06e(%rip), %rcx     # 0x5b336
callq 0xd1c0
movq -0x58(%rbp), %rdi
addq $0xa8, %rdi
movslq -0x1c(%rbp), %rsi
callq 0x102a0
movq -0x58(%rbp), %rdi
movl (%rax), %eax
movl %eax, %esi
callq 0xfd70
cmpq $0x1, %rax
jne 0xf2f6
jmp 0xf315
leaq 0x4c0c1(%rip), %rdi     # 0x5b3be
leaq 0x4bd1b(%rip), %rsi     # 0x5b01f
movl $0x13c, %edx            # imm = 0x13C
leaq 0x4c026(%rip), %rcx     # 0x5b336
callq 0xd1c0
movq -0x58(%rbp), %rdi
movq %rdi, %rax
addq $0x78, %rax
movq %rax, -0x98(%rbp)
movq %rdi, %rax
addq $0x90, %rax
movq %rax, -0xa0(%rbp)
addq $0xa8, %rdi
movslq -0x1c(%rbp), %rsi
callq 0x102a0
movq -0xa0(%rbp), %rdi
movl (%rax), %eax
movl %eax, %esi
callq 0x102a0
movq -0x98(%rbp), %rdi
movl (%rax), %eax
movl %eax, %esi
callq 0x102a0
movq %rax, %rcx
xorl %eax, %eax
cmpl $0x1, (%rcx)
movb %al, -0x89(%rbp)
jbe 0xf3d5
movq -0x58(%rbp), %rdi
movq %rdi, %rax
addq $0x78, %rax
movq %rax, -0xa8(%rbp)
movq %rdi, %rax
addq $0x90, %rax
movq %rax, -0xb0(%rbp)
addq $0xa8, %rdi
movslq -0x1c(%rbp), %rsi
callq 0x102a0
movq -0xb0(%rbp), %rdi
movl (%rax), %eax
movl %eax, %esi
callq 0x102a0
movq -0xa8(%rbp), %rdi
movl (%rax), %eax
movl %eax, %esi
callq 0x102a0
cmpl $-0x2, (%rax)
setbe %al
movb %al, -0x89(%rbp)
movb -0x89(%rbp), %al
testb $0x1, %al
jne 0xf3e1
jmp 0xf3e3
jmp 0xf402
leaq 0x4bff6(%rip), %rdi     # 0x5b3e0
leaq 0x4bc2e(%rip), %rsi     # 0x5b01f
movl $0x13d, %edx            # imm = 0x13D
leaq 0x4bf39(%rip), %rcx     # 0x5b336
callq 0xd1c0
movq -0x58(%rbp), %rdi
movq %rdi, %rax
addq $0x78, %rax
movq %rax, -0xd0(%rbp)
movq %rdi, %rax
addq $0x90, %rax
movq %rax, -0xd8(%rbp)
addq $0xa8, %rdi
movslq -0x1c(%rbp), %rsi
callq 0x102a0
movq -0xd8(%rbp), %rdi
movl (%rax), %eax
movl %eax, %esi
callq 0x102a0
movq -0xd0(%rbp), %rdi
movl (%rax), %eax
movl %eax, %esi
callq 0x102a0
movq -0x58(%rbp), %rdi
movl (%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
sete %al
andb $0x1, %al
movb %al, -0x29(%rbp)
movq %rdi, %rax
addq $0x78, %rax
movq %rax, -0xc0(%rbp)
movq %rdi, %rax
addq $0x90, %rax
movq %rax, -0xc8(%rbp)
addq $0xa8, %rdi
movslq -0x1c(%rbp), %rsi
callq 0x102a0
movq -0xc8(%rbp), %rdi
movl (%rax), %eax
movl %eax, %esi
callq 0x102a0
movq -0xc0(%rbp), %rdi
movl (%rax), %eax
movl %eax, %esi
callq 0x102a0
movl (%rax), %eax
shrl %eax
subl $0x1, %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0xb4(%rbp)
movq -0x10(%rbp), %rdi
callq 0x102f0
movl %eax, %ecx
movl -0xb4(%rbp), %eax
cmpl %ecx, %eax
jae 0xf4e0
jmp 0xf4ff
leaq 0x4bf31(%rip), %rdi     # 0x5b418
leaq 0x4bb31(%rip), %rsi     # 0x5b01f
movl $0x141, %edx            # imm = 0x141
leaq 0x4be3c(%rip), %rcx     # 0x5b336
callq 0xd1c0
movq -0x58(%rbp), %rdi
addq $0xa8, %rdi
movslq -0x1c(%rbp), %rsi
callq 0x102a0
movl (%rax), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movq -0x58(%rbp), %rdi
movl -0x34(%rbp), %eax
movq %rax, -0xe0(%rbp)
addq $0xa8, %rdi
movslq -0x1c(%rbp), %rsi
callq 0x102a0
movq %rax, %rcx
movq -0xe0(%rbp), %rax
movl (%rcx), %ecx
addq -0x28(%rbp), %rcx
cmpq %rcx, %rax
jae 0xf799
movq -0x58(%rbp), %rdi
movl -0x34(%rbp), %eax
movl %eax, %esi
callq 0xfd70
movq -0x58(%rbp), %rdi
movq %rax, -0x40(%rbp)
movb $0x1, -0x41(%rbp)
addq $0x90, %rdi
movl -0x34(%rbp), %eax
movl %eax, %esi
callq 0x102a0
movl (%rax), %eax
movl %eax, -0x48(%rbp)
movq -0x58(%rbp), %rdi
movl -0x48(%rbp), %eax
movq %rax, -0xf0(%rbp)
addq $0x90, %rdi
movl -0x34(%rbp), %eax
movl %eax, %esi
callq 0x102a0
movq -0xf0(%rbp), %rcx
movl (%rax), %eax
movl %eax, %edx
addq -0x40(%rbp), %rdx
xorl %eax, %eax
cmpq %rdx, %rcx
movb %al, -0xe1(%rbp)
jae 0xf5c6
movb -0x41(%rbp), %al
movb %al, -0xe1(%rbp)
movb -0xe1(%rbp), %al
testb $0x1, %al
jne 0xf5d5
jmp 0xf76e
movq -0x58(%rbp), %rdi
addq $0x78, %rdi
movl -0x48(%rbp), %eax
movl %eax, %esi
callq 0x102a0
movq %rax, %rcx
xorl %eax, %eax
cmpl $0x1, (%rcx)
movb %al, -0xf1(%rbp)
jbe 0xf615
movq -0x58(%rbp), %rdi
addq $0x78, %rdi
movl -0x48(%rbp), %eax
movl %eax, %esi
callq 0x102a0
cmpl $-0x2, (%rax)
setbe %al
movb %al, -0xf1(%rbp)
movb -0xf1(%rbp), %al
testb $0x1, %al
jne 0xf621
jmp 0xf623
jmp 0xf642
leaq 0x4bc2b(%rip), %rdi     # 0x5b255
leaq 0x4b9ee(%rip), %rsi     # 0x5b01f
movl $0x149, %edx            # imm = 0x149
leaq 0x4bcf9(%rip), %rcx     # 0x5b336
callq 0xd1c0
movq -0x58(%rbp), %rdi
addq $0x78, %rdi
movl -0x48(%rbp), %eax
movl %eax, %esi
callq 0x102a0
movl (%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
sete %al
xorb $-0x1, %al
testb $0x1, %al
jne 0xf667
jmp 0xf669
jmp 0xf688
leaq 0x4bc5d(%rip), %rdi     # 0x5b2cd
leaq 0x4b9a8(%rip), %rsi     # 0x5b01f
movl $0x14a, %edx            # imm = 0x14A
leaq 0x4bcb3(%rip), %rcx     # 0x5b336
callq 0xd1c0
movq -0x58(%rbp), %rdi
addq $0x78, %rdi
movl -0x48(%rbp), %eax
movl %eax, %esi
callq 0x102a0
movl (%rax), %eax
shrl %eax
subl $0x1, %eax
movl %eax, -0xf8(%rbp)
movq -0x10(%rbp), %rdi
callq 0x102f0
movl %eax, %ecx
movl -0xf8(%rbp), %eax
cmpl %ecx, %eax
jae 0xf6be
jmp 0xf6dd
leaq 0x4bd72(%rip), %rdi     # 0x5b437
leaq 0x4b953(%rip), %rsi     # 0x5b01f
movl $0x14b, %edx            # imm = 0x14B
leaq 0x4bc5e(%rip), %rcx     # 0x5b336
callq 0xd1c0
movq -0x10(%rbp), %rdi
callq 0x10310
movq -0x58(%rbp), %rdi
movq %rax, -0x100(%rbp)
addq $0x78, %rdi
movl -0x48(%rbp), %eax
movl %eax, %esi
callq 0x102a0
movq %rax, %rcx
movq -0x100(%rbp), %rax
movl (%rcx), %ecx
shrl %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x4c(%rbp)
cmpl $0x1, -0x4c(%rbp)
ja 0xf720
jmp 0xf73f
leaq 0x4bd47(%rip), %rdi     # 0x5b46e
leaq 0x4b8f1(%rip), %rsi     # 0x5b01f
movl $0x14d, %edx            # imm = 0x14D
leaq 0x4bbfc(%rip), %rcx     # 0x5b336
callq 0xd1c0
cmpl $0x1, -0x4c(%rbp)
sete %al
andb $0x1, %al
movzbl %al, %ecx
movb -0x41(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
andl %ecx, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, -0x41(%rbp)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0xf582
movb -0x41(%rbp), %al
andb $0x1, %al
movzbl %al, %ecx
movb -0x29(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
xorl %ecx, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, -0x29(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xf51b
movb -0x29(%rbp), %dl
xorl %eax, %eax
movl $0x1, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0x104(%rbp)
movq -0x10(%rbp), %rdi
callq 0x10310
movl -0x104(%rbp), %edx
movl -0x30(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
jmp 0xf7c6
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xf228
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
nopl (%rax)