// File: metastableB[P]Program-Dependence-Graph-Creator/./pdg.cpp
// Function: PDG::get_var(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, Line)
std::vector<std::string>
PDG::get_var(std::string s, struct Line it) {
	std::vector<std::string> var;
	/*
	 * If an assignment statement,
	 * the string to the left of an = is a variable.
	 * else search for existing variables in the string
	 * make sure they are not substrings and add tit */
	 s= " " + s + " ";
	 int pos = -1;
	 if(it.type == Line_Type::SCOPE_CLOSE) return var;
	 else if(it.type == Line_Type::ASSIGNMENT){
	 	//std::cout << "s" << s <<std::endl;
	 	int m = s.find("=");
	 	pos = m;
	 	m -= 1;
	 	int cnt = 0;
	 	while(m>=0 && std::isspace(s[m])) m--;
	 	while(m>=0 && std::isalnum(s[m])) {m--;cnt++;}
	 	if(m < 0){ 
	 		std::cout << "ERROR Extracting variable " << 
	 	 			"from assignment L : " << it.line_no << std::endl;
	 	 	return var;
	 	 }
	 	 var.push_back(s.substr(++m,cnt));
	 } 
	 for(auto v:variable_map){
	 	while((pos = s.find(v.first,pos+1)) != std::string::npos) {
	 		/*
	 		 * we might have a match. This can be a
	 		 * false positive as well.
	 		 */
	 		 if(!std::isalnum(s[pos-1]) && !std::isalnum(s[pos+v.first.length()])){
	 		 	/* WE have a variable people! */
	 		 	var.push_back(v.first);
	 		 	break;
	 		 }
	 	}
	 }
	 return var;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x170, %rsp            # imm = 0x170
movq %rdx, -0x108(%rbp)
movq %rdi, -0x120(%rbp)
movq %rdi, %rax
movq %rax, -0x118(%rbp)
movq %rdi, -0x8(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x20(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x10(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x18(%rbp)
movq %rsi, -0x30(%rbp)
movq %rdx, -0x38(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x110(%rbp)
movb $0x0, -0x39(%rbp)
callq 0x6850
movq -0x108(%rbp), %rdx
leaq 0x4d23(%rip), %rsi      # 0xa10a
leaq -0x80(%rbp), %rdi
callq 0x6030
jmp 0x53f2
leaq 0x4d11(%rip), %rdx      # 0xa10a
leaq -0x60(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x5fe0
jmp 0x5408
movq -0x108(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x3340
leaq -0x60(%rbp), %rdi
callq 0x31a0
leaq -0x80(%rbp), %rdi
callq 0x31a0
movl $0xffffffff, -0x90(%rbp) # imm = 0xFFFFFFFF
cmpl $0x4, -0x10(%rbp)
jne 0x5484
movb $0x1, -0x39(%rbp)
movl $0x1, -0x94(%rbp)
jmp 0x5833
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x5855
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x31a0
jmp 0x5855
cmpl $0x0, -0x10(%rbp)
jne 0x569f
movq -0x108(%rbp), %rdi
leaq 0x4c41(%rip), %rsi      # 0xa0dd
xorl %eax, %eax
movl %eax, %edx
callq 0x34d0
movl %eax, -0x98(%rbp)
movl -0x98(%rbp), %eax
movl %eax, -0x90(%rbp)
movl -0x98(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x98(%rbp)
movl $0x0, -0x9c(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x98(%rbp)
movb %al, -0x121(%rbp)
jl 0x5518
movq -0x108(%rbp), %rdi
movslq -0x98(%rbp), %rsi
callq 0x34e0
movq %rax, -0x130(%rbp)
jmp 0x54fd
movq -0x130(%rbp), %rax
movsbl (%rax), %edi
callq 0x3080
cmpl $0x0, %eax
setne %al
movb %al, -0x121(%rbp)
movb -0x121(%rbp), %al
testb $0x1, %al
jne 0x5524
jmp 0x5535
movl -0x98(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x98(%rbp)
jmp 0x54d0
jmp 0x5537
xorl %eax, %eax
cmpl $0x0, -0x98(%rbp)
movb %al, -0x131(%rbp)
jl 0x557f
movq -0x108(%rbp), %rdi
movslq -0x98(%rbp), %rsi
callq 0x34e0
movq %rax, -0x140(%rbp)
jmp 0x5564
movq -0x140(%rbp), %rax
movsbl (%rax), %edi
callq 0x3290
cmpl $0x0, %eax
setne %al
movb %al, -0x131(%rbp)
movb -0x131(%rbp), %al
testb $0x1, %al
jne 0x558b
jmp 0x55ab
movl -0x98(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x98(%rbp)
movl -0x9c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x9c(%rbp)
jmp 0x5537
cmpl $0x0, -0x98(%rbp)
jge 0x562c
movq 0x9a1d(%rip), %rdi      # 0xefd8
leaq 0x4b95(%rip), %rsi      # 0xa157
callq 0x3260
movq %rax, -0x148(%rbp)
jmp 0x55d0
movq -0x148(%rbp), %rdi
leaq 0x4b94(%rip), %rsi      # 0xa172
callq 0x3260
movq %rax, -0x150(%rbp)
jmp 0x55ec
movq -0x150(%rbp), %rdi
movl -0x18(%rbp), %esi
callq 0x3460
movq %rax, -0x158(%rbp)
jmp 0x5604
movq -0x158(%rbp), %rdi
movq 0x99b6(%rip), %rsi      # 0xefc8
callq 0x32c0
jmp 0x5619
movb $0x1, -0x39(%rbp)
movl $0x1, -0x94(%rbp)
jmp 0x5833
movq -0x108(%rbp), %rsi
movl -0x98(%rbp), %eax
incl %eax
movl %eax, -0x98(%rbp)
movslq %eax, %rdx
movslq -0x9c(%rbp), %rcx
leaq -0xc0(%rbp), %rdi
callq 0x32a0
jmp 0x5659
movq -0x120(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x6870
jmp 0x566e
leaq -0xc0(%rbp), %rdi
callq 0x31a0
jmp 0x569f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x31a0
jmp 0x5855
jmp 0x56a1
movq -0x110(%rbp), %rax
addq $0x230, %rax            # imm = 0x230
movq %rax, -0xc8(%rbp)
movq -0xc8(%rbp), %rdi
callq 0x68a0
movq %rax, -0xd0(%rbp)
movq -0xc8(%rbp), %rdi
callq 0x68d0
movq %rax, -0xd8(%rbp)
leaq -0xd0(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x6900
testb $0x1, %al
jne 0x56f7
jmp 0x5825
leaq -0xd0(%rbp), %rdi
callq 0x6930
movq %rax, %rsi
leaq -0x100(%rbp), %rdi
callq 0x6950
jmp 0x5714
jmp 0x5716
movq -0x108(%rbp), %rdi
leaq -0x100(%rbp), %rsi
movl -0x90(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdx
callq 0x34f0
movl %eax, -0x90(%rbp)
cltq
cmpq $-0x1, %rax
je 0x5808
movq -0x108(%rbp), %rdi
movl -0x90(%rbp), %eax
decl %eax
movslq %eax, %rsi
callq 0x34e0
movq %rax, -0x160(%rbp)
jmp 0x5767
movq -0x160(%rbp), %rax
movsbl (%rax), %edi
callq 0x3290
cmpl $0x0, %eax
jne 0x5803
movslq -0x90(%rbp), %rax
movq %rax, -0x170(%rbp)
leaq -0x100(%rbp), %rdi
callq 0x33e0
movq -0x170(%rbp), %rsi
movq -0x108(%rbp), %rdi
addq %rax, %rsi
callq 0x34e0
movq %rax, -0x168(%rbp)
jmp 0x57b8
movq -0x168(%rbp), %rax
movsbl (%rax), %edi
callq 0x3290
cmpl $0x0, %eax
jne 0x5803
movq -0x120(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x6990
jmp 0x57e1
jmp 0x5808
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x100(%rbp), %rdi
callq 0x6a00
jmp 0x5855
jmp 0x5716
leaq -0x100(%rbp), %rdi
callq 0x6a00
leaq -0xd0(%rbp), %rdi
callq 0x6a20
jmp 0x56db
movb $0x1, -0x39(%rbp)
movl $0x1, -0x94(%rbp)
testb $0x1, -0x39(%rbp)
jne 0x5845
movq -0x120(%rbp), %rdi
callq 0x67f0
movq -0x118(%rbp), %rax
addq $0x170, %rsp            # imm = 0x170
popq %rbp
retq
movq -0x120(%rbp), %rdi
callq 0x67f0
movq -0x88(%rbp), %rdi
callq 0x3470
nopl (%rax)