// File: /workspace/github_cpp_makefile_star2_O1/kc885[P]SAT-Solver-with-CDCL/cdcl.cpp
// Function: ck_cdcl_solver::Solver::unitPropagate(std::unordered_set<int, std::hash<int>, std::equal_to<int>, std::allocator<int>>&, int)
bool unitPropagate(std::unordered_set<int> &implied, int level){
            //visited array
            std::vector<int> visited(clauses.size(),0);
            
            std::unordered_set<int> intermediate;
            

            //unit propagation
            
            int new_imply_flag;
            do{
                new_imply_flag = 0;
                for (int i =0; i < (int)clauses.size(); i++){
                    if(visited[i] == 0){
                        
                        visited[i] = 1;
                        
                        //analyze this clause
                        int val = 0;
                        int undef_num = 0;
                        int target_var;
                        
                        for(auto iter = clauses[i].begin(); iter != clauses[i].end(); iter++){
                            if(val_decisionLevel[std::abs(*iter)] == 0){
                                undef_num++;
                                target_var = *iter;
                                if(undef_num > 1)
                                    break;
                            }
                            else if(val_decisionLevel[std::abs(*iter)] * (*iter) > 0){
                                val = 1;
                                break;
                            }
                        }
                        
                        if(val == 0 ){
                            //conflict
                            if(undef_num == 0){
                               
                                //learn a new clause
                                std::unordered_set<int> learnt_level;
                                std::unordered_set<int> learnt;
                                
                                for(auto iter = intermediate.begin(); iter!= intermediate.end();iter++){
                                    if(intermediate.count(-(*iter)) == 0){
                                        varToClause[*iter].push_back(clauses.size());
                                        learnt.insert(*iter);
                                    }
                                }

 
                                clauses.push_back(learnt);
                                
                                for(auto iter = implied.begin(); iter != implied.end(); iter++)
                                    val_decisionLevel[*iter] = 0;
                                return false;
                            }
                            //imply a new variable
                            else if(undef_num == 1){
                                new_imply_flag = 1;
                                implied.insert(std::abs(target_var));
                                
                                
                                val_decisionLevel[std::abs(target_var)] = (((target_var) > 0) - ((target_var) < 0))*level;
                                
                                //get variables which help to imply this variable(inclusing itself)
                                for(auto iter = clauses[i].begin(); iter != clauses[i].end(); iter++){
                                    intermediate.insert(*iter);
                                }
                                
                                for(auto iter = varToClause[target_var].begin();iter != varToClause[target_var].end(); iter++)
                                    visited[*iter] = 0;
                                for(auto iter = varToClause[-target_var].begin();iter != varToClause[-target_var].end(); iter++)
                                    visited[*iter] = 0;
                                break;        
                            }
                        }
                          
                    }  
                }

            }while(new_imply_flag == 1);
            return true;
        }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movl %edx, 0x1c(%rsp)
movq %rsi, %r12
movq %rdi, %r15
leaq 0x38(%rdi), %rax
movq %rax, 0x80(%rsp)
movq 0x40(%rdi), %rax
subq 0x38(%rdi), %rax
sarq $0x3, %rax
movabsq $0x6db6db6db6db6db7, %rsi # imm = 0x6DB6DB6DB6DB6DB7
imulq %rax, %rsi
leaq 0xc0(%rsp), %r13
movl $0x0, (%r13)
leaq 0x28(%rsp), %rdi
leaq 0x40(%rsp), %rcx
movq %r13, %rdx
callq 0x4f06
leaq 0xf0(%rsp), %rax
movq %rax, -0x30(%rax)
movq $0x1, -0x28(%rax)
xorps %xmm0, %xmm0
movups %xmm0, -0x20(%rax)
movl $0x3f800000, -0x10(%rax) # imm = 0x3F800000
movups %xmm0, -0x8(%rax)
movq %r12, 0x78(%rsp)
movq 0x38(%r15), %rax
movq 0x40(%r15), %rcx
subq %rax, %rcx
shrq $0x3, %rcx
imull $0xb6db6db7, %ecx, %ecx # imm = 0xB6DB6DB7
xorl %edx, %edx
testl %ecx, %ecx
jle 0x4ce1
movq $0x0, 0x20(%rsp)
xorl %r14d, %r14d
movq 0x28(%rsp), %rcx
cmpl $0x0, (%rcx,%r14,4)
jne 0x4ca8
movl $0x1, (%rcx,%r14,4)
imulq $0x38, %r14, %rbx
movq 0x10(%rax,%rbx), %rsi
movb $0x1, %cl
xorl %eax, %eax
movl $0x0, %edx
movb $0x1, %dil
testq %rsi, %rsi
je 0x4a1d
movq 0x50(%r15), %rdi
xorl %edx, %edx
movl 0x8(%rsi), %r8d
movl %r8d, %r9d
negl %r9d
cmovsl %r8d, %r9d
movl (%rdi,%r9,4), %r9d
testl %r9d, %r9d
je 0x49f9
imull %r8d, %r9d
testl %r9d, %r9d
jle 0x4a07
jmp 0x4a11
movl %r8d, 0xc(%rsp)
testl %edx, %edx
movl $0x1, %edx
jg 0x4a15
movq (%rsi), %rsi
testq %rsi, %rsi
jne 0x49d7
jmp 0x4a1a
xorl %edi, %edi
jmp 0x4a1d
movl $0x2, %edx
movb $0x1, %dil
testb %dil, %dil
je 0x4ca4
cmpl $0x1, %edx
je 0x4b95
testl %edx, %edx
jne 0x4ca4
leaq 0x70(%rsp), %rax
movq %rax, 0x40(%rsp)
movl $0x1, %ecx
movq %rcx, 0x48(%rsp)
xorps %xmm0, %xmm0
leaq 0x40(%rsp), %rax
movups %xmm0, 0x10(%rax)
movl $0x3f800000, %edx       # imm = 0x3F800000
movl %edx, 0x60(%rsp)
movups %xmm0, 0x28(%rax)
leaq 0xb8(%rsp), %rax
movq %rax, 0x88(%rsp)
movq %rcx, 0x90(%rsp)
movups %xmm0, -0x20(%rax)
movl %edx, 0xa8(%rsp)
movups %xmm0, -0x8(%rax)
movq 0xd0(%rsp), %r12
testq %r12, %r12
leaq 0x10(%rsp), %rbx
je 0x4b37
xorl %eax, %eax
subl 0x8(%r12), %eax
movl %eax, 0x10(%rsp)
movq %r13, %rdi
movq %rbx, %rsi
callq 0x3546
testq %rax, %rax
jne 0x4b2a
leaq 0x8(%r12), %rbx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x383e
movq 0x40(%r15), %rcx
subq 0x38(%r15), %rcx
shrq $0x3, %rcx
imull $0xb6db6db7, %ecx, %ecx # imm = 0xB6DB6DB7
movl %ecx, 0x10(%rsp)
movq 0x8(%rax), %rsi
cmpq 0x10(%rax), %rsi
je 0x4afd
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rax)
leaq 0x10(%rsp), %rbp
jmp 0x4b0d
movq %rax, %rdi
leaq 0x10(%rsp), %rbp
movq %rbp, %rdx
callq 0x3038
leaq 0x88(%rsp), %rdi
movq %rdi, 0x10(%rsp)
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x35c0
leaq 0x10(%rsp), %rbx
movq (%r12), %r12
testq %r12, %r12
jne 0x4aa1
movq 0x80(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x2fc4
movq 0x78(%rsp), %r12
movq 0x10(%r12), %rax
testq %rax, %rax
je 0x4b72
movq 0x50(%r15), %rcx
movslq 0x8(%rax), %rdx
movl $0x0, (%rcx,%rdx,4)
movq (%rax), %rax
testq %rax, %rax
jne 0x4b5f
leaq 0x88(%rsp), %rdi
callq 0x3de2
leaq 0x40(%rsp), %rdi
callq 0x3de2
movl $0x1, %eax
xorl %ecx, %ecx
jmp 0x4ca4
movl 0xc(%rsp), %eax
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
movl %ecx, 0x88(%rsp)
movq %r12, 0x40(%rsp)
movq %r12, %rdi
leaq 0x88(%rsp), %rsi
leaq 0x40(%rsp), %rdx
callq 0x507a
movl 0xc(%rsp), %eax
movl %eax, %ecx
sarl $0x1f, %ecx
xorl %edx, %edx
testl %eax, %eax
setne %dl
orl %ecx, %edx
imull 0x1c(%rsp), %edx
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
movq 0x50(%r15), %rax
movl %edx, (%rax,%rcx,4)
movq 0x38(%r15), %rax
movq 0x10(%rax,%rbx), %rbx
testq %rbx, %rbx
je 0x4c0f
leaq 0x8(%rbx), %rsi
movq %r13, 0x40(%rsp)
movq %r13, %rdi
leaq 0x40(%rsp), %rdx
callq 0x35c0
movq (%rbx), %rbx
jmp 0x4bef
movq %r15, %rdi
leaq 0xc(%rsp), %rsi
callq 0x383e
movq (%rax), %rbx
movq %r15, %rdi
leaq 0xc(%rsp), %rsi
callq 0x383e
cmpq 0x8(%rax), %rbx
je 0x4c47
movslq (%rbx), %rax
movq 0x28(%rsp), %rcx
movl $0x0, (%rcx,%rax,4)
addq $0x4, %rbx
jmp 0x4c1f
xorl %eax, %eax
subl 0xc(%rsp), %eax
movl %eax, 0x40(%rsp)
movq %r15, %rdi
leaq 0x40(%rsp), %rsi
callq 0x3174
movq (%rax), %rbx
xorl %eax, %eax
subl 0xc(%rsp), %eax
movl %eax, 0x40(%rsp)
movq %r15, %rdi
leaq 0x40(%rsp), %rsi
callq 0x3174
cmpq 0x8(%rax), %rbx
je 0x4c93
movslq (%rbx), %rax
movq 0x28(%rsp), %rcx
movl $0x0, (%rcx,%rax,4)
addq $0x4, %rbx
jmp 0x4c61
xorl %ecx, %ecx
movl $0x1, %eax
movq %rax, 0x20(%rsp)
movl $0x4, %eax
testb %cl, %cl
je 0x4cd1
incq %r14
movq 0x38(%r15), %rax
movq 0x40(%r15), %rcx
subq %rax, %rcx
shrq $0x3, %rcx
imull $0xb6db6db7, %ecx, %ecx # imm = 0xB6DB6DB7
movslq %ecx, %rcx
cmpq %rcx, %r14
jl 0x499f
movl $0x4, %eax
cmpl $0x4, %eax
sete %bl
cmpl $0x1, 0x20(%rsp)
sete %dl
jmp 0x4ce3
movb $0x1, %bl
testb %bl, %bl
je 0x4cef
testb %dl, %dl
jne 0x4974
leaq 0xc0(%rsp), %rdi
callq 0x3de2
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x4d13
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movl %ebx, %eax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4d53
jmp 0x4d53
jmp 0x4d33
jmp 0x4d53
jmp 0x4d33
jmp 0x4d33
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x3de2
leaq 0x40(%rsp), %rdi
callq 0x3de2
jmp 0x4d56
jmp 0x4d53
jmp 0x4d53
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
callq 0x3de2
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x4d7a
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movq %rbx, %rdi
callq 0x2210