// File: 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
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xc0(%rbp)
movl 0x214(%rax), %eax
incl %eax
movq %rsp, %rcx
movq %rcx, -0x10(%rbp)
movq %rax, %rdx
addq $0xf, %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0xb8(%rbp)
movq %rcx, %rsp
movq %rax, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movq -0xc0(%rbp), %rcx
movl -0x1c(%rbp), %eax
movl 0x214(%rcx), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jge 0x4693
jmp 0x4678
movq -0xb8(%rbp), %rax
movl -0x1c(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x1c(%rbp)
movslq %ecx, %rcx
movb $0x0, (%rax,%rcx)
jmp 0x465f
movq -0xc0(%rbp), %rdi
addq $0x218, %rdi            # imm = 0x218
callq 0x6180
movq %rax, -0x28(%rbp)
movq -0xc0(%rbp), %rdi
addq $0x218, %rdi            # imm = 0x218
callq 0x5f70
movq %rax, -0x30(%rbp)
leaq -0x28(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x61b0
testb $0x1, %al
jne 0x46d7
jmp 0x4aa4
leaq -0x28(%rbp), %rdi
callq 0x5fc0
movq %rax, %rcx
movq -0xb8(%rbp), %rax
movslq (%rcx), %rcx
testb $0x1, (%rax,%rcx)
je 0x46f8
jmp 0x4a8d
leaq -0x28(%rbp), %rdi
callq 0x5fc0
cmpl $0x6, 0x8(%rax)
jne 0x480a
leaq -0x28(%rbp), %rdi
movl $0x1, %esi
callq 0x61f0
movq %rax, -0x38(%rbp)
movq -0xc0(%rbp), %rdi
addq $0x218, %rdi            # imm = 0x218
callq 0x5f70
movq %rax, -0x40(%rbp)
leaq -0x38(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x61b0
testb $0x1, %al
jne 0x474a
jmp 0x4805
leaq -0x38(%rbp), %rdi
callq 0x5fc0
movl 0x4(%rax), %eax
movl %eax, -0xc4(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x5fc0
movq %rax, %rcx
movl -0xc4(%rbp), %eax
cmpl 0x4(%rcx), %eax
jne 0x47ef
leaq -0x38(%rbp), %rdi
callq 0x5fc0
cmpl $0x2, 0x8(%rax)
je 0x47ef
leaq -0x38(%rbp), %rdi
callq 0x5fc0
movq -0xb8(%rbp), %rcx
movq %rax, %rdx
movq -0xc0(%rbp), %rax
movslq (%rdx), %rdx
movb $0x1, (%rcx,%rdx)
movq 0x260(%rax), %rax
movq %rax, -0xd8(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x5fc0
movq %rax, %rcx
movq -0xd8(%rbp), %rax
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0xd0(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x5fc0
movq %rax, %rcx
movq -0xd0(%rbp), %rax
movslq (%rcx), %rcx
movl $0x1, (%rax,%rcx,4)
jmp 0x47f1
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
callq 0x6230
movq %rax, -0x48(%rbp)
jmp 0x471d
jmp 0x4a89
leaq -0x28(%rbp), %rdi
movl $0x1, %esi
callq 0x6270
movq %rax, -0x50(%rbp)
movq -0xc0(%rbp), %rdi
addq $0x218, %rdi            # imm = 0x218
callq 0x6180
movq %rax, -0x58(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x61b0
testb $0x1, %al
jne 0x4846
jmp 0x4888
leaq -0x50(%rbp), %rdi
callq 0x5fc0
cmpl $0x1, 0x8(%rax)
je 0x4873
leaq -0x50(%rbp), %rdi
callq 0x5fc0
cmpl $0x2, 0x8(%rax)
je 0x4873
leaq -0x50(%rbp), %rdi
callq 0x5fc0
cmpl $0x3, 0x8(%rax)
jne 0x4875
jmp 0x4888
jmp 0x4877
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
callq 0x62b0
movq %rax, -0x60(%rbp)
jmp 0x481c
movq -0xc0(%rbp), %rdi
addq $0x218, %rdi            # imm = 0x218
callq 0x6180
movq %rax, -0x68(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x62f0
testb $0x1, %al
jne 0x48b2
jmp 0x48d1
movq 0xa71f(%rip), %rdi      # 0xefd8
leaq 0x5821(%rip), %rsi      # 0xa0e1
callq 0x3260
movl $0x1, -0x6c(%rbp)
jmp 0x4aab
movq -0x50(%rbp), %rax
movq %rax, -0x78(%rbp)
movl $0x1, -0x7c(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x5fc0
cmpl $0x2, 0x8(%rax)
jne 0x494f
movl $0x2, -0x7c(%rbp)
movq -0xc0(%rbp), %rdi
addq $0x218, %rdi            # imm = 0x218
callq 0x6180
movq %rax, -0x88(%rbp)
leaq -0x78(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x61b0
testb $0x1, %al
jne 0x4926
jmp 0x494d
leaq -0x78(%rbp), %rdi
callq 0x5fc0
cmpl $0x1, 0x8(%rax)
jne 0x4937
jmp 0x494d
jmp 0x4939
leaq -0x78(%rbp), %rdi
xorl %esi, %esi
callq 0x62b0
movq %rax, -0x90(%rbp)
jmp 0x48f6
jmp 0x494f
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
callq 0x6230
movq %rax, -0x98(%rbp)
movq -0xc0(%rbp), %rdi
addq $0x218, %rdi            # imm = 0x218
callq 0x5f70
movq %rax, -0xa0(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x61b0
testb $0x1, %al
jne 0x4994
jmp 0x4a87
leaq -0x50(%rbp), %rdi
callq 0x5fc0
movq %rax, %rcx
movq -0xb8(%rbp), %rax
movslq (%rcx), %rcx
testb $0x1, (%rax,%rcx)
je 0x49b5
jmp 0x4a87
leaq -0x50(%rbp), %rdi
callq 0x5fc0
movl 0x4(%rax), %eax
movl %eax, -0xdc(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x5fc0
movq %rax, %rcx
movl -0xdc(%rbp), %eax
movl 0x4(%rcx), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jne 0x4a6e
leaq -0x50(%rbp), %rdi
callq 0x5fc0
cmpl $0x2, 0x8(%rax)
je 0x4a6e
leaq -0x50(%rbp), %rdi
callq 0x5fc0
movq -0xb8(%rbp), %rcx
movq %rax, %rdx
movq -0xc0(%rbp), %rax
movslq (%rdx), %rdx
movb $0x1, (%rcx,%rdx)
movl -0x7c(%rbp), %ecx
movl %ecx, -0xec(%rbp)
movq 0x260(%rax), %rax
movq %rax, -0xf8(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x5fc0
movq %rax, %rcx
movq -0xf8(%rbp), %rax
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0xe8(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x5fc0
movl -0xec(%rbp), %edx
movq %rax, %rcx
movq -0xe8(%rbp), %rax
movslq (%rcx), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x4a70
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
callq 0x6230
movq %rax, -0xa8(%rbp)
jmp 0x4961
jmp 0x4a89
jmp 0x4a8b
jmp 0x4a8d
leaq -0x28(%rbp), %rdi
xorl %esi, %esi
callq 0x6230
movq %rax, -0xb0(%rbp)
jmp 0x46aa
movl $0x0, -0x6c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, %rsp
movq %rbp, %rsp
popq %rbp
retq
nopw (%rax,%rax)