// File: vianna274[P]dropbox/src/Client.cpp
// Function: Dropbox::Client::download(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void Client::download(string filename){
	MessageData request = make_packet(TYPE_REQUEST_DOWNLOAD, 1 , 1, -1, filename.c_str());
	this->socket->send(&request);

	char cCurrentPath[FILENAME_MAX];
	if (!getcwd(cCurrentPath, sizeof(cCurrentPath))) 
		cout << "ERROR GETTING THE CURRENT DIRECTORY!!" << endl;
	cCurrentPath[sizeof(cCurrentPath) - 1] = '\0';
	string currentPath(cCurrentPath);
	currentPath += "/";

	MessageData *data = this->socket->receive(TIMEOUT_OFF);
	if(data->type == TYPE_SEND_FILE) {
		FileRecord * fileRecord = (FileRecord *)(data->payload);
		this->receiveFile(this->socket, string(fileRecord->filename), currentPath);
	}
	else if(data->type == TYPE_NOTHING_TO_SEND)
		cout << "File does not exist." << endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20c0, %rsp           # imm = 0x20C0
movq %rsi, -0x2090(%rbp)
movq %rdi, %rax
movq -0x2090(%rbp), %rdi
movq %rax, -0x8(%rbp)
movq %rdi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x2088(%rbp)
callq 0x3180
movq %rax, %r9
leaq -0xfe4(%rbp), %rdi
movl $0x8, %esi
movl $0x1, %ecx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
movl %ecx, %edx
callq 0x97a0
movq -0x2088(%rbp), %rax
movq 0x40(%rax), %rdi
leaq -0xfe4(%rbp), %rsi
callq 0x17d90
leaq -0x1ff0(%rbp), %rdi
movl $0x1000, %esi           # imm = 0x1000
callq 0x3200
cmpq $0x0, %rax
jne 0x6255
movq 0x1cd8e(%rip), %rdi     # 0x22fc8
leaq 0x12e95(%rip), %rsi     # 0x190d6
callq 0x33a0
movq %rax, %rdi
movq 0x1cd60(%rip), %rsi     # 0x22fb0
callq 0x33d0
movb $0x0, -0xff1(%rbp)
leaq -0x2011(%rbp), %rdi
movq %rdi, -0x2098(%rbp)
callq 0x3620
movq -0x2098(%rbp), %rdx
leaq -0x2010(%rbp), %rdi
leaq -0x1ff0(%rbp), %rsi
callq 0x3480
jmp 0x628b
leaq -0x2011(%rbp), %rdi
callq 0x33e0
leaq 0x13169(%rip), %rsi     # 0x19407
leaq -0x2010(%rbp), %rdi
callq 0x3390
jmp 0x62ac
movq -0x2088(%rbp), %rax
movq 0x40(%rax), %rdi
xorl %esi, %esi
callq 0x18090
movq %rax, -0x20a0(%rbp)
jmp 0x62c7
movq -0x20a0(%rbp), %rax
movq %rax, -0x2030(%rbp)
movq -0x2030(%rbp), %rax
cmpl $0x3, (%rax)
jne 0x6441
movq -0x2088(%rbp), %rax
movq -0x2030(%rbp), %rcx
addq $0x14, %rcx
movq %rcx, -0x2038(%rbp)
movq 0x40(%rax), %rax
movq %rax, -0x20b8(%rbp)
movq -0x2038(%rbp), %rax
movq %rax, -0x20b0(%rbp)
leaq -0x2059(%rbp), %rdi
movq %rdi, -0x20a8(%rbp)
callq 0x3620
movq -0x20b0(%rbp), %rsi
movq -0x20a8(%rbp), %rdx
leaq -0x2058(%rbp), %rdi
callq 0x3480
jmp 0x6346
leaq -0x2080(%rbp), %rdi
leaq -0x2010(%rbp), %rsi
callq 0x3190
jmp 0x635b
movq -0x20b8(%rbp), %rsi
movq -0x2088(%rbp), %rdi
leaq -0x2058(%rbp), %rdx
leaq -0x2080(%rbp), %rcx
callq 0x9c30
jmp 0x637e
leaq -0x2080(%rbp), %rdi
callq 0x3280
leaq -0x2058(%rbp), %rdi
callq 0x3280
leaq -0x2059(%rbp), %rdi
callq 0x33e0
jmp 0x6482
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2020(%rbp)
movl %eax, -0x2024(%rbp)
leaq -0x2011(%rbp), %rdi
callq 0x33e0
jmp 0x64a3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2020(%rbp)
movl %eax, -0x2024(%rbp)
jmp 0x6497
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2020(%rbp)
movl %eax, -0x2024(%rbp)
jmp 0x6433
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2020(%rbp)
movl %eax, -0x2024(%rbp)
jmp 0x6427
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2020(%rbp)
movl %eax, -0x2024(%rbp)
leaq -0x2080(%rbp), %rdi
callq 0x3280
leaq -0x2058(%rbp), %rdi
callq 0x3280
leaq -0x2059(%rbp), %rdi
callq 0x33e0
jmp 0x6497
movq -0x2030(%rbp), %rax
cmpl $0x7, (%rax)
jne 0x6480
movq 0x1cb74(%rip), %rdi     # 0x22fc8
leaq 0x12ca1(%rip), %rsi     # 0x190fc
callq 0x33a0
movq %rax, -0x20c0(%rbp)
jmp 0x6469
movq -0x20c0(%rbp), %rdi
movq 0x1cb39(%rip), %rsi     # 0x22fb0
callq 0x33d0
jmp 0x647e
jmp 0x6480
jmp 0x6482
leaq -0x2010(%rbp), %rdi
callq 0x3280
addq $0x20c0, %rsp           # imm = 0x20C0
popq %rbp
retq
leaq -0x2010(%rbp), %rdi
callq 0x3280
movq -0x2020(%rbp), %rdi
callq 0x3610
nop