// File: JohnWoodman[P]SHellNo/listener.cpp
// Function: listener::uploadFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
int listener::uploadFile(string l_path, string r_path) {
	printf("Uploading File...\n");
	std::streampos filesize = 0;
	ifstream in(l_path, std::ios::binary);

	if (!in.is_open()) {
		printf("Error Opening File");
		return 1;
	}

	char* sendbuf = new char[1024];
	int sendbuflen = 1024;
	memset(sendbuf, '\0', sendbuflen);

	string cmd = "upload:" + r_path;
	send(new_fd, cmd.c_str(), cmd.length(), 0);

	while (in.is_open()) {
		printf("File is open\n");
		in.read(sendbuf, sendbuflen);
		if (in.eof()) {
			printf("End of file\n");
			send(new_fd, sendbuf, sendbuflen, 0);
			memset(sendbuf, '\0', sendbuflen);
			in.close();
		} else {
			printf("Sending file\n");
			send(new_fd, sendbuf, sendbuflen, 0);
			memset(sendbuf, '\0', sendbuflen);
		}
	}
	printf("Finished Uploading!\n");
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2d0, %rsp            # imm = 0x2D0
movq %rsi, -0x290(%rbp)
movq %rdx, -0x2a8(%rbp)
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x2a0(%rbp)
leaq 0x46ab(%rip), %rdi      # 0x35222
xorl %eax, %eax
movl %eax, -0x294(%rbp)
callq 0x6090
movl -0x294(%rbp), %eax
movl %eax, %esi
leaq -0x30(%rbp), %rdi
callq 0x31760
movq -0x290(%rbp), %rsi
leaq -0x238(%rbp), %rdi
movq %rdi, -0x288(%rbp)
movl $0x4, %edx
callq 0x6790
movq -0x288(%rbp), %rdi
callq 0x6780
movb %al, -0x279(%rbp)
jmp 0x30bc8
movb -0x279(%rbp), %al
testb $0x1, %al
jne 0x30c11
jmp 0x30bd4
leaq 0x465a(%rip), %rdi      # 0x35235
xorl %eax, %eax
callq 0x6090
jmp 0x30be4
movl $0x1, -0x4(%rbp)
movl $0x1, -0x248(%rbp)
jmp 0x30e2a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
jmp 0x30e42
movl $0x400, %edi            # imm = 0x400
callq 0x6040
movq %rax, -0x2b0(%rbp)
jmp 0x30c24
movq -0x2b0(%rbp), %rax
movq %rax, -0x250(%rbp)
movl $0x400, -0x254(%rbp)    # imm = 0x400
movq -0x250(%rbp), %rdi
movslq -0x254(%rbp), %rdx
xorl %esi, %esi
callq 0x62c0
movq -0x2a8(%rbp), %rdx
leaq 0x45e9(%rip), %rsi      # 0x35248
leaq -0x278(%rbp), %rdi
callq 0x31650
jmp 0x30c6d
movq -0x2a0(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0x2bc(%rbp)
leaq -0x278(%rbp), %rdi
movq %rdi, -0x2c8(%rbp)
callq 0x6210
movq -0x2c8(%rbp), %rdi
movq %rax, -0x2b8(%rbp)
callq 0x6730
movl -0x2bc(%rbp), %edi
movq -0x2b8(%rbp), %rsi
movq %rax, %rdx
xorl %ecx, %ecx
callq 0x6290
jmp 0x30cbc
jmp 0x30cbe
leaq -0x238(%rbp), %rdi
callq 0x6780
movb %al, -0x2c9(%rbp)
jmp 0x30cd2
movb -0x2c9(%rbp), %al
testb $0x1, %al
jne 0x30ce1
jmp 0x30dfd
leaq 0x4568(%rip), %rdi      # 0x35250
xorl %eax, %eax
callq 0x6090
jmp 0x30cf1
movq -0x250(%rbp), %rsi
movslq -0x254(%rbp), %rdx
leaq -0x238(%rbp), %rdi
callq 0x6610
jmp 0x30d0d
movq -0x238(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x238(%rbp,%rax), %rdi
callq 0x68b0
movb %al, -0x2ca(%rbp)
jmp 0x30d2d
movb -0x2ca(%rbp), %al
testb $0x1, %al
jne 0x30d39
jmp 0x30db2
leaq 0x451e(%rip), %rdi      # 0x3525e
xorl %eax, %eax
callq 0x6090
jmp 0x30d49
movq -0x2a0(%rbp), %rax
movl 0x14(%rax), %edi
movq -0x250(%rbp), %rsi
movslq -0x254(%rbp), %rdx
xorl %ecx, %ecx
callq 0x6290
jmp 0x30d6a
movq -0x250(%rbp), %rdi
movslq -0x254(%rbp), %rdx
xorl %esi, %esi
callq 0x62c0
leaq -0x238(%rbp), %rdi
callq 0x6100
jmp 0x30d8d
jmp 0x30df8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
leaq -0x278(%rbp), %rdi
callq 0x6330
jmp 0x30e42
leaq 0x44b2(%rip), %rdi      # 0x3526b
xorl %eax, %eax
callq 0x6090
jmp 0x30dc2
movq -0x2a0(%rbp), %rax
movl 0x14(%rax), %edi
movq -0x250(%rbp), %rsi
movslq -0x254(%rbp), %rdx
xorl %ecx, %ecx
callq 0x6290
jmp 0x30de3
movq -0x250(%rbp), %rdi
movslq -0x254(%rbp), %rdx
xorl %esi, %esi
callq 0x62c0
jmp 0x30cbe
leaq 0x4475(%rip), %rdi      # 0x35279
xorl %eax, %eax
callq 0x6090
jmp 0x30e0d
movl $0x0, -0x4(%rbp)
movl $0x1, -0x248(%rbp)
leaq -0x278(%rbp), %rdi
callq 0x6330
leaq -0x238(%rbp), %rdi
callq 0x6140
movl -0x4(%rbp), %eax
addq $0x2d0, %rsp            # imm = 0x2D0
popq %rbp
retq
leaq -0x238(%rbp), %rdi
callq 0x6140
movq -0x240(%rbp), %rdi
callq 0x6850
nopw (%rax,%rax)