// File: /workspace/github_cpp_makefile_star2_O3/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 $0xe8, %rsp
movl %edx, 0xc(%rsp)
movq %rsi, 0x10(%rsp)
movq %rdi, %rbx
movq 0x40(%rdi), %rsi
subq 0x38(%rdi), %rsi
sarq $0x3, %rsi
movabsq $0x6db6db6db6db6db7, %r14 # imm = 0x6DB6DB6DB6DB6DB7
imulq %r14, %rsi
leaq 0xb0(%rsp), %r15
movl $0x0, (%r15)
leaq 0x20(%rsp), %rdi
leaq 0x40(%rsp), %rcx
movq %r15, %rdx
callq 0x4e3c
leaq 0xe0(%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 0x38(%rbx), %rax
movq 0x40(%rbx), %rsi
subq %rax, %rsi
sarq $0x3, %rsi
imulq %r14, %rsi
movb $0x1, %bpl
testl %esi, %esi
jle 0x4c10
leaq 0x38(%rbx), %rcx
movq %rcx, 0x38(%rsp)
leaq 0x40(%rsp), %r13
leaq 0x8(%rsp), %r12
movq 0x20(%rsp), %rcx
movq 0x50(%rbx), %rdx
movl %esi, %esi
xorl %edi, %edi
cmpl $0x0, (%rcx,%rdi,4)
je 0x4937
incq %rdi
cmpq %rsi, %rdi
jne 0x4924
jmp 0x4aad
movl $0x1, (%rcx,%rdi,4)
imulq $0x38, %rdi, %rbp
movq 0x10(%rax,%rbp), %r8
testq %r8, %r8
je 0x4ab5
xorl %r10d, %r10d
movl 0x8(%r8), %r11d
movl %r11d, %r14d
negl %r14d
cmovsl %r11d, %r14d
movl (%rdx,%r14,4), %r14d
testl %r14d, %r14d
je 0x4975
imull %r11d, %r14d
testl %r14d, %r14d
jle 0x4988
jmp 0x492a
movl %r11d, 0x8(%rsp)
movl %r11d, %r9d
testl %r10d, %r10d
movl $0x1, %r10d
jg 0x492a
movq (%r8), %r8
testq %r8, %r8
jne 0x4953
testl %r10d, %r10d
je 0x4ab5
movl %r9d, %eax
negl %eax
cmovsl %r9d, %eax
movl %eax, 0x78(%rsp)
movq 0x10(%rsp), %rdi
movq %rdi, 0x40(%rsp)
leaq 0x78(%rsp), %rsi
movq %r13, %rdx
callq 0x4fb8
movl 0x8(%rsp), %eax
movl %eax, %ecx
sarl $0x1f, %ecx
xorl %edx, %edx
testl %eax, %eax
setne %dl
orl %ecx, %edx
imull 0xc(%rsp), %edx
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
movq 0x50(%rbx), %rax
movl %edx, (%rax,%rcx,4)
movq 0x38(%rbx), %rax
movq 0x10(%rax,%rbp), %rbp
testq %rbp, %rbp
je 0x4a0a
leaq 0x8(%rbp), %rsi
movq %r15, 0x40(%rsp)
movq %r15, %rdi
movq %r13, %rdx
callq 0x356c
movq (%rbp), %rbp
jmp 0x49eb
movq %rbx, %rdi
movq %r12, %rsi
callq 0x37f8
movq (%rax), %rbp
movq %rbx, %rdi
movq %r12, %rsi
callq 0x37f8
cmpq 0x8(%rax), %rbp
je 0x4a3f
movslq (%rbp), %rax
movq 0x20(%rsp), %rcx
movl $0x0, (%rcx,%rax,4)
addq $0x4, %rbp
jmp 0x4a18
xorl %eax, %eax
subl 0x8(%rsp), %eax
movl %eax, 0x40(%rsp)
movq %rbx, %rdi
movq %r13, %rsi
callq 0x31c6
movq (%rax), %rbp
xorl %eax, %eax
subl 0x8(%rsp), %eax
movl %eax, 0x40(%rsp)
movq %rbx, %rdi
movq %r13, %rsi
callq 0x31c6
cmpq 0x8(%rax), %rbp
je 0x4a88
movslq (%rbp), %rax
movq 0x20(%rsp), %rcx
movl $0x0, (%rcx,%rax,4)
addq $0x4, %rbp
jmp 0x4a57
movq 0x38(%rbx), %rax
movq 0x40(%rbx), %rsi
subq %rax, %rsi
sarq $0x3, %rsi
movabsq $0x6db6db6db6db6db7, %rcx # imm = 0x6DB6DB6DB6DB6DB7
imulq %rcx, %rsi
testl %esi, %esi
jg 0x4917
movb $0x1, %bpl
jmp 0x4c10
leaq 0x70(%rsp), %rax
movq %rax, -0x30(%rax)
movl $0x1, %ecx
movq %rcx, -0x28(%rax)
xorps %xmm0, %xmm0
movups %xmm0, -0x20(%rax)
movl $0x3f800000, %edx       # imm = 0x3F800000
movl %edx, -0x10(%rax)
movups %xmm0, -0x8(%rax)
leaq 0xa8(%rsp), %rax
movq %rax, -0x30(%rax)
movq %rcx, -0x28(%rax)
movups %xmm0, -0x20(%rax)
movl %edx, -0x10(%rax)
movups %xmm0, -0x8(%rax)
movq 0xc0(%rsp), %r13
testq %r13, %r13
je 0x4bc6
leaq 0x18(%rsp), %r15
movslq 0x8(%r13), %rcx
negq %rcx
movq 0xb0(%rsp), %rdi
movq 0xb8(%rsp), %r8
movq %rcx, %rax
xorl %edx, %edx
divq %r8
movq (%rdi,%rdx,8), %rax
testq %rax, %rax
je 0x4b5e
movq %rdx, %rsi
movq (%rax), %r9
cmpl %ecx, 0x8(%r9)
je 0x4bb9
movq (%r9), %r9
testq %r9, %r9
je 0x4b5e
movslq 0x8(%r9), %rdi
movq %rdi, %rax
xorl %edx, %edx
divq %r8
cmpq %rsi, %rdx
jne 0x4b5e
cmpl %ecx, %edi
jne 0x4b3f
jmp 0x4bb9
leaq 0x8(%r13), %r12
movq %rbx, %rdi
movq %r12, %rsi
callq 0x37f8
movq 0x40(%rbx), %rcx
subq 0x38(%rbx), %rcx
shrq $0x3, %rcx
imull $0xb6db6db7, %ecx, %ecx # imm = 0xB6DB6DB7
movl %ecx, 0x18(%rsp)
movq 0x8(%rax), %rsi
cmpq 0x10(%rax), %rsi
je 0x4b99
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rax)
jmp 0x4ba4
movq %rax, %rdi
movq %r15, %rdx
callq 0x308a
leaq 0x78(%rsp), %rdi
movq %rdi, 0x18(%rsp)
movq %r12, %rsi
movq %r15, %rdx
callq 0x356c
movq (%r13), %r13
testq %r13, %r13
jne 0x4b0b
leaq 0x78(%rsp), %rsi
movq 0x38(%rsp), %rdi
callq 0x3016
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rax
testq %rax, %rax
je 0x4bfa
movq 0x50(%rbx), %rcx
movslq 0x8(%rax), %rdx
movl $0x0, (%rcx,%rdx,4)
movq (%rax), %rax
testq %rax, %rax
jne 0x4be7
leaq 0x78(%rsp), %rdi
callq 0x3d9a
leaq 0x40(%rsp), %rdi
callq 0x3d9a
xorl %ebp, %ebp
leaq 0xb0(%rsp), %rdi
callq 0x3d9a
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x4c34
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movl %ebp, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4c52
jmp 0x4c52
jmp 0x4c6f
jmp 0x4c6f
jmp 0x4c6f
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x3d9a
leaq 0x40(%rsp), %rdi
callq 0x3d9a
jmp 0x4c72
jmp 0x4c6f
jmp 0x4c6f
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
callq 0x3d9a
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x4c96
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movq %rbx, %rdi
callq 0x2210