// File: /workspace/github_cpp_makefile_star2_O3/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 %r13
pushq %r12
pushq %rbx
subq $0x338, %rsp            # imm = 0x338
movl %edi, -0x30(%rbp)
cmpl $0x1, %edi
jle 0x6801
movq %rsi, %r13
leaq -0xe0(%rbp), %rbx
movq %rbx, -0x10(%rbx)
movq 0xa3a1(%rip), %rsi      # 0x10380
movq 0xa3a2(%rip), %rdx      # 0x10388
addq %rsi, %rdx
leaq -0xf0(%rbp), %r15
movq %r15, %rdi
callq 0x80a2
movq %r15, %rdi
callq 0x734f
movq -0xf0(%rbp), %rdi
cmpq %rbx, %rdi
je 0x6011
callq 0x3360
leaq -0xc0(%rbp), %rbx
movq %rbx, -0x10(%rbx)
movq 0xa37d(%rip), %rsi      # 0x103a0
movq 0xa37e(%rip), %rdx      # 0x103a8
addq %rsi, %rdx
leaq -0xd0(%rbp), %r15
movq %r15, %rdi
callq 0x80a2
movq %r15, %rdi
callq 0x734f
movq -0xd0(%rbp), %rdi
cmpq %rbx, %rdi
je 0x6055
callq 0x3360
movq 0xa364(%rip), %rsi      # 0x103c0
leaq -0x358(%rbp), %r15
movq %r15, %rdi
movl $0x8, %edx
callq 0x3610
movq (%r15), %rax
movq -0x18(%rax), %rax
movl -0x338(%rbp,%rax), %ebx
movq %r15, %rdi
callq 0x3100
testl %ebx, %ebx
je 0x60c2
leaq 0x6502(%rip), %r15      # 0xc593
movq %r15, %rdi
callq 0x3600
movq %rax, %r12
leaq 0x636d(%rip), %rdi      # 0xc410
callq 0x3600
movq %r12, %rdi
movq %rax, %rsi
callq 0x9314
movq 0xa306(%rip), %rsi      # 0x103c0
movq %r15, %rdi
callq 0x3260
leaq -0x60(%rbp), %rbx
movq %rbx, -0x10(%rbx)
movq 0xa2cf(%rip), %rsi      # 0x103a0
movq 0xa2d0(%rip), %rdx      # 0x103a8
addq %rsi, %rdx
leaq -0x70(%rbp), %r15
movq %r15, %rdi
callq 0x80a2
leaq 0x5fb3(%rip), %rsi      # 0xc0a1
movq %r15, %rdi
callq 0x3650
leaq 0x5fa7(%rip), %rsi      # 0xc0a4
leaq -0x70(%rbp), %rdi
callq 0x3650
leaq -0x348(%rbp), %r12
movq %r12, -0x10(%r12)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x6134
movq %rdx, -0x358(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x348(%rbp)
jmp 0x613c
movups (%rcx), %xmm0
movups %xmm0, (%r12)
movq 0x8(%rax), %rdx
leaq -0x358(%rbp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x6316(%rip), %rsi      # 0xc477
callq 0x3650
leaq -0x40(%rbp), %r14
movq %r14, -0x10(%r14)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x618a
movq %rdx, -0x50(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x40(%rbp)
jmp 0x6191
movups (%rcx), %xmm0
movups %xmm0, (%r14)
movq 0x8(%rax), %rdx
movq %rdx, -0x48(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq -0x358(%rbp), %rdi
cmpq %r12, %rdi
je 0x61b9
callq 0x3360
movq -0x70(%rbp), %rdi
cmpq %rbx, %rdi
je 0x61c7
callq 0x3360
movq -0x50(%rbp), %rsi
leaq -0x358(%rbp), %rdi
movl $0x8, %edx
callq 0x3610
leaq -0x358(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
movl -0x338(%rbp,%rax), %r15d
callq 0x3100
testl %r15d, %r15d
je 0x63d8
movl $0x70, %edi
callq 0x3390
movq %rax, %r15
leaq -0x358(%rbp), %rsi
movq %r12, (%rsi)
movl $0x65736162, 0x10(%rsi) # imm = 0x65736162
movq $0x4, 0x8(%rsi)
xorl %eax, %eax
movb %al, 0x14(%rsi)
leaq -0x70(%rbp), %rdx
movq %rbx, (%rdx)
movl $0x2e303a76, 0x10(%rdx) # imm = 0x2E303A76
movl $0x302e302e, 0x13(%rdx) # imm = 0x302E302E
movq $0x7, 0x8(%rdx)
movb %al, 0x17(%rdx)
movq %r15, %rdi
callq 0x9894
movq %r15, 0xa1ae(%rip)      # 0x10408
movq -0x70(%rbp), %rdi
cmpq %rbx, %rdi
je 0x6268
callq 0x3360
movq -0x358(%rbp), %rdi
cmpq %r12, %rdi
je 0x6279
callq 0x3360
movq 0xa188(%rip), %r15      # 0x10408
movq 0xa119(%rip), %rsi      # 0x103a0
leaq -0x110(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x3190
leaq -0x110(%rbp), %rsi
movq %r15, %rdi
callq 0x9de2
leaq -0x100(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x62bb
callq 0x3360
movq -0x50(%rbp), %rdi
cmpq %r14, %rdi
je 0x62c9
callq 0x3360
leaq -0x358(%rbp), %r15
movq %r12, (%r15)
movq 0xa0e6(%rip), %rsi      # 0x103c0
movq 0xa0e7(%rip), %rdx      # 0x103c8
addq %rsi, %rdx
movq %r15, %rdi
callq 0x80a2
movq %r15, %rdi
callq 0xa554
movq %r13, %rbx
movq -0x358(%rbp), %rdi
cmpq %r12, %rdi
je 0x6308
callq 0x3360
callq 0xa9b0
movq 0x8(%rbx), %r15
leaq 0x5e1a(%rip), %rsi      # 0xc132
movq %r15, %rdi
callq 0x34b0
testl %eax, %eax
je 0x66e6
leaq 0x5e7e(%rip), %rsi      # 0xc1ad
movq %r15, %rdi
callq 0x34b0
testl %eax, %eax
je 0x641a
leaq 0x5ec3(%rip), %rsi      # 0xc209
movq %r15, %rdi
callq 0x34b0
testl %eax, %eax
je 0x6558
leaq 0x5ecc(%rip), %rsi      # 0xc229
movq %r15, %rdi
callq 0x34b0
testl %eax, %eax
je 0x65a4
leaq 0x5f56(%rip), %rsi      # 0xc2ca
movq %r15, %rdi
callq 0x34b0
testl %eax, %eax
je 0x675f
leaq 0x64f2(%rip), %rsi      # 0xc87d
movq %r15, %rdi
callq 0x34b0
testl %eax, %eax
je 0x6601
leaq 0x5f90(%rip), %rsi      # 0xc332
movq %r15, %rdi
callq 0x34b0
testl %eax, %eax
je 0x660b
leaq 0x6048(%rip), %rsi      # 0xc401
movq %r15, %rdi
callq 0x34b0
testl %eax, %eax
jne 0x6801
callq 0x5515
callq 0x5cf2
jmp 0x66d2
leaq -0x358(%rbp), %rdi
movq %r12, (%rdi)
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
addq %rsi, %rdx
callq 0x80a2
leaq -0x358(%rbp), %rdi
callq 0xa11c
movq %rax, 0xa003(%rip)      # 0x10408
movq -0x358(%rbp), %rdi
cmpq %r12, %rdi
jne 0x62b6
jmp 0x62bb
movq 0x9baf(%rip), %rbx      # 0xffd0
leaq 0x5d8d(%rip), %rsi      # 0xc1b5
movl $0xd, %edx
movq %rbx, %rdi
callq 0x3400
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3370
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3280
leaq 0x5d60(%rip), %rsi      # 0xc1c3
movl $0x2b, %edx
movq %rbx, %rdi
callq 0x3400
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3370
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3280
leaq 0x60f5(%rip), %r14      # 0xc593
movq %r14, %rdi
callq 0x3600
movq %rax, %r15
leaq 0x5f60(%rip), %rdi      # 0xc410
callq 0x3600
movq %r15, %rdi
movq %rax, %rsi
callq 0x9314
movq 0x9ef9(%rip), %rsi      # 0x103c0
movq %r14, %rdi
callq 0x3260
leaq -0xa0(%rbp), %r15
movq %r15, -0x10(%r15)
movq 0x9edf(%rip), %rsi      # 0x103c0
movq 0x9ee0(%rip), %rdx      # 0x103c8
addq %rsi, %rdx
leaq -0xb0(%rbp), %r14
movq %r14, %rdi
callq 0x80a2
movq %r14, %rdi
callq 0xa554
movq -0xb0(%rbp), %rdi
cmpq %r15, %rdi
je 0x6513
callq 0x3360
leaq 0x5cd5(%rip), %rsi      # 0xc1ef
movl $0x19, %edx
movq %rbx, %rdi
callq 0x3400
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3370
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3280
callq 0x3e9c
jmp 0x66d2
movq 0x9a71(%rip), %rbx      # 0xffd0
leaq 0x5cac(%rip), %rsi      # 0xc212
movl $0x16, %edx
movq %rbx, %rdi
callq 0x3400
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3370
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3280
callq 0x43af
jmp 0x66d2
cmpl $0x2, -0x30(%rbp)
jne 0x67c8
movq 0x9a1b(%rip), %rbx      # 0xffd0
leaq 0x5cdc(%rip), %rsi      # 0xc298
movl $0x31, %edx
movq %rbx, %rdi
callq 0x3400
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3370
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3280
leaq 0x9f79(%rip), %rdi      # 0x10570
callq 0xa47c
jmp 0x66d2
callq 0x9594
jmp 0x66d2
movq 0x10(%rbx), %rsi
leaq -0x358(%rbp), %rdi
leaq -0x50(%rbp), %rdx
callq 0x3190
leaq 0x9f9a(%rip), %r14      # 0x105c0
leaq -0x358(%rbp), %rsi
movq %r14, %rdi
callq 0x8140
movq %rax, %r15
movq -0x358(%rbp), %rdi
cmpq %r12, %rdi
je 0x6649
callq 0x3360
addq $0x8, %r14
cmpq %r14, %r15
je 0x6889
callq 0x5515
movq 0x10(%rbx), %rsi
leaq -0x90(%rbp), %rdi
leaq -0x358(%rbp), %rdx
callq 0x3190
leaq -0x90(%rbp), %rdi
callq 0x59ce
leaq -0x80(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x6690
callq 0x3360
movq 0x9939(%rip), %rbx      # 0xffd0
leaq 0x5ced(%rip), %rsi      # 0xc38b
movl $0x75, %edx
movq %rbx, %rdi
callq 0x3400
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3370
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3280
xorl %eax, %eax
addq $0x338, %rsp            # imm = 0x338
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x2, -0x30(%rbp)
jne 0x66f6
movl $0x2, %edi
jmp 0x6806
movq 0x10(%r13), %rdi
callq 0x3600
movq %rax, %rbx
leaq -0x358(%rbp), %rdi
leaq -0x50(%rbp), %rdx
movq %rax, %rsi
callq 0x3190
leaq 0x9e54(%rip), %r14      # 0x10570
leaq -0x358(%rbp), %rsi
movq %r14, %rdi
callq 0x8140
movq %rax, %r15
movq -0x358(%rbp), %rdi
cmpq %r12, %rdi
je 0x673f
callq 0x3360
addq $0x8, %r14
cmpq %r14, %r15
jne 0x6815
movq 0x987d(%rip), %rdi      # 0xffd0
leaq 0x59e1(%rip), %rsi      # 0xc13b
jmp 0x6897
movq 0x10(%rbx), %rdi
callq 0x3600
movq %rax, %rbx
leaq -0x358(%rbp), %rdi
leaq -0x50(%rbp), %rdx
movq %rax, %rsi
callq 0x3190
leaq 0x9e3b(%rip), %r14      # 0x105c0
leaq -0x358(%rbp), %rsi
movq %r14, %rdi
callq 0x8140
movq %rax, %r15
movq -0x358(%rbp), %rdi
cmpq %r12, %rdi
je 0x67a8
callq 0x3360
addq $0x8, %r14
cmpq %r14, %r15
jne 0x68d4
movq 0x9814(%rip), %rdi      # 0xffd0
leaq 0x5b10(%rip), %rsi      # 0xc2d3
jmp 0x698b
movq 0x10(%rbx), %rdi
leaq 0x5a5c(%rip), %rsi      # 0xc22f
callq 0x34b0
testl %eax, %eax
jne 0x6801
leaq 0x9ddd(%rip), %rax      # 0x105c0
cmpq $0x0, 0x28(%rax)
jne 0x68ab
movq 0x97db(%rip), %rdi      # 0xffd0
leaq 0x5a3f(%rip), %rsi      # 0xc23b
jmp 0x6897
movl $0x1, %edi
callq 0x6b09
movl $0x1, %edi
callq 0x3440
leaq -0x358(%rbp), %rdi
leaq -0x50(%rbp), %rdx
movq %rbx, %rsi
callq 0x3190
leaq 0x9d91(%rip), %r14      # 0x105c0
leaq -0x358(%rbp), %rsi
movq %r14, %rdi
callq 0x8140
movq %rax, %r15
movq -0x358(%rbp), %rdi
cmpq %r12, %rdi
je 0x6852
callq 0x3360
addq $0x8, %r14
cmpq %r14, %r15
jne 0x6963
movq %rbx, %rdi
callq 0x4916
leaq -0x150(%rbp), %rdi
leaq -0x358(%rbp), %rdx
movq %rbx, %rsi
callq 0x3190
leaq -0x150(%rbp), %rdi
callq 0x5463
movq 0x9740(%rip), %rdi      # 0xffd0
leaq 0x5aa3(%rip), %rsi      # 0xc33a
callq 0x3380
movq %rax, %rdi
callq 0x31e0
xorl %edi, %edi
callq 0x3440
movq 0x971e(%rip), %rdi      # 0xffd0
leaq 0x59b0(%rip), %rsi      # 0xc269
callq 0x3380
movq %rax, %rdi
callq 0x31e0
leaq 0x9cf3(%rip), %rdi      # 0x105c0
callq 0xa47c
jmp 0x68a4
movq 0x9b2d(%rip), %rdi      # 0x10408
callq 0x9dd8
movq (%rax), %r14
movq 0x9b1e(%rip), %rdi      # 0x10408
callq 0x9dd8
movq 0x8(%rax), %r15
leaq -0x358(%rbp), %rdi
leaq -0x50(%rbp), %rdx
movq %rbx, %rsi
callq 0x3190
leaq -0x358(%rbp), %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x9153
movq %rax, %r14
movq 0x9ae6(%rip), %rdi      # 0x10408
callq 0x9dd8
movq 0x8(%rax), %r15
movq -0x358(%rbp), %rdi
cmpq %r12, %rdi
je 0x693c
callq 0x3360
cmpq %r15, %r14
jne 0x699d
leaq -0x130(%rbp), %rdi
leaq -0x358(%rbp), %rdx
movq %rbx, %rsi
callq 0x3190
leaq -0x130(%rbp), %rdi
callq 0x5463
movq 0x9666(%rip), %rdi      # 0xffd0
leaq 0x5829(%rip), %rsi      # 0xc19a
callq 0x3380
movq %rax, %rdi
movq %rbx, %rsi
callq 0x3380
leaq 0x5ad3(%rip), %rsi      # 0xc45b
movq %rax, %rdi
callq 0x3380
movq %rax, %rdi
callq 0x31e0
jmp 0x680b
movq 0x962c(%rip), %rdi      # 0xffd0
leaq 0x5954(%rip), %rsi      # 0xc2ff
callq 0x3380
movq %rax, %rdi
movq %rbx, %rsi
callq 0x3380
leaq 0x5946(%rip), %rsi      # 0xc308
movq %rax, %rdi
jmp 0x6897
movq %rax, %r13
leaq -0x120(%rbp), %rax
jmp 0x6a00
jmp 0x6a24
jmp 0x6aa1
movq %rax, %r13
leaq -0x140(%rbp), %rax
jmp 0x6a00
jmp 0x6a24
jmp 0x6aa1
jmp 0x6a24
jmp 0x6aa1
jmp 0x6a24
movq %rax, %r13
leaq -0x80(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0x6aee
jmp 0x6af3
jmp 0x6a24
jmp 0x6aa1
jmp 0x6a24
jmp 0x6aa1
jmp 0x6a24
jmp 0x6aa1
movq %rax, %r13
jmp 0x6af3
movq %rax, %r13
movq -0xb0(%rbp), %rdi
cmpq %r15, %rdi
jne 0x6aee
jmp 0x6af3
movq %rax, %r13
movq -0x358(%rbp), %rdi
cmpq %r12, %rdi
jne 0x6a9a
jmp 0x6afe
movq %rax, %r13
leaq -0x100(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0x6a9a
jmp 0x6afe
jmp 0x6afb
movq %rax, %r13
movq -0x70(%rbp), %rdi
cmpq %rbx, %rdi
je 0x6a86
callq 0x3360
movq -0x358(%rbp), %rdi
cmpq %r12, %rdi
je 0x6a97
callq 0x3360
movq %r15, %rdi
callq 0x3360
jmp 0x6afe
movq %rax, %r13
movq -0x358(%rbp), %rdi
cmpq %r12, %rdi
jne 0x6aee
jmp 0x6af3
movq %rax, %r13
movq -0x358(%rbp), %rdi
cmpq %r12, %rdi
je 0x6acd
callq 0x3360
jmp 0x6acd
jmp 0x6aca
movq %rax, %r13
movq -0x70(%rbp), %rdi
jmp 0x6ae9
movq %rax, %r13
movq -0xd0(%rbp), %rdi
jmp 0x6ae9
movq %rax, %r13
movq -0xf0(%rbp), %rdi
cmpq %rbx, %rdi
je 0x6af3
callq 0x3360
movq %r13, %rdi
callq 0x35c0
movq %rax, %r13
movq -0x50(%rbp), %rdi
cmpq %r14, %rdi
jne 0x6aee
jmp 0x6af3