// File: /workspace/github_cpp_makefile_star2_O1/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
movq %rdi, %rbx
movl 0x214(%rdi), %edx
leal 0x1(%rdx), %eax
movq %rsp, %r14
addq $0xf, %rax
andq $-0x10, %rax
subq %rax, %r14
movq %r14, %rsp
testl %edx, %edx
js 0x2ee0
incq %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x2110
movq 0x218(%rbx), %r13
movq 0x220(%rbx), %rax
cmpq %rax, %r13
je 0x3028
movslq (%r13), %rcx
cmpb $0x0, (%r14,%rcx)
jne 0x301f
cmpl $0x6, 0x8(%r13)
jne 0x2f55
leaq 0xc(%r13), %rcx
cmpq %rax, %rcx
je 0x301f
movq 0x260(%rbx), %rdx
movl 0x4(%rcx), %esi
cmpl 0x4(%r13), %esi
jne 0x2f47
cmpl $0x2, 0x8(%rcx)
je 0x2f47
movslq (%rcx), %rsi
movb $0x1, (%r14,%rsi)
movslq (%r13), %rdi
movq (%rdx,%rdi,8), %rdi
movl $0x1, (%rdi,%rsi,4)
addq $0xc, %rcx
cmpq %rax, %rcx
jne 0x2f21
jmp 0x301f
movq 0x218(%rbx), %r15
leaq 0x8(%r13), %rsi
movq %r13, %rdx
movq %rdx, %rdi
movq %rsi, %rcx
addq $-0xc, %rdx
cmpq %r15, %rdx
je 0x2f83
movl -0x4(%rdi), %r8d
decl %r8d
leaq -0xc(%rcx), %rsi
cmpl $0x2, %r8d
ja 0x2f63
leaq -0xc(%rdi), %r12
cmpq %r15, %r12
je 0x3002
movl $0x1, %edx
cmpl $0x2, -0x4(%rdi)
movq %r12, %rsi
jne 0x2fb6
movl $0x2, %edx
movq %r12, %rsi
cmpq %r15, %r12
je 0x2fb6
cmpl $0x1, 0x8(%rsi)
je 0x2fb6
addq $-0xc, %rsi
cmpq %r15, %rsi
jne 0x2fa7
cmpq %rax, %rdi
je 0x301a
movq 0x260(%rbx), %rdi
movslq -0x8(%rcx), %r9
cmpb $0x0, (%r14,%r9)
jne 0x301a
leaq -0x8(%rcx), %r8
movl 0x4(%rsi), %r10d
incl %r10d
cmpl %r10d, 0x4(%r8)
jne 0x2ff3
cmpl $0x2, (%rcx)
je 0x2ff3
movb $0x1, (%r14,%r9)
movslq (%rsi), %r10
movq (%rdi,%r10,8), %r10
movl %edx, (%r10,%r9,4)
addq $0xc, %rcx
addq $0xc, %r8
cmpq %rax, %r8
jne 0x2fc2
jmp 0x301a
movl $0x22, %edx
movq 0x5fca(%rip), %rdi      # 0x8fd8
leaq 0x30cc(%rip), %rsi      # 0x60e1
callq 0x2200
cmpq %r15, %r12
je 0x3028
addq $0xc, %r13
jmp 0x2ee7
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop