// File: parth-shel[P]xpac/client.cpp
// Function: calculate_indegrees()
void calculate_indegrees() {
	indegree_map.clear();
	//Adding all the installed packages to the map:
	for(auto itr = user_installed_list.begin(); itr!=user_installed_list.end(); itr++) {
		indegree_map.insert(std::make_pair(itr->first,0));
	}

	//Performing a breadth first search on the graph to see all reachable packages:
	std::queue<std::string> bfs_indegree_queue;
	std::unordered_set<std::string> indegree_visited;

	//Pushing the first element into the bfs_queue:
	bfs_indegree_queue.push("base");
	indegree_visited.insert("base");

	//Performing the bfs here:
	while(!bfs_indegree_queue.empty()){
		std::string next_pkg_name = bfs_indegree_queue.front();
		bfs_indegree_queue.pop();

		std::string next_pkg_filepath = metadata_dir + "/." + next_pkg_name + ".metadata";
		metadata * next_pkg = metadata::get_package(next_pkg_filepath);

		//Getting the dependency list of the next package:
		std::vector<std::string> * next_pkg_dep_list = next_pkg->get_dep_list();

		for(auto itr = next_pkg_dep_list->begin(); itr!=next_pkg_dep_list->end(); itr++) {
			
			//Updating indegree values in the map:
			auto indegree_find = indegree_map.find(*itr);
			if(indegree_find != indegree_map.end()) {
				if(next_pkg_name.compare("base") == 0) { //One degree depth
					indegree_find->second++;
				}
				else{
					indegree_find->second += 2;
				}
			}

			//Finding whether it has already been visited:
			auto found = indegree_visited.find(*itr);
			//If not found then:
			if(found == indegree_visited.end()) {
				indegree_visited.insert(*itr);
				bfs_indegree_queue.push(*itr);
			}
		}
	}

	//Testing calculating indegrees:
	/*for(auto itr=indegree_map.begin(); itr!=indegree_map.end(); itr++){
		std::cout<<"Node: "<<itr->first<<" "<<"Value: "<<itr->second<<std::endl;
	}*/
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2c0, %rsp            # imm = 0x2C0
leaq 0x185ee(%rip), %rdi     # 0x1e5e0
callq 0x9880
leaq 0x18672(%rip), %rdi     # 0x1e670
callq 0x9380
movq %rax, -0x8(%rbp)
leaq 0x18662(%rip), %rdi     # 0x1e670
callq 0x93e0
movq %rax, -0x10(%rbp)
leaq -0x8(%rbp), %rdi
leaq -0x10(%rbp), %rsi
callq 0x93b0
testb $0x1, %al
jne 0x602d
jmp 0x60c1
leaq -0x8(%rbp), %rdi
callq 0x9410
movq %rax, %rsi
movl $0x0, -0x3c(%rbp)
leaq -0x38(%rbp), %rdi
movq %rdi, -0x260(%rbp)
leaq -0x3c(%rbp), %rdx
callq 0x98e0
movq -0x260(%rbp), %rsi
leaq 0x1857e(%rip), %rdi     # 0x1e5e0
callq 0x98a0
movb %dl, -0x251(%rbp)
movq %rax, -0x250(%rbp)
jmp 0x6076
movb -0x251(%rbp), %al
movq -0x250(%rbp), %rcx
movq %rcx, -0x60(%rbp)
movb %al, -0x58(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x9920
leaq -0x8(%rbp), %rdi
xorl %esi, %esi
callq 0x9580
movq %rax, -0x68(%rbp)
jmp 0x6007
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x9920
jmp 0x661a
leaq -0xb8(%rbp), %rdi
callq 0x9290
leaq -0xf0(%rbp), %rdi
callq 0x92e0
leaq -0x111(%rbp), %rdi
movq %rdi, -0x268(%rbp)
callq 0x46e0
movq -0x268(%rbp), %rdx
leaq 0xefbe(%rip), %rsi      # 0x150b8
leaq -0x110(%rbp), %rdi
callq 0x4560
jmp 0x6108
leaq -0xb8(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x9940
jmp 0x611d
leaq -0x110(%rbp), %rdi
callq 0x47e8
leaq -0x111(%rbp), %rdi
callq 0x4460
leaq -0x139(%rbp), %rdi
movq %rdi, -0x270(%rbp)
callq 0x46e0
movq -0x270(%rbp), %rdx
leaq 0xef62(%rip), %rsi      # 0x150b8
leaq -0x138(%rbp), %rdi
callq 0x4560
jmp 0x6164
leaq -0xf0(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0x9970
movb %dl, -0x279(%rbp)
movq %rax, -0x278(%rbp)
jmp 0x6186
movb -0x279(%rbp), %al
movq -0x278(%rbp), %rcx
movq %rcx, -0x150(%rbp)
movb %al, -0x148(%rbp)
leaq -0x138(%rbp), %rdi
callq 0x47e8
leaq -0x139(%rbp), %rdi
callq 0x4460
leaq -0xb8(%rbp), %rdi
callq 0x99b0
movb %al, -0x27a(%rbp)
jmp 0x61cc
movb -0x27a(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x61dd
jmp 0x65e1
leaq -0xb8(%rbp), %rdi
callq 0x99d0
movq %rax, -0x288(%rbp)
jmp 0x61f2
movq -0x288(%rbp), %rsi
leaq -0x170(%rbp), %rdi
callq 0x41d0
jmp 0x6207
leaq -0xb8(%rbp), %rdi
callq 0x99f0
jmp 0x6215
leaq 0x18234(%rip), %rsi     # 0x1e450
leaq 0xee92(%rip), %rdx      # 0x150b5
leaq -0x1d0(%rbp), %rdi
callq 0x9170
jmp 0x6231
leaq -0x1b0(%rbp), %rdi
leaq -0x1d0(%rbp), %rsi
leaq -0x170(%rbp), %rdx
callq 0x94c0
jmp 0x624d
leaq 0xf237(%rip), %rdx      # 0x1548b
leaq -0x190(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
callq 0x9470
jmp 0x6269
leaq -0x1b0(%rbp), %rdi
callq 0x47e8
leaq -0x1d0(%rbp), %rdi
callq 0x47e8
leaq -0x1f8(%rbp), %rdi
leaq -0x190(%rbp), %rsi
callq 0x41d0
jmp 0x6296
leaq -0x1f8(%rbp), %rdi
callq 0x11b80
movq %rax, -0x290(%rbp)
jmp 0x62ab
leaq -0x1f8(%rbp), %rdi
callq 0x47e8
movq -0x290(%rbp), %rax
movq %rax, -0x1d8(%rbp)
movq -0x1d8(%rbp), %rdi
callq 0x11810
movq %rax, -0x298(%rbp)
jmp 0x62da
movq -0x298(%rbp), %rax
movq %rax, -0x200(%rbp)
movq -0x200(%rbp), %rdi
callq 0x95e0
movq %rax, -0x208(%rbp)
movq -0x200(%rbp), %rdi
callq 0x9650
movq %rax, -0x210(%rbp)
leaq -0x208(%rbp), %rdi
leaq -0x210(%rbp), %rsi
callq 0x9610
testb $0x1, %al
jne 0x632a
jmp 0x65aa
leaq -0x208(%rbp), %rdi
callq 0x9680
movq %rax, %rsi
leaq 0x182a0(%rip), %rdi     # 0x1e5e0
callq 0x9a10
movq %rax, -0x2a0(%rbp)
jmp 0x634e
movq -0x2a0(%rbp), %rax
movq %rax, -0x218(%rbp)
leaq 0x1827d(%rip), %rdi     # 0x1e5e0
callq 0x9a70
movq %rax, -0x220(%rbp)
leaq -0x218(%rbp), %rdi
leaq -0x220(%rbp), %rsi
callq 0x9a40
testb $0x1, %al
jne 0x638b
jmp 0x64cd
leaq -0x170(%rbp), %rdi
leaq 0xed1f(%rip), %rsi      # 0x150b8
callq 0x4170
cmpl $0x0, %eax
jne 0x64b6
leaq -0x218(%rbp), %rdi
callq 0x9aa0
movl 0x20(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x20(%rax)
jmp 0x64cb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x63e7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x110(%rbp), %rdi
callq 0x47e8
leaq -0x111(%rbp), %rdi
callq 0x4460
jmp 0x6602
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x641e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x138(%rbp), %rdi
callq 0x47e8
leaq -0x139(%rbp), %rdi
callq 0x4460
jmp 0x6602
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x6602
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x65d3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x6477
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0x47e8
leaq -0x1d0(%rbp), %rdi
callq 0x47e8
jmp 0x65d3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x65c7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x1f8(%rbp), %rdi
callq 0x47e8
jmp 0x65c7
leaq -0x218(%rbp), %rdi
callq 0x9aa0
movl 0x20(%rax), %ecx
addl $0x2, %ecx
movl %ecx, 0x20(%rax)
jmp 0x64cd
leaq -0x208(%rbp), %rdi
callq 0x9680
movq %rax, %rsi
leaq -0xf0(%rbp), %rdi
callq 0x9ac0
movq %rax, -0x2a8(%rbp)
jmp 0x64f1
movq -0x2a8(%rbp), %rax
movq %rax, -0x228(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x9b20
movq %rax, -0x230(%rbp)
leaq -0x228(%rbp), %rdi
leaq -0x230(%rbp), %rsi
callq 0x9af0
testb $0x1, %al
jne 0x652b
jmp 0x658e
leaq -0x208(%rbp), %rdi
callq 0x9680
movq %rax, %rsi
leaq -0xf0(%rbp), %rdi
callq 0x9b50
movb %dl, -0x2b1(%rbp)
movq %rax, -0x2b0(%rbp)
jmp 0x6555
movb -0x2b1(%rbp), %al
movq -0x2b0(%rbp), %rcx
movq %rcx, -0x240(%rbp)
movb %al, -0x238(%rbp)
leaq -0x208(%rbp), %rdi
callq 0x9680
movq %rax, %rsi
leaq -0xb8(%rbp), %rdi
callq 0x9b90
jmp 0x658c
jmp 0x658e
jmp 0x6590
leaq -0x208(%rbp), %rdi
xorl %esi, %esi
callq 0x96a0
movq %rax, -0x248(%rbp)
jmp 0x62fb
leaq -0x190(%rbp), %rdi
callq 0x47e8
leaq -0x170(%rbp), %rdi
callq 0x47e8
jmp 0x61b8
leaq -0x190(%rbp), %rdi
callq 0x47e8
leaq -0x170(%rbp), %rdi
callq 0x47e8
jmp 0x6602
leaq -0xf0(%rbp), %rdi
callq 0x9300
leaq -0xb8(%rbp), %rdi
callq 0x92c0
addq $0x2c0, %rsp            # imm = 0x2C0
popq %rbp
retq
leaq -0xf0(%rbp), %rdi
callq 0x9300
leaq -0xb8(%rbp), %rdi
callq 0x92c0
movq -0x48(%rbp), %rdi
callq 0x46d0
nopw %cs:(%rax,%rax)