// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x228, %rsp            # imm = 0x228
movq %rdx, %r12
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x2bb3(%rip), %rdi      # 0x171cd
callq 0x55a0
leaq -0x250(%rbp), %rdi
movq %r14, %rsi
movl $0x4, %edx
callq 0x55d0
leaq -0x1d8(%rbp), %r14
movq %r14, %rdi
callq 0x50c0
testb %al, %al
je 0x14773
movl $0x400, %edi            # imm = 0x400
callq 0x5030
movq %rax, %r15
movl $0x400, %edx            # imm = 0x400
movq %rax, %rdi
xorl %esi, %esi
callq 0x5230
leaq 0x2acc(%rip), %rsi      # 0x17139
leaq -0x48(%rbp), %rdi
movq %r12, %rdx
callq 0x14ea5
movl 0x14(%rbx), %edi
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
xorl %ecx, %ecx
callq 0x51f0
movq %r14, %rdi
callq 0x50c0
testb %al, %al
je 0x1474a
leaq 0x2b86(%rip), %r12      # 0x17228
leaq -0x250(%rbp), %r13
movq %r12, %rdi
callq 0x55a0
movl $0x400, %edx            # imm = 0x400
movq %r13, %rdi
movq %r15, %rsi
callq 0x5480
movq -0x250(%rbp), %rax
movq -0x18(%rax), %rax
testb $0x2, -0x230(%rbp,%rax)
jne 0x14705
leaq 0x2b58(%rip), %rdi      # 0x17235
callq 0x55a0
movl 0x14(%rbx), %edi
movl $0x400, %edx            # imm = 0x400
movq %r15, %rsi
xorl %ecx, %ecx
callq 0x51f0
movl $0x400, %edx            # imm = 0x400
movq %r15, %rdi
xorl %esi, %esi
callq 0x5230
jmp 0x1473a
leaq 0x2b36(%rip), %rdi      # 0x17242
callq 0x55a0
movl 0x14(%rbx), %edi
movl $0x400, %edx            # imm = 0x400
movq %r15, %rsi
xorl %ecx, %ecx
callq 0x51f0
movl $0x400, %edx            # imm = 0x400
movq %r15, %rdi
xorl %esi, %esi
callq 0x5230
movq %r13, %rdi
callq 0x50b0
movq %r14, %rdi
callq 0x50c0
testb %al, %al
jne 0x146a9
leaq 0x2a8e(%rip), %rdi      # 0x171df
callq 0x55a0
leaq -0x38(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1476f
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x5370
xorl %ebx, %ebx
jmp 0x14786
leaq 0x29ac(%rip), %rdi      # 0x17126
xorl %eax, %eax
callq 0x5070
movl $0x1, %ebx
leaq -0x250(%rbp), %rdi
callq 0x50e0
movl %ebx, %eax
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x147af
jmp 0x147aa
movq %rax, %rbx
jmp 0x147cb
movq %rax, %rbx
leaq -0x38(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x147cb
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x5370
leaq -0x250(%rbp), %rdi
callq 0x50e0
movq %rbx, %rdi
callq 0x5630
nop