// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Correct.cpp
// Function: Merge_DAGCon(Graph*)
void Merge_DAGCon(Graph* DAGCon)
{
    ///using the length of edge representing if it has been visited
    ///in default, the length of edge is 0
    RSet iter_node, iter_edge;
    long long flag;

    Node* currentNode;
    Node* outNode;
    Edge* edge;
    Edge* e_forward;
    Edge* e_backward;

    // int num_way = Real_Length(Output_Edges(G_Node(*DAGCon, DAGCon->s_start_nodeID)));
    // if(num_way > 2)
    // {
    //     print_graph(DAGCon);
    // }
    

    
    ///at begining, only the start node has no in-node
    currentNode = &(G_Node(*DAGCon, DAGCon->s_start_nodeID));
    Push_Node(DAGCon, &currentNode);
    

    
    while (Pop_Node(DAGCon, &currentNode))
    {
        ///merge in-node
        Merge_In_Nodes(DAGCon, currentNode);
        ///merge out-node
        Merge_Out_Nodes(DAGCon, currentNode);

        clear_RSet(&iter_edge);
        ///for all out-edges of currentNode, set as visited
        while (getOutputEdges(&iter_edge, DAGCon, currentNode, &edge))
        {
            get_bi_direction_edges(DAGCon, edge, &e_forward, &e_backward);
            Visit(*e_forward) = 1;
            Visit(*e_backward) = 1;
        }
        


        ///check all out-node of currentNode
        clear_RSet(&iter_node);
        while(getOutputNodes(&iter_node, DAGCon, currentNode, &outNode))
        {

            ///for each outNode, check if all in-edges have been visited
            flag = 0;
            clear_RSet(&iter_edge);
            while (getInputEdges(&iter_edge, DAGCon, outNode, &edge))
            {
                if(Visit(*edge) == 0)
                {
                    flag = 1;
                    break;
                }
            }
            //if all in-edges of Out_node have already been visited, push it to queue
            if(flag == 0)
            {
                Push_Node(DAGCon, &outNode);
            }
        }
    }



    // if(num_way > 2)
    // {
    //     print_graph(DAGCon);
    //     fprintf(stderr, "****************************note*****************\n\n");
    // }


    ///debug_DAGCon(DAGCon);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0xa8(%rdi), %rax
shlq $0x7, %rax
movq 0x18(%rdi), %rcx
movq 0x78(%rdi), %r15
movq (%rcx,%rax), %r14
movq 0x88(%rdi), %rsi
cmpq %rsi, %r15
jl 0x4d16d
movq 0x70(%rbx), %rax
testq %rax, %rax
je 0x4d138
subq %rax, %r15
leaq (,%r15,8), %rdx
movq 0x90(%rbx), %rdi
leaq (%rdi,%rax,8), %rsi
cmpq %rax, %r15
jle 0x4d15c
callq 0x2360
jmp 0x4d161
leaq (%rsi,%rsi), %rax
movq %rax, 0x88(%rbx)
movq 0x90(%rbx), %rdi
shlq $0x4, %rsi
callq 0x2370
movq %rax, 0x90(%rbx)
jmp 0x4d16d
callq 0x2160
movq $0x0, 0x70(%rbx)
movq %r15, 0x78(%rbx)
movq 0x78(%rbx), %rax
movq 0x90(%rbx), %rcx
movq %r14, (%rcx,%rax,8)
incq 0x78(%rbx)
movl $0x1, %r15d
movq 0x70(%rbx), %rax
movq 0x78(%rbx), %rcx
movq $-0x1, %r14
cmpq %rcx, %rax
je 0x4d1ad
movq 0x90(%rbx), %rdx
movq (%rdx,%rax,8), %r14
leaq 0x1(%rax), %rdx
movq %rdx, 0x70(%rbx)
cmpq %rcx, %rax
je 0x4d43a
shlq $0x7, %r14
addq 0x18(%rbx), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c618
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4be58
movq %r14, (%rsp)
movq 0x50(%r14), %rax
leaq -0x1(%rax), %rcx
xorl %edx, %edx
movb $0x1, %sil
cmpq %rax, %rdx
jge 0x4d247
movq (%rsp), %rsi
movq 0x40(%rsi), %rdi
imulq $0x38, %rdx, %r8
movb $0x1, %sil
cmpq $-0x1, 0x8(%rdi,%r8)
je 0x4d206
movb $0x1, %r8b
jmp 0x4d226
addq %rdi, %r8
addq $0x40, %r8
cmpq %rdx, %rcx
je 0x4d244
incq %rdx
cmpq $-0x1, (%r8)
leaq 0x38(%r8), %r8
je 0x4d20d
cmpq %rax, %rdx
setl %r8b
testb %r8b, %r8b
je 0x4d247
imulq $0x38, %rdx, %r8
cmpq $-0x1, 0x8(%rdi,%r8)
je 0x4d247
addq %r8, %rdi
incq %rdx
xorl %esi, %esi
movq %rdi, %r13
jmp 0x4d247
movq %rax, %rdx
testb %sil, %sil
jne 0x4d2b4
movq (%r13), %r11
movq 0x8(%r13), %rsi
movq 0x28(%r13), %r9
movq 0x18(%rbx), %r8
movq %r11, %rdi
shlq $0x7, %rdi
leaq (%r8,%rdi), %r10
addq $0x40, %r10
cmpq 0x10(%r10), %r9
jae 0x4d292
movq (%r10), %rdi
imulq $0x38, %r9, %r14
cmpq %r11, (%rdi,%r14)
jne 0x4d292
addq %r14, %rdi
cmpq %rsi, 0x8(%rdi)
jne 0x4d292
shlq $0x7, %rsi
imulq $0x38, 0x30(%r13), %r9
jmp 0x4d2a2
imulq $0x38, 0x30(%r13), %rdi
addq (%r10), %rdi
shlq $0x7, %rsi
imulq $0x38, %r9, %r9
addq 0x60(%r8,%rsi), %r9
movq %r15, 0x20(%rdi)
movq %r15, 0x20(%r9)
jmp 0x4d1e2
xorl %ebp, %ebp
movq (%rsp), %r9
movq 0x50(%r9), %rdx
movb $0x1, %al
cmpq %rdx, %rbp
jge 0x4d31d
movq 0x40(%r9), %rsi
imulq $0x38, %rbp, %rdi
movq 0x8(%rsi,%rdi), %rcx
movb $0x1, %al
cmpq $-0x1, %rcx
je 0x4d2de
movb $0x1, %dl
jmp 0x4d304
addq %rdi, %rsi
addq $0x40, %rsi
leaq -0x1(%rdx), %rdi
cmpq %rbp, %rdi
je 0x4d31a
movq (%rsi), %rcx
addq $0x38, %rsi
incq %rbp
cmpq $-0x1, %rcx
je 0x4d2e9
cmpq %rdx, %rbp
setl %dl
testb %dl, %dl
je 0x4d31d
shlq $0x7, %rcx
addq 0x18(%rbx), %rcx
incq %rbp
xorl %eax, %eax
movq %rcx, %r12
jmp 0x4d31d
movq %rdx, %rbp
testb %al, %al
jne 0x4d42f
movq 0x70(%r12), %rax
leaq -0x1(%rax), %rcx
xorl %edx, %edx
movb $0x1, %sil
cmpq %rax, %rdx
jge 0x4d392
movq 0x60(%r12), %rdi
imulq $0x38, %rdx, %r8
movb $0x1, %sil
cmpq $-0x1, 0x8(%rdi,%r8)
je 0x4d351
movb $0x1, %r8b
jmp 0x4d371
addq %rdi, %r8
addq $0x40, %r8
cmpq %rdx, %rcx
je 0x4d38f
incq %rdx
cmpq $-0x1, (%r8)
leaq 0x38(%r8), %r8
je 0x4d358
cmpq %rax, %rdx
setl %r8b
testb %r8b, %r8b
je 0x4d392
imulq $0x38, %rdx, %r8
cmpq $-0x1, 0x8(%rdi,%r8)
je 0x4d392
addq %r8, %rdi
incq %rdx
xorl %esi, %esi
movq %rdi, %r13
jmp 0x4d392
movq %rax, %rdx
testb %sil, %sil
jne 0x4d3a3
cmpq $0x0, 0x20(%r13)
jne 0x4d330
jmp 0x4d2ba
movq (%r12), %r15
movq 0x78(%rbx), %r14
movq 0x88(%rbx), %rsi
cmpq %rsi, %r14
jl 0x4d417
movq 0x70(%rbx), %rax
testq %rax, %rax
je 0x4d3e2
subq %rax, %r14
leaq (,%r14,8), %rdx
movq 0x90(%rbx), %rdi
leaq (%rdi,%rax,8), %rsi
cmpq %rax, %r14
jle 0x4d406
callq 0x2360
jmp 0x4d40b
leaq (%rsi,%rsi), %rax
movq %rax, 0x88(%rbx)
movq 0x90(%rbx), %rdi
shlq $0x4, %rsi
callq 0x2370
movq %rax, 0x90(%rbx)
jmp 0x4d417
callq 0x2160
movq $0x0, 0x70(%rbx)
movq %r14, 0x78(%rbx)
movq 0x78(%rbx), %rax
movq 0x90(%rbx), %rcx
movq %r15, (%rcx,%rax,8)
incq 0x78(%rbx)
jmp 0x4d2b6
movl $0x1, %r15d
jmp 0x4d186
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq