// File: /workspace/github_cpp_makefile_star2_O2/metastableB[P]Program-Dependence-Graph-Creator/./pdg.cpp
// Function: PDG::cdg()
void PDG::cdg(){
 	bool added[total_lines+1];
 	for(int i = 0;i < total_lines + 1; added[i++]=false);
 	for(auto i = program_map.begin();i!= program_map.end();i++){
 		if(added[i->line_no]) continue;
 		else if(i->type == Line_Type::BEGIN){
 			for(auto j = i + 1; j != program_map.end(); j++){
 				if(j->scope == i->scope && j->type != Line_Type::ELSE){
 					added[j->line_no] = true;
 					g_cdg[i->line_no][j->line_no] = 1;
 				}
 			}		
 		} else{
 			/* First non added statement. Find the sub block
 			 * this statement belongs to and, evaluate the
 			 * truth of that statement and for that value
 			 * add this to the node
 			 */
 			 auto j = i - 1;
 			 for(; j!= program_map.begin();j--)
 			 	if(j->type ==Line_Type::IF || j->type==Line_Type::ELSE || j->type == Line_Type::WHILE) break;
 			 if(j== program_map.begin()){
 			 	std::cout << "WOW WOW! Something weird happened\n";
 			 	return ;
 			 }
 			 auto k = j;
 			 int tr = 1;
 			 if(k->type == Line_Type::ELSE) {
 			 	tr = 2;
 			 	for(; k!=program_map.begin();k--)
 			 		if(k->type == Line_Type::IF) break;
 			 }
 			 j++;
 			 for(;j !=program_map.end();j++){
 			 	if(added[j->line_no]) break;
 			 	if(j->scope == k->scope + 1 && j->type != Line_Type::ELSE){
 			 		added[j->line_no] = true;
 			 		g_cdg[k->line_no][j->line_no] = tr;
 			 	}
 			 }
 		}
 	}
 }

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movslq 0x214(%rdi), %rcx
leal 0x1(%rcx), %edx
movq %rsp, %rax
addq $0xf, %rdx
andq $-0x10, %rdx
subq %rdx, %rax
movq %rax, %rsp
xorl %edx, %edx
cmpq %rcx, %rdx
jg 0x2c87
movb $0x0, (%rax,%rdx)
incq %rdx
jmp 0x2c79
movq 0x218(%rdi), %rcx
movq 0x220(%rdi), %rdx
leaq 0xc(%rcx), %rsi
pushq $-0xc
popq %r8
xorl %r9d, %r9d
movq %rcx, %rbx
cmpq %rdx, %rbx
je 0x2dd9
movslq (%rbx), %r10
cmpb $0x0, (%rax,%r10)
je 0x2cc8
addq $0xc, %rbx
addq $0xc, %r9
addq $0xc, %r8
addq $0xc, %rsi
jmp 0x2ca3
cmpl $0x6, 0x8(%rbx)
movq %r8, %r10
movq %r9, %r15
jne 0x2d11
movq 0x260(%rdi), %r14
movq %rsi, %r15
cmpq %rdx, %r15
je 0x2cb6
movl 0x4(%r15), %r10d
cmpl 0x4(%rbx), %r10d
jne 0x2d0b
cmpl $0x2, 0x8(%r15)
je 0x2d0b
movslq (%r15), %r10
movb $0x1, (%rax,%r10)
movslq (%rbx), %r12
movq (%r14,%r12,8), %r12
movl $0x1, (%r12,%r10,4)
addq $0xc, %r15
jmp 0x2cde
cmpq $0xc, %r15
je 0x2db8
movq %r10, %r14
movl -0x4(%rcx,%r15), %r12d
decl %r12d
addq $-0xc, %r15
addq $-0xc, %r10
cmpl $0x2, %r12d
ja 0x2d11
testq %r15, %r15
je 0x2db8
cmpl $0x2, 0x8(%rcx,%r15)
jne 0x2d54
testq %r14, %r14
je 0x2d5c
cmpl $0x1, 0x8(%rcx,%r14)
je 0x2d61
addq $-0xc, %r14
jmp 0x2d41
leaq (%rcx,%r15), %r14
pushq $0x1
jmp 0x2d66
movq %rcx, %r14
jmp 0x2d64
addq %rcx, %r14
pushq $0x2
popq %r12
addq %rcx, %r15
addq $0xc, %r15
movq 0x260(%rdi), %r13
cmpq %rdx, %r15
je 0x2cb6
movslq (%r15), %r10
cmpb $0x0, (%rax,%r10)
jne 0x2cb6
movl 0x4(%r14), %r11d
incl %r11d
cmpl %r11d, 0x4(%r15)
jne 0x2db2
cmpl $0x2, 0x8(%r15)
je 0x2db2
movb $0x1, (%rax,%r10)
movslq (%r14), %r11
movq (%r13,%r11,8), %r11
movl %r12d, (%r11,%r10,4)
addq $0xc, %r15
jmp 0x2d76
movq 0x5219(%rip), %rdi      # 0x7fd8
leaq 0x231b(%rip), %rsi      # 0x50e1
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x21b0
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq