// File: /workspace/github_cpp_makefile_star2_O2/girdhari9[P]mTORRENT/ClientServer.cpp
// Function: main
int main(int arg, char * args[]){
	getcwd(root_path,1000);
	string cmd, ClientLog = "clientlog.txt";

	MYIP = args[1];
	MYPORT = args[2];
	TRACKER1IP = args[3];
	TRACKER1PORT = args[4];
	DOWNLOADLOG = args[5];
	PORT = stoi(MYPORT);

	ReadLogFile(ClientLog);
	UpdateToTracker();

	while(1){

		cout<<"Enter Command: ";
		cin>>cmd;

		if(cmd == "share"){
			string filename, mtorrentfilename;
			cin>>filename;
			cin>>mtorrentfilename;
			TotalSharedFile.push_back(mtorrentfilename);
			string SHA = mtorrentFile(filename,mtorrentfilename,TRACKER1IP,TRACKER1PORT);
			UpdateDownloadLog(1,filename);

			CreateLog.push_back(mtorrentfilename);
			CreateLog.push_back(SHA);
			CreateLog.push_back(root_path);
			UpdateLogFile(ClientLog);
			ClientLog.erase(ClientLog.begin(),ClientLog.end());
			
			thread client (FunctionCalling, cref(mtorrentfilename),1,SHA,root_path);
			thread server (ServerConnection);
			client.join();
			server.detach();
		}
		else if(cmd == "remove"){
			string mtorrentfilename;
			cin>>mtorrentfilename;
			if(mtorrentfilename.size() > 9 && mtorrentfilename.substr(mtorrentfilename.size()-9) != ".mtorrent"){
        		cout<<"\n> Please give correct name of mtorrent file!\n";
		        return 0;
		    }

		    thread client (FunctionCalling, cref(mtorrentfilename),2,"No",root_path);
		    client.join();
		}
		else if(cmd == "get" || cmd == "Get"){
			string mtorrentfilename;
			cin>>mtorrentfilename;

			if(mtorrentfilename.size() > 9 && mtorrentfilename.substr(mtorrentfilename.size()-9) != ".mtorrent"){
        		cout<<"\n> Please give correct name of mtorrent file!\n";
		        return 0;
		    }

			thread client (FunctionCalling, cref(mtorrentfilename),0,"No",root_path);
			UpdateDownloadLog(0,mtorrentfilename);

			thread server (ServerConnection);
		    client.join();
		    server.detach();
		}
		else if(cmd == "show" || cmd == "Show"){
			string dw; cin>>dw;
			ShowDownloadDetail();
		}
		else{
			cout<<"Error: Command not found!\n";
		}

	    Jump:
		    cout<<"Do you want to continue? [Y/N]: ";
		    char c;
		    cin>>c;
		    if((c == 'N') || (c == 'n')){
		    	UpdateLogFile(ClientLog);
		    	for(unsigned int i = 0; i < TotalSharedFile.size(); i++){
		    		thread client (FunctionCalling, cref(TotalSharedFile[i]),2,"No",root_path);
		    		client.join();
		    	}
		        cout<<"Connection Closed!\n";
		        break;
		    }
		    else if((c == 'Y') || (c == 'y'))
		    	continue;
		    else{
		    	cout<<"Plese enter correct...\n";
			    goto Jump;
		    }
	}
    return 0; 
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1f8, %rsp            # imm = 0x1F8
movq %rsi, %rbx
leaq 0xb939(%rip), %rdi      # 0x10470
movl $0x3e8, %esi            # imm = 0x3E8
callq 0x41e0
leaq 0xc8(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x64c4(%rip), %rsi      # 0xb020
leaq 0x78(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x6040
movq 0x8(%rbx), %rsi
leaq 0xb812(%rip), %rdi      # 0x10388
callq 0x4620
movq 0x10(%rbx), %rsi
leaq 0xb822(%rip), %rdi      # 0x103a8
callq 0x4620
movq 0x18(%rbx), %rsi
leaq 0xb832(%rip), %rdi      # 0x103c8
callq 0x4620
movq 0x20(%rbx), %rsi
leaq 0xb842(%rip), %rdi      # 0x103e8
callq 0x4620
movq 0x28(%rbx), %rsi
leaq 0xb852(%rip), %rdi      # 0x10408
callq 0x4620
leaq 0xb7e6(%rip), %rdi      # 0x103a8
pushq $0xa
popq %rdx
xorl %esi, %esi
callq 0x607b
movl %eax, 0xb7ae(%rip)      # 0x10380
leaq 0x118(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x4470
leaq 0x118(%rsp), %rdi
callq 0x5409
leaq 0x118(%rsp), %rdi
callq 0x4678
callq 0x55da
movq 0xb3be(%rip), %r14      # 0xffc8
leaq 0x641d(%rip), %rsi      # 0xb02e
leaq 0xf8(%rsp), %rbx
leaq 0x158(%rsp), %rbp
leaq 0x98(%rsp), %r12
movq %r14, %rdi
callq 0x4330
leaq 0xb8(%rsp), %r15
movq 0xb3a0(%rip), %rdi      # 0xffe0
movq %r15, %rsi
callq 0x4420
movq %r15, %rdi
leaq 0x63ec(%rip), %rsi      # 0xb03e
callq 0x6097
testb %al, %al
je 0x4ea3
leaq 0x18(%rsp), %rax
movq %rax, 0x8(%rsp)
andq $0x0, 0x10(%rsp)
xorl %ecx, %ecx
movb %cl, 0x18(%rsp)
leaq 0x38(%rsp), %rax
movq %rax, 0x28(%rsp)
andq $0x0, 0x30(%rsp)
movb %cl, 0x38(%rsp)
movq 0xb350(%rip), %rdi      # 0xffe0
leaq 0x8(%rsp), %rsi
callq 0x4420
movq 0xb33f(%rip), %rdi      # 0xffe0
leaq 0x28(%rsp), %rsi
callq 0x4420
leaq 0xb7a6(%rip), %rdi      # 0x10458
leaq 0x28(%rsp), %rsi
callq 0x60a4
leaq 0x198(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x4470
leaq 0x178(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x4470
movq %rbx, %rdi
leaq 0xb6de(%rip), %rsi      # 0x103c8
callq 0x4470
movq %rbp, %rdi
leaq 0xb6ef(%rip), %rsi      # 0x103e8
callq 0x4470
movq %r12, %r13
movq %r12, %rdi
leaq 0x198(%rsp), %r15
movq %r15, %rsi
leaq 0x178(%rsp), %rbx
movq %rbx, %rdx
leaq 0xf8(%rsp), %r12
movq %r12, %rcx
movq %rbp, %r8
callq 0xa04c
movq %rbp, %rdi
callq 0x4678
movq %r12, %rdi
callq 0x4678
movq %rbx, %rdi
callq 0x4678
movq %r15, %rdi
callq 0x4678
leaq 0x1d8(%rsp), %rbx
movq %rbx, %rdi
leaq 0x8(%rsp), %rsi
callq 0x4470
movq %r13, %r12
leaq 0xbb1c(%rip), %r15      # 0x10888
leaq 0x58(%rsp), %r13
leaq 0x48(%rsp), %rbp
pushq $0x1
popq %rdi
movq %rbx, %rsi
callq 0x5749
movq %rbx, %rdi
callq 0x4678
movq %r15, %rdi
leaq 0x28(%rsp), %rsi
callq 0x60a4
movq %r15, %rdi
movq %r12, %rsi
callq 0x60a4
movq %r13, %rdi
leaq 0xb6c5(%rip), %rsi      # 0x10470
movq %rbp, %rdx
callq 0x6040
movq %r15, %rdi
movq %r13, %rsi
callq 0x680a
movq %r13, %rdi
callq 0x4678
leaq 0x138(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x4470
leaq 0x138(%rsp), %rbx
movq %rbx, %rdi
callq 0x5bcc
movq %rbx, %rdi
callq 0x4678
movq 0x78(%rsp), %rsi
movq 0x80(%rsp), %rdx
addq %rsi, %rdx
leaq 0x78(%rsp), %rdi
callq 0x40e0
leaq 0xf8(%rsp), %rbx
leaq 0x158(%rsp), %rbp
leaq 0x28(%rsp), %rax
movq %rax, 0x48(%rsp)
movl $0x1, 0x54(%rsp)
leaq 0x58(%rsp), %rdi
leaq 0x1f74(%rip), %rsi      # 0x6dac
leaq 0x48(%rsp), %r15
movq %r15, %rdx
leaq 0x54(%rsp), %rcx
movq %r12, %r8
leaq 0xb621(%rip), %r9       # 0x10470
callq 0x60d0
movq %r15, %rdi
leaq 0x4afa(%rip), %rsi      # 0x9958
callq 0x6176
leaq 0x58(%rsp), %rdi
callq 0x4580
leaq 0x48(%rsp), %r15
movq %r15, %rdi
callq 0x45a0
movq %r15, %rdi
callq 0x61dc
leaq 0x58(%rsp), %rdi
callq 0x61dc
movq %r12, %rdi
callq 0x4678
leaq 0x28(%rsp), %rdi
callq 0x4678
jmp 0x50a0
movq %r15, %rdi
leaq 0x6197(%rip), %rsi      # 0xb044
callq 0x6097
testb %al, %al
je 0x4f76
leaq 0x18(%rsp), %rax
movq %rax, 0x8(%rsp)
andq $0x0, 0x10(%rsp)
movb $0x0, 0x18(%rsp)
movq 0xb10a(%rip), %rdi      # 0xffe0
leaq 0x8(%rsp), %rsi
callq 0x4420
movq 0x10(%rsp), %rdx
cmpq $0xa, %rdx
jb 0x4f27
addq $-0x9, %rdx
leaq 0x28(%rsp), %r15
movq %r15, %rdi
leaq 0x8(%rsp), %rsi
pushq $-0x1
popq %rcx
callq 0x4360
movq %r15, %rdi
leaq 0x613d(%rip), %rsi      # 0xb04b
callq 0x61e9
movl %eax, %r13d
movq %r15, %rdi
callq 0x4678
testb %r13b, %r13b
jne 0x525d
leaq 0x8(%rsp), %rax
movq %rax, 0x98(%rsp)
movl $0x2, 0x58(%rsp)
leaq 0x28(%rsp), %r15
movq %r15, %rdi
leaq 0x1e61(%rip), %rsi      # 0x6dac
movq %r12, %rdx
leaq 0x58(%rsp), %rcx
leaq 0x612a(%rip), %r8       # 0xb084
leaq 0xb50f(%rip), %r9       # 0x10470
callq 0x61f4
movq %r15, %rdi
callq 0x4580
movq %r15, %rdi
jmp 0x509b
movq %r15, %rdi
leaq 0x6107(%rip), %rsi      # 0xb087
callq 0x6097
testb %al, %al
jne 0x4fa0
movq %r15, %rdi
leaq 0x60f8(%rip), %rsi      # 0xb08b
callq 0x6097
testb %al, %al
je 0x50fd
leaq 0x18(%rsp), %rax
movq %rax, 0x8(%rsp)
andq $0x0, 0x10(%rsp)
movb $0x0, 0x18(%rsp)
movq 0xb024(%rip), %rdi      # 0xffe0
leaq 0x8(%rsp), %rsi
callq 0x4420
movq 0x10(%rsp), %rdx
cmpq $0xa, %rdx
jb 0x500d
addq $-0x9, %rdx
leaq 0x28(%rsp), %r15
movq %r15, %rdi
leaq 0x8(%rsp), %rsi
pushq $-0x1
popq %rcx
callq 0x4360
movq %r15, %rdi
leaq 0x6057(%rip), %rsi      # 0xb04b
callq 0x61e9
movl %eax, %r13d
movq %r15, %rdi
callq 0x4678
testb %r13b, %r13b
jne 0x5272
leaq 0x8(%rsp), %rax
movq %rax, 0x98(%rsp)
andl $0x0, 0x58(%rsp)
leaq 0x28(%rsp), %rdi
leaq 0x1d81(%rip), %rsi      # 0x6dac
movq %r12, %rdx
leaq 0x58(%rsp), %rcx
leaq 0x604a(%rip), %r8       # 0xb084
leaq 0xb42f(%rip), %r9       # 0x10470
callq 0x61f4
leaq 0x1b8(%rsp), %r15
movq %r15, %rdi
leaq 0x8(%rsp), %rsi
callq 0x4470
xorl %edi, %edi
movq %r15, %rsi
callq 0x5749
movq %r15, %rdi
callq 0x4678
movq %r12, %rdi
leaq 0x48e1(%rip), %rsi      # 0x9958
callq 0x6176
leaq 0x28(%rsp), %rdi
callq 0x4580
movq %r12, %rdi
callq 0x45a0
movq %r12, %rdi
callq 0x61dc
leaq 0x28(%rsp), %rdi
callq 0x61dc
leaq 0x8(%rsp), %rdi
callq 0x4678
movq %r14, %rdi
leaq 0x6000(%rip), %rsi      # 0xb0b4
callq 0x4330
movq 0xaf20(%rip), %rdi      # 0xffe0
leaq 0x58(%rsp), %rsi
callq 0x4460
movzbl 0x58(%rsp), %eax
andl $-0x21, %eax
cmpl $0x59, %eax
je 0x50f1
cmpl $0x4e, %eax
je 0x516c
movq %r14, %rdi
leaq 0x5feb(%rip), %rsi      # 0xb0d5
callq 0x4330
jmp 0x50aa
leaq 0x5f36(%rip), %rsi      # 0xb02e
jmp 0x4c29
movq %r15, %rdi
leaq 0x5f88(%rip), %rsi      # 0xb08f
callq 0x6097
testb %al, %al
jne 0x5128
leaq 0xb8(%rsp), %rdi
leaq 0x5f75(%rip), %rsi      # 0xb094
callq 0x6097
testb %al, %al
je 0x5158
leaq 0x18(%rsp), %rax
movq %rax, 0x8(%rsp)
andq $0x0, 0x10(%rsp)
movb $0x0, 0x18(%rsp)
movq 0xae9c(%rip), %rdi      # 0xffe0
leaq 0x8(%rsp), %rsi
callq 0x4420
callq 0x5f42
jmp 0x50a0
movq %r14, %rdi
leaq 0x5f37(%rip), %rsi      # 0xb099
callq 0x4330
jmp 0x50aa
leaq 0xd8(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x4470
leaq 0xd8(%rsp), %rdi
callq 0x5bcc
leaq 0xd8(%rsp), %rdi
callq 0x4678
xorl %ebx, %ebx
leaq 0x5ee3(%rip), %r14      # 0xb084
leaq 0xb2c8(%rip), %r15      # 0x10470
leaq 0x8(%rsp), %r12
leaq 0x28(%rsp), %r13
leaq 0x98(%rsp), %rbp
movl %ebx, %ebx
movq 0xb29d(%rip), %rcx      # 0x10460
movq 0xb28e(%rip), %rax      # 0x10458
subq %rax, %rcx
sarq $0x5, %rcx
cmpq %rbx, %rcx
jbe 0x521f
movq %rbx, %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, 0x28(%rsp)
movl $0x2, 0x98(%rsp)
movq %r12, %rdi
leaq 0x1bb2(%rip), %rsi      # 0x6dac
movq %r13, %rdx
movq %rbp, %rcx
movq %r14, %r8
movq %r15, %r9
callq 0x61f4
movq %r12, %rdi
callq 0x4580
movq %r12, %rdi
callq 0x61dc
incl %ebx
jmp 0x51ba
movq 0xada2(%rip), %rdi      # 0xffc8
leaq 0x61a7(%rip), %rsi      # 0xb3d4
callq 0x4330
leaq 0x78(%rsp), %rdi
callq 0x4678
leaq 0xb8(%rsp), %rdi
callq 0x4678
xorl %eax, %eax
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xad64(%rip), %rdi      # 0xffc8
leaq 0x5dea(%rip), %rsi      # 0xb055
callq 0x4330
jmp 0x5285
movq 0xad4f(%rip), %rdi      # 0xffc8
leaq 0x5dd5(%rip), %rsi      # 0xb055
callq 0x4330
leaq 0x8(%rsp), %rdi
callq 0x4678
jmp 0x5232
jmp 0x52bc
jmp 0x52bc
jmp 0x52bc
jmp 0x52bc
jmp 0x52bc
jmp 0x52b5
movq %rax, %rbx
leaq 0x1b8(%rsp), %rdi
callq 0x4678
jmp 0x52d4
jmp 0x52b5
jmp 0x52bc
jmp 0x52bc
movq %rax, %rbx
jmp 0x52d4
jmp 0x52bc
movq %rax, %rbx
jmp 0x53c4
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x61dc
leaq 0x28(%rsp), %rdi
callq 0x61dc
jmp 0x53c4
movq %rax, %rbx
leaq 0xd8(%rsp), %rdi
jmp 0x53c9
movq %rax, %rbx
jmp 0x5399
jmp 0x53aa
jmp 0x53aa
movq %rax, %rbx
leaq 0x138(%rsp), %rdi
jmp 0x532c
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
jmp 0x532c
jmp 0x53aa
movq %rax, %rbx
leaq 0x1d8(%rsp), %rdi
callq 0x4678
jmp 0x53ad
movq %rax, %rbx
leaq 0x158(%rsp), %rdi
callq 0x4678
jmp 0x5348
movq %rax, %rbx
leaq 0xf8(%rsp), %rdi
callq 0x4678
jmp 0x535a
movq %rax, %rbx
leaq 0x178(%rsp), %rdi
callq 0x4678
jmp 0x536c
movq %rax, %rbx
leaq 0x198(%rsp), %rdi
jmp 0x53b5
jmp 0x53a5
movq %rax, %rbx
leaq 0x118(%rsp), %rdi
jmp 0x53c9
movq %rax, %rbx
jmp 0x53f4
jmp 0x53e7
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x61dc
leaq 0x58(%rsp), %rdi
callq 0x61dc
jmp 0x53ad
movq %rax, %rbx
jmp 0x53ba
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x4678
leaq 0x28(%rsp), %rdi
callq 0x4678
leaq 0x8(%rsp), %rdi
callq 0x4678
jmp 0x53ea
jmp 0x53e7
jmp 0x53e7
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x61dc
jmp 0x53ea
jmp 0x53e7
jmp 0x53e7
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x4678
leaq 0xb8(%rsp), %rdi
callq 0x4678
movq %rbx, %rdi
callq 0x45b0