// File: /workspace/github_cpp_makefile_star2_O2/parth-shel[P]xpac/client.cpp
// Function: main
int main(int argc, char ** argv){
	if(argc<2){
		print_err(1);
		exit(1);
	}

	//Initializing:
	xpac_init();
	
	if(!strcmp(argv[1],"-install")){
		if(argc<3){
			print_err(2);
			exit(1);
		}

		char * pkg_name = strdup(argv[2]);

		//Checking if package available in the repository:
		auto find_itr = universe_list.find(std::string(pkg_name));
		if(find_itr == universe_list.end()){	//Package not available to install in the repo!
			std::cout<<"Sorry, package not available in the repository! Please check the website for more information!"<<std::endl;
			exit(0);
		}

		if(user_installed_list.find(std::string(pkg_name)) != user_installed_list.end()) {
			std::cout<<"Already installed "<<pkg_name<<"!"<<std::endl;
			exit(1);
		}

		//Installing the package:
		bool result = install_package(pkg_name);

		//Terminating:
		if(result)
			terminate(pkg_name);
		else
			exit(1);	//Should not reach here!
	}
	else if(!strcmp(argv[1],"-update")){
		std::cout<<"Updating xpac"<<std::endl;
		std::cout<<"Fetching updated package list from server: "<<std::endl;
		update_from_server();
		parse_universe_of_packages(universe_file);
		std::cout<<"Calculating differences: "<<std::endl;
		calculate_differences();
	}
	else if(!strcmp(argv[1], "-upgrade")){
		std::cout<<"Upgrading all packages"<<std::endl;
		upgrade_all_packages();
	}
	else if(!strcmp(argv[1],"-list")){
		if(argc > 2) {
			if(!strcmp(argv[2],"--installed")){
				if(user_installed_list.size() == 0){
					std::cout<<"No packages installed on this system by xpac!"<<std::endl;
					exit(0);
				}
				std::cout<<"Listing all packages installed on the system: "<<std::endl;
				print_package_set(user_installed_list);
				exit(0);
			}
			else{
				print_err(1);
				exit(1);
			}
		}
		std::cout<<"Listing all packages available for installation: "<<std::endl;
		print_package_set(universe_list);	
	}
	else if(!strcmp(argv[1],"-protect")){
		char * pkg_name = strdup(argv[2]);

		auto find_itr = user_installed_list.find(std::string(pkg_name));
		if(find_itr == user_installed_list.end()){	//Package not available to install in the repo!
			std::cout<<"Sorry, package not installed on the system!"<<std::endl;
			exit(1);
		}

		//Actually protecting the package right now:
		if(std::find(base->get_dep_list()->begin(), base->get_dep_list()->end(), std::string(pkg_name)) == base->get_dep_list()->end()){
			terminate(pkg_name);
		}
		std::cout<<"Package "<<pkg_name<<" successfully added to the protected list"<<std::endl;
		exit(0);
	}
	else if(!strcmp(argv[1],"-help")){
		man_help();
	}
	else if(!strcmp(argv[1],"-remove")){
		auto find_itr = user_installed_list.find(std::string(argv[2]));
		if(find_itr == user_installed_list.end()){	//Package not available to install in the repo!
			std::cout<<"Sorry, the package requested for removal is not installed on the current system!"<<std::endl;
			exit(0);
		}
		calculate_indegrees();
		remove_package(argv[2]);
		std::cout<<"Note: Removal of packages often leads to orphaned packages! Please run xpac -cleanup to remove any orphaned packages!"<<std::endl;
	}
	else if(!strcmp(argv[1],"-cleanup")){
		calculate_indegrees();
		remove_orphans();
	}
	else{
		print_err(1);
		exit(1);
	}
	return 0; //Successful exit
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
cmpl $0x1, %edi
jle 0x5609
movq %rsi, %rbx
movl %edi, %r14d
leaq 0xa290(%rip), %rsi      # 0xf390
leaq -0x160(%rbp), %r15
movq %r15, %rdi
callq 0x34a0
movq %r15, %rdi
callq 0x5d7d
leaq -0x160(%rbp), %rdi
callq 0x36a8
leaq 0xa286(%rip), %rsi      # 0xf3b0
leaq -0x140(%rbp), %r15
movq %r15, %rdi
callq 0x34a0
movq %r15, %rdi
callq 0x5d7d
leaq -0x140(%rbp), %rdi
callq 0x36a8
leaq 0xa27c(%rip), %rdi      # 0xf3d0
callq 0x6cdb
testb %al, %al
jne 0x5162
callq 0x58ca
leaq 0xa247(%rip), %rsi      # 0xf3b0
leaq 0x4f31(%rip), %rdx      # 0xa0a1
leaq -0x80(%rbp), %r15
movq %r15, %rdi
callq 0x5e5c
leaq 0x4f21(%rip), %rdx      # 0xa0a4
leaq -0x60(%rbp), %rdi
movq %r15, %rsi
callq 0x5f2a
leaq 0x52e1(%rip), %rdx      # 0xa477
leaq -0x40(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x5f2a
leaq -0x60(%rbp), %rdi
callq 0x36a8
leaq -0x80(%rbp), %rdi
callq 0x36a8
leaq -0x40(%rbp), %rdi
callq 0x6cdb
testb %al, %al
je 0x51e8
leaq -0x60(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x34a0
leaq -0x60(%rbp), %rdi
callq 0x8728
movq %rax, 0xa239(%rip)      # 0xf418
leaq -0x60(%rbp), %rdi
jmp 0x527b
pushq $0x70
popq %rdi
callq 0x3380
movq %rax, %r15
leaq 0x4eaa(%rip), %rsi      # 0xa0a4
leaq -0x60(%rbp), %rdi
leaq -0xa0(%rbp), %rdx
callq 0x3180
leaq 0x5350(%rip), %rsi      # 0xa561
leaq -0x80(%rbp), %rdi
leaq -0x19(%rbp), %rdx
callq 0x3180
leaq -0x60(%rbp), %rsi
leaq -0x80(%rbp), %rdx
movq %r15, %rdi
callq 0x82b0
movq %r15, 0xa1e3(%rip)      # 0xf418
leaq -0x80(%rbp), %rdi
callq 0x36a8
leaq -0x60(%rbp), %rdi
callq 0x36a8
movq 0xa1ca(%rip), %r15      # 0xf418
movq 0xa15b(%rip), %rsi      # 0xf3b0
leaq -0xa0(%rbp), %rdi
leaq -0x19(%rbp), %rdx
callq 0x3180
leaq -0xa0(%rbp), %rsi
movq %r15, %rdi
callq 0x8576
leaq -0xa0(%rbp), %rdi
callq 0x36a8
leaq -0x40(%rbp), %rdi
callq 0x36a8
leaq 0xa140(%rip), %rsi      # 0xf3d0
leaq -0x40(%rbp), %r15
movq %r15, %rdi
callq 0x34a0
movq %r15, %rdi
callq 0x8a10
leaq -0x40(%rbp), %rdi
callq 0x36a8
callq 0x8d24
movq 0x8(%rbx), %r15
leaq 0x4e75(%rip), %rsi      # 0xa132
movq %r15, %rdi
callq 0x34b0
testl %eax, %eax
je 0x5504
leaq 0x4ed9(%rip), %rsi      # 0xa1ad
movq %r15, %rdi
callq 0x34b0
testl %eax, %eax
je 0x537d
leaq 0x4f1e(%rip), %rsi      # 0xa209
movq %r15, %rdi
callq 0x34b0
testl %eax, %eax
je 0x5406
leaq 0x4f27(%rip), %rsi      # 0xa229
movq %r15, %rdi
callq 0x34b0
testl %eax, %eax
je 0x542b
leaq 0x4fb1(%rip), %rsi      # 0xa2ca
movq %r15, %rdi
callq 0x34b0
testl %eax, %eax
je 0x5575
leaq 0x552d(%rip), %rsi      # 0xa85d
movq %r15, %rdi
callq 0x34b0
testl %eax, %eax
je 0x5461
leaq 0x4feb(%rip), %rsi      # 0xa332
movq %r15, %rdi
callq 0x34b0
testl %eax, %eax
je 0x546b
leaq 0x50a3(%rip), %rsi      # 0xa401
movq %r15, %rdi
callq 0x34b0
testl %eax, %eax
jne 0x5609
callq 0x4a13
callq 0x4f06
jmp 0x54f4
movq 0x9c4c(%rip), %rbx      # 0xefd0
leaq 0x4e2a(%rip), %rsi      # 0xa1b5
movq %rbx, %rdi
callq 0x3370
movq %rax, %rdi
callq 0x31f0
leaq 0x4e21(%rip), %rsi      # 0xa1c3
movq %rbx, %rdi
callq 0x3370
movq %rax, %rdi
callq 0x31f0
callq 0x58ca
leaq 0xa012(%rip), %rsi      # 0xf3d0
leaq -0x100(%rbp), %rbx
movq %rbx, %rdi
callq 0x34a0
movq %rbx, %rdi
callq 0x8a10
leaq -0x100(%rbp), %rdi
callq 0x36a8
movq 0x9be8(%rip), %rdi      # 0xefd0
leaq 0x4e00(%rip), %rsi      # 0xa1ef
callq 0x3370
movq %rax, %rdi
callq 0x31f0
callq 0x3bec
jmp 0x54f4
movq 0x9bc3(%rip), %rdi      # 0xefd0
leaq 0x4dfe(%rip), %rsi      # 0xa212
callq 0x3370
movq %rax, %rdi
callq 0x31f0
callq 0x3ed2
jmp 0x54f4
cmpl $0x2, %r14d
jne 0x55d0
movq 0x9b94(%rip), %rdi      # 0xefd0
leaq 0x4e55(%rip), %rsi      # 0xa298
callq 0x3370
movq %rax, %rdi
callq 0x31f0
leaq 0xa129(%rip), %rdi      # 0xf580
callq 0x897c
jmp 0x54f4
callq 0x80d4
jmp 0x54f4
movq 0x10(%rbx), %rsi
leaq -0x40(%rbp), %rdi
leaq -0x60(%rbp), %rdx
callq 0x3180
leaq 0xa14d(%rip), %r14      # 0xf5d0
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
callq 0x6d4a
movq %rax, %r15
leaq -0x40(%rbp), %rdi
callq 0x36a8
addq $0x8, %r14
cmpq %r14, %r15
je 0x567d
callq 0x4a13
movq 0x10(%rbx), %rsi
leaq -0xc0(%rbp), %rdi
leaq -0x40(%rbp), %rdx
callq 0x3180
leaq -0xc0(%rbp), %rdi
callq 0x4d13
leaq -0xc0(%rbp), %rdi
callq 0x36a8
movq 0x9af0(%rip), %rdi      # 0xefd0
leaq 0x4ea4(%rip), %rsi      # 0xa38b
callq 0x3370
movq %rax, %rdi
callq 0x31f0
xorl %eax, %eax
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x2, %r14d
jne 0x551a
pushq $0x2
popq %rdi
callq 0x58a4
pushq $0x1
popq %rdi
callq 0x3410
movq 0x10(%rbx), %rdi
callq 0x3600
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
leaq -0x60(%rbp), %rdx
movq %rax, %rsi
callq 0x3180
leaq 0xa043(%rip), %r14      # 0xf580
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
callq 0x6d4a
movq %rax, %r15
leaq -0x40(%rbp), %rdi
callq 0x36a8
addq $0x8, %r14
cmpq %r14, %r15
jne 0x561a
movq 0x9a67(%rip), %rdi      # 0xefd0
leaq 0x4bcb(%rip), %rsi      # 0xa13b
jmp 0x568b
movq 0x10(%rbx), %rdi
callq 0x3600
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
leaq -0x60(%rbp), %rdx
movq %rax, %rsi
callq 0x3180
leaq 0xa038(%rip), %r14      # 0xf5d0
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
callq 0x6d4a
movq %rax, %r15
leaq -0x40(%rbp), %rdi
callq 0x36a8
addq $0x8, %r14
cmpq %r14, %r15
jne 0x56c8
movq 0x9a0c(%rip), %rdi      # 0xefd0
leaq 0x4d08(%rip), %rsi      # 0xa2d3
jmp 0x576e
movq 0x10(%rbx), %rdi
leaq 0x4c54(%rip), %rsi      # 0xa22f
callq 0x34b0
testl %eax, %eax
jne 0x5609
leaq 0x9fe5(%rip), %rax      # 0xf5d0
cmpq $0x0, 0x28(%rax)
jne 0x569f
movq 0x99d3(%rip), %rdi      # 0xefd0
leaq 0x4c37(%rip), %rsi      # 0xa23b
jmp 0x568b
pushq $0x1
popq %rbx
movl %ebx, %edi
callq 0x58a4
movl %ebx, %edi
callq 0x3410
leaq -0x40(%rbp), %rdi
leaq -0x60(%rbp), %rdx
movq %rbx, %rsi
callq 0x3180
leaq 0x9f9f(%rip), %r14      # 0xf5d0
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
callq 0x6d4a
movq %rax, %r15
addq $0x8, %r14
leaq -0x40(%rbp), %rdi
callq 0x36a8
cmpq %r14, %r15
jne 0x5746
movq %rbx, %rdi
callq 0x4203
leaq -0x120(%rbp), %rdi
leaq -0x40(%rbp), %rdx
movq %rbx, %rsi
callq 0x3180
leaq -0x120(%rbp), %rdi
callq 0x4985
movq 0x994c(%rip), %rdi      # 0xefd0
leaq 0x4caf(%rip), %rsi      # 0xa33a
callq 0x3370
movq %rax, %rdi
callq 0x31f0
xorl %edi, %edi
callq 0x3410
movq 0x992a(%rip), %rdi      # 0xefd0
leaq 0x4bbc(%rip), %rsi      # 0xa269
callq 0x3370
movq %rax, %rdi
callq 0x31f0
leaq 0x9f0f(%rip), %rdi      # 0xf5d0
callq 0x897c
jmp 0x5698
movq 0x9d49(%rip), %rdi      # 0xf418
callq 0x856c
movq (%rax), %r14
movq 0x9d3a(%rip), %rdi      # 0xf418
callq 0x856c
movq 0x8(%rax), %r15
leaq -0x40(%rbp), %rdi
leaq -0x60(%rbp), %rdx
movq %rbx, %rsi
callq 0x3180
leaq -0x40(%rbp), %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x7c93
movq %rax, %r14
movq 0x9d08(%rip), %rdi      # 0xf418
callq 0x856c
movq 0x8(%rax), %r15
leaq -0x40(%rbp), %rdi
callq 0x36a8
cmpq %r15, %r14
jne 0x5780
leaq -0xe0(%rbp), %rdi
leaq -0x40(%rbp), %rdx
movq %rbx, %rsi
callq 0x3180
leaq -0xe0(%rbp), %rdi
callq 0x4985
movq 0x9883(%rip), %rdi      # 0xefd0
leaq 0x4a46(%rip), %rsi      # 0xa19a
callq 0x3370
movq %rax, %rdi
movq %rbx, %rsi
callq 0x3370
leaq 0x4cf0(%rip), %rsi      # 0xa45b
movq %rax, %rdi
callq 0x3370
movq %rax, %rdi
callq 0x31f0
jmp 0x5512
movq 0x9849(%rip), %rdi      # 0xefd0
leaq 0x4b71(%rip), %rsi      # 0xa2ff
callq 0x3370
movq %rax, %rdi
movq %rbx, %rsi
callq 0x3370
leaq 0x4b63(%rip), %rsi      # 0xa308
movq %rax, %rdi
jmp 0x568b
movq %rax, %rbx
leaq -0xe0(%rbp), %rdi
jmp 0x5897
jmp 0x5806
jmp 0x5890
movq %rax, %rbx
leaq -0x120(%rbp), %rdi
jmp 0x5897
jmp 0x5806
jmp 0x5890
jmp 0x5806
jmp 0x5890
jmp 0x5806
movq %rax, %rbx
leaq -0xc0(%rbp), %rdi
jmp 0x5897
jmp 0x5806
jmp 0x5890
jmp 0x5806
jmp 0x5890
jmp 0x5806
jmp 0x5890
movq %rax, %rbx
jmp 0x589c
movq %rax, %rbx
leaq -0x100(%rbp), %rdi
jmp 0x5897
movq %rax, %rbx
leaq -0xa0(%rbp), %rdi
jmp 0x5858
jmp 0x5890
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
callq 0x36a8
jmp 0x5839
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x36a8
jmp 0x5847
movq %rax, %rbx
movq %r15, %rdi
callq 0x3360
jmp 0x5893
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x36a8
jmp 0x5893
jmp 0x5890
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x36a8
jmp 0x5872
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
jmp 0x5897
movq %rax, %rbx
leaq -0x140(%rbp), %rdi
jmp 0x5897
movq %rax, %rbx
leaq -0x160(%rbp), %rdi
jmp 0x5897
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
callq 0x36a8
movq %rbx, %rdi
callq 0x35c0