// File: /workspace/github_cpp_makefile_star2_O3/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
subq $0x18, %rsp
movq %rdi, %rbx
movl 0x214(%rdi), %eax
leal 0x1(%rax), %edx
movq %rsp, %r14
leaq 0xf(%rdx), %rcx
andq $-0x10, %rcx
subq %rcx, %r14
movq %r14, %rsp
testl %eax, %eax
js 0x2eb6
movq %r14, %rdi
xorl %esi, %esi
callq 0x2110
movq 0x218(%rbx), %rax
movq 0x220(%rbx), %rcx
cmpq %rcx, %rax
je 0x302e
leaq 0x8(%rax), %rdx
movq $-0xc, %rsi
xorl %edi, %edi
movq %rax, %r8
movslq (%r8), %r9
cmpb $0x0, (%r14,%r9)
jne 0x3015
cmpl $0x6, 0x8(%r8)
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r11
jne 0x2f45
leaq 0xc(%r8), %r9
cmpq %rcx, %r9
je 0x3015
movq 0x260(%rbx), %r10
movl 0x4(%r9), %r11d
cmpl 0x4(%r8), %r11d
jne 0x2f37
cmpl $0x2, 0x8(%r9)
je 0x2f37
movslq (%r9), %r11
movb $0x1, (%r14,%r11)
movslq (%r8), %r15
movq (%r10,%r15,8), %r15
movl $0x1, (%r15,%r11,4)
addq $0xc, %r9
cmpq %rcx, %r9
jne 0x2f0f
jmp 0x3015
cmpq $0xc, %r11
je 0x303d
movq %r12, %r10
movq %r15, %r9
movl -0x4(%rax,%r11), %r13d
decl %r13d
addq $-0xc, %r11
addq $-0xc, %r12
addq $-0xc, %r15
cmpl $0x2, %r13d
ja 0x2f45
testq %r11, %r11
je 0x303d
cmpl $0x2, 0x8(%rax,%r11)
jne 0x2f9a
cmpl $0x1, 0x8(%rax,%r10)
je 0x2fa7
addq $-0xc, %r10
jne 0x2f80
movl $0x2, -0x2c(%rbp)
movq %rax, %r10
jmp 0x2fb1
leaq (%rax,%r11), %r10
movl $0x1, -0x2c(%rbp)
jmp 0x2fb1
addq %rax, %r10
movl $0x2, -0x2c(%rbp)
addq %rax, %r11
addq $0xc, %r11
cmpq %rcx, %r11
je 0x3015
movq 0x260(%rbx), %r11
movq %r11, -0x38(%rbp)
movslq -0x8(%r9), %r13
cmpb $0x0, (%r14,%r13)
jne 0x3015
leaq -0x8(%r9), %r12
movl 0x4(%r10), %r15d
incl %r15d
cmpl %r15d, 0x4(%r12)
jne 0x3008
cmpl $0x2, (%r9)
je 0x3008
movb $0x1, (%r14,%r13)
movslq (%r10), %r15
movq -0x38(%rbp), %r11
movq (%r11,%r15,8), %r15
movq %rbx, %r11
movl -0x2c(%rbp), %ebx
movl %ebx, (%r15,%r13,4)
movq %r11, %rbx
addq $0xc, %r9
addq $0xc, %r12
cmpq %rcx, %r12
jne 0x2fc8
addq $0xc, %r8
addq $0xc, %rdi
addq $0xc, %rsi
addq $0xc, %rdx
cmpq %rcx, %r8
jne 0x2edd
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x5f94(%rip), %rdi      # 0x8fd8
leaq 0x3096(%rip), %rsi      # 0x60e1
movl $0x22, %edx
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2200
nop