// File: vianna274[P]dropbox/client.cpp
// Function: main
int main(int argc, char *argv[])
{
	bool endSession = false;
	
	if(argc != 4){
        cout << "Incorrect number of arguments.\nExpected ./build/client <username> <server_ip_adress> <local_ip>" << endl;
        return -1;
	}
	string username(argv[1]);
	string serverIP(argv[2]);
	string localIp(argv[3]);
	Dropbox::Client client(username, serverIP, SERVER_PORT, localIp);

	while(!endSession){
		
		vector<string> arguments = getArguments();
		if(arguments.size() > 0 && arguments.size() < 3){
			client.lockMutex();
			
			string command = arguments[0];
			boost::to_upper(command);
			if (command == "UPLOAD"){
				if(arguments.size() != 2) puts("Wrong size of command -- upload <file path>");
				else {
					client.sendFile(client.getSocket(), arguments[1], client.getUsername());
				}

			}else if (command == "DOWNLOAD"){
				if(arguments.size() != 2) puts("Wrong size of command -- download <file path>");
				else {
					client.download(arguments[1]);
				}
			}else if (command == "DELETE"){
				if(arguments.size() != 2) puts("Wrong size of command -- delete <file path>");
				else {
					client.sendDeleteFile(client.getSocket(), arguments[1], client.getUsername());
				}

			}else if (command == "LIST_SERVER"){
				if(arguments.size() != 1) puts("Wrong size of command -- list_server");
				else {
					client.requestServerFileList();
				}

			}else if (command == "LIST_CLIENT"){
				if(arguments.size() != 1) puts("Wrong size of command -- list_client");
				else {
					client.list_client();
				}

			}else if (command == "GET_SYNC_DIR"){
				if(arguments.size() != 1) puts("Wrong size of command -- get_sync_dir");
				else { 
					client.get_sync_dir();
				}

			}else if(command == "EXIT"){
				if(arguments.size() != 1) puts("Wrong size of command -- exit");
				else {
					client.exit();
					endSession = true;
				}

			} else {
				puts("Unidentified command!");
			}

			client.unlockMutex();
		}
	}

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x340, %rsp            # imm = 0x340
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movb $0x0, -0x11(%rbp)
cmpl $0x4, -0x8(%rbp)
je 0x19a01
movq 0x105e6(%rip), %rdi     # 0x29fc0
leaq 0x4cf9(%rip), %rsi      # 0x1e6da
callq 0x4470
movq %rax, %rdi
movq 0x105b8(%rip), %rsi     # 0x29fa8
callq 0x44b0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1a217
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x2f0(%rbp)
leaq -0x39(%rbp), %rdi
movq %rdi, -0x2e8(%rbp)
callq 0x4790
movq -0x2f0(%rbp), %rsi
movq -0x2e8(%rbp), %rdx
leaq -0x38(%rbp), %rdi
callq 0x45b0
jmp 0x19a39
leaq -0x39(%rbp), %rdi
callq 0x44d0
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x300(%rbp)
leaq -0x71(%rbp), %rdi
movq %rdi, -0x2f8(%rbp)
callq 0x4790
movq -0x300(%rbp), %rsi
movq -0x2f8(%rbp), %rdx
leaq -0x70(%rbp), %rdi
callq 0x45b0
jmp 0x19a7a
leaq -0x71(%rbp), %rdi
callq 0x44d0
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x310(%rbp)
leaq -0x99(%rbp), %rdi
movq %rdi, -0x308(%rbp)
callq 0x4790
movq -0x310(%rbp), %rsi
movq -0x308(%rbp), %rdx
leaq -0x98(%rbp), %rdi
callq 0x45b0
jmp 0x19ac1
leaq -0x99(%rbp), %rdi
callq 0x44d0
leaq -0x1c0(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x41e0
jmp 0x19adf
leaq -0x1e0(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x41e0
jmp 0x19af1
leaq -0x200(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x41e0
jmp 0x19b06
leaq -0x1a0(%rbp), %rdi
leaq -0x1c0(%rbp), %rsi
leaq -0x1e0(%rbp), %rdx
movl $0xfa0, %ecx            # imm = 0xFA0
leaq -0x200(%rbp), %r8
callq 0x4b00
jmp 0x19b2e
leaq -0x200(%rbp), %rdi
callq 0x42f0
leaq -0x1e0(%rbp), %rdi
callq 0x42f0
leaq -0x1c0(%rbp), %rdi
callq 0x42f0
movb -0x11(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x19b60
jmp 0x1a1b8
leaq -0x218(%rbp), %rdi
callq 0x197d0
jmp 0x19b6e
leaq -0x218(%rbp), %rdi
callq 0x13450
cmpq $0x0, %rax
jbe 0x1a199
leaq -0x218(%rbp), %rdi
callq 0x13450
cmpq $0x3, %rax
jae 0x1a199
leaq -0x1a0(%rbp), %rdi
callq 0x7c60
jmp 0x19ba8
xorl %eax, %eax
movl %eax, %esi
leaq -0x218(%rbp), %rdi
callq 0x1af10
movq %rax, %rsi
leaq -0x238(%rbp), %rdi
callq 0x41e0
jmp 0x19bc9
leaq -0x240(%rbp), %rdi
movq %rdi, -0x318(%rbp)
callq 0x4830
movq -0x318(%rbp), %rsi
leaq -0x238(%rbp), %rdi
callq 0x1af30
jmp 0x19bf1
leaq -0x240(%rbp), %rdi
callq 0x45e0
leaq 0x4b36(%rip), %rsi      # 0x1e73a
leaq -0x238(%rbp), %rdi
callq 0x1af80
movb %al, -0x319(%rbp)
jmp 0x19c18
movb -0x319(%rbp), %al
testb $0x1, %al
jne 0x19c27
jmp 0x19e18
leaq -0x218(%rbp), %rdi
callq 0x13450
cmpq $0x2, %rax
je 0x19d53
leaq 0x4afd(%rip), %rdi      # 0x1e741
callq 0x46b0
jmp 0x19c4b
jmp 0x19e13
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x39(%rbp), %rdi
callq 0x44d0
jmp 0x1a223
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x71(%rbp), %rdi
callq 0x44d0
jmp 0x1a20c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x99(%rbp), %rdi
callq 0x44d0
jmp 0x1a203
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x1a1f7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x19cf2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x19ce6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x200(%rbp), %rdi
callq 0x42f0
leaq -0x1e0(%rbp), %rdi
callq 0x42f0
leaq -0x1c0(%rbp), %rdi
callq 0x42f0
jmp 0x1a1f7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x1a1eb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x1a1aa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x240(%rbp), %rdi
callq 0x45e0
jmp 0x1a18b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x1a18b
leaq -0x1a0(%rbp), %rdi
callq 0x8440
movq %rax, -0x328(%rbp)
jmp 0x19d68
leaq -0x218(%rbp), %rdi
movl $0x1, %esi
callq 0x1af10
movq %rax, %rsi
leaq -0x260(%rbp), %rdi
callq 0x41e0
jmp 0x19d8a
leaq -0x280(%rbp), %rdi
leaq -0x1a0(%rbp), %rsi
callq 0x1afb0
jmp 0x19d9f
movq -0x328(%rbp), %rsi
leaq -0x1a0(%rbp), %rdi
leaq -0x260(%rbp), %rdx
leaq -0x280(%rbp), %rcx
callq 0xb9a0
jmp 0x19dc2
leaq -0x280(%rbp), %rdi
callq 0x42f0
leaq -0x260(%rbp), %rdi
callq 0x42f0
jmp 0x19e13
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x19e02
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x280(%rbp), %rdi
callq 0x42f0
leaq -0x260(%rbp), %rdi
callq 0x42f0
jmp 0x1a18b
jmp 0x1a16f
leaq 0x494e(%rip), %rsi      # 0x1e76d
leaq -0x238(%rbp), %rdi
callq 0x1af80
movb %al, -0x329(%rbp)
jmp 0x19e33
movb -0x329(%rbp), %al
testb $0x1, %al
jne 0x19e42
jmp 0x19ecb
leaq -0x218(%rbp), %rdi
callq 0x13450
cmpq $0x2, %rax
je 0x19e64
leaq 0x491b(%rip), %rdi      # 0x1e776
callq 0x46b0
jmp 0x19e62
jmp 0x19ec6
leaq -0x218(%rbp), %rdi
movl $0x1, %esi
callq 0x1af10
movq %rax, %rsi
leaq -0x2a0(%rbp), %rdi
callq 0x41e0
jmp 0x19e86
leaq -0x1a0(%rbp), %rdi
leaq -0x2a0(%rbp), %rsi
callq 0x7360
jmp 0x19e9b
leaq -0x2a0(%rbp), %rdi
callq 0x42f0
jmp 0x19ec6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x2a0(%rbp), %rdi
callq 0x42f0
jmp 0x1a18b
jmp 0x1a16d
leaq 0x48d2(%rip), %rsi      # 0x1e7a4
leaq -0x238(%rbp), %rdi
callq 0x1af80
movb %al, -0x32a(%rbp)
jmp 0x19ee6
movb -0x32a(%rbp), %al
testb $0x1, %al
jne 0x19ef5
jmp 0x19fdf
leaq -0x218(%rbp), %rdi
callq 0x13450
cmpq $0x2, %rax
je 0x19f1a
leaq 0x489d(%rip), %rdi      # 0x1e7ab
callq 0x46b0
jmp 0x19f15
jmp 0x19fda
leaq -0x1a0(%rbp), %rdi
callq 0x8440
movq %rax, -0x338(%rbp)
jmp 0x19f2f
leaq -0x218(%rbp), %rdi
movl $0x1, %esi
callq 0x1af10
movq %rax, %rsi
leaq -0x2c0(%rbp), %rdi
callq 0x41e0
jmp 0x19f51
leaq -0x2e0(%rbp), %rdi
leaq -0x1a0(%rbp), %rsi
callq 0x1afb0
jmp 0x19f66
movq -0x338(%rbp), %rsi
leaq -0x1a0(%rbp), %rdi
leaq -0x2c0(%rbp), %rdx
leaq -0x2e0(%rbp), %rcx
callq 0xcad0
jmp 0x19f89
leaq -0x2e0(%rbp), %rdi
callq 0x42f0
leaq -0x2c0(%rbp), %rdi
callq 0x42f0
jmp 0x19fda
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x19fc9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x2e0(%rbp), %rdi
callq 0x42f0
leaq -0x2c0(%rbp), %rdi
callq 0x42f0
jmp 0x1a18b
jmp 0x1a16b
leaq 0x47f1(%rip), %rsi      # 0x1e7d7
leaq -0x238(%rbp), %rdi
callq 0x1af80
movb %al, -0x339(%rbp)
jmp 0x19ffa
movb -0x339(%rbp), %al
testb $0x1, %al
jne 0x1a006
jmp 0x1a03d
leaq -0x218(%rbp), %rdi
callq 0x13450
cmpq $0x1, %rax
je 0x1a028
leaq 0x47c4(%rip), %rdi      # 0x1e7e3
callq 0x46b0
jmp 0x1a026
jmp 0x1a038
leaq -0x1a0(%rbp), %rdi
callq 0x7730
jmp 0x1a036
jmp 0x1a038
jmp 0x1a169
leaq 0x47c4(%rip), %rsi      # 0x1e808
leaq -0x238(%rbp), %rdi
callq 0x1af80
movb %al, -0x33a(%rbp)
jmp 0x1a058
movb -0x33a(%rbp), %al
testb $0x1, %al
jne 0x1a064
jmp 0x1a09b
leaq -0x218(%rbp), %rdi
callq 0x13450
cmpq $0x1, %rax
je 0x1a086
leaq 0x4797(%rip), %rdi      # 0x1e814
callq 0x46b0
jmp 0x1a084
jmp 0x1a096
leaq -0x1a0(%rbp), %rdi
callq 0x7660
jmp 0x1a094
jmp 0x1a096
jmp 0x1a167
leaq 0x4797(%rip), %rsi      # 0x1e839
leaq -0x238(%rbp), %rdi
callq 0x1af80
movb %al, -0x33b(%rbp)
jmp 0x1a0b6
movb -0x33b(%rbp), %al
testb $0x1, %al
jne 0x1a0c2
jmp 0x1a0f6
leaq -0x218(%rbp), %rdi
callq 0x13450
cmpq $0x1, %rax
je 0x1a0e4
leaq 0x476b(%rip), %rdi      # 0x1e846
callq 0x46b0
jmp 0x1a0e2
jmp 0x1a0f4
leaq -0x1a0(%rbp), %rdi
callq 0x5120
jmp 0x1a0f2
jmp 0x1a0f4
jmp 0x1a165
leaq 0x476f(%rip), %rsi      # 0x1e86c
leaq -0x238(%rbp), %rdi
callq 0x1af80
movb %al, -0x33c(%rbp)
jmp 0x1a111
movb -0x33c(%rbp), %al
testb $0x1, %al
jne 0x1a11d
jmp 0x1a153
leaq -0x218(%rbp), %rdi
callq 0x13450
cmpq $0x1, %rax
je 0x1a13f
leaq 0x473b(%rip), %rdi      # 0x1e871
callq 0x46b0
jmp 0x1a13d
jmp 0x1a151
leaq -0x1a0(%rbp), %rdi
callq 0x76d0
jmp 0x1a14d
movb $0x1, -0x11(%rbp)
jmp 0x1a163
leaq 0x4735(%rip), %rdi      # 0x1e88f
callq 0x46b0
jmp 0x1a161
jmp 0x1a163
jmp 0x1a165
jmp 0x1a167
jmp 0x1a169
jmp 0x1a16b
jmp 0x1a16d
jmp 0x1a16f
leaq -0x1a0(%rbp), %rdi
callq 0x7c80
jmp 0x1a17d
leaq -0x238(%rbp), %rdi
callq 0x42f0
jmp 0x1a199
leaq -0x238(%rbp), %rdi
callq 0x42f0
jmp 0x1a1aa
leaq -0x218(%rbp), %rdi
callq 0x12bb0
jmp 0x19b52
leaq -0x218(%rbp), %rdi
callq 0x12bb0
jmp 0x1a1eb
movl $0x0, -0x4(%rbp)
leaq -0x1a0(%rbp), %rdi
callq 0x6fc0
leaq -0x98(%rbp), %rdi
callq 0x42f0
leaq -0x70(%rbp), %rdi
callq 0x42f0
leaq -0x38(%rbp), %rdi
callq 0x42f0
jmp 0x1a217
leaq -0x1a0(%rbp), %rdi
callq 0x6fc0
leaq -0x98(%rbp), %rdi
callq 0x42f0
leaq -0x70(%rbp), %rdi
callq 0x42f0
leaq -0x38(%rbp), %rdi
callq 0x42f0
jmp 0x1a223
movl -0x4(%rbp), %eax
addq $0x340, %rsp            # imm = 0x340
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x4780
nopl (%rax)