// File: /workspace/github_cpp_makefile_star2_O2/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 0x2719(%rip), %rdi      # 0x151cd
callq 0x55b0
leaq -0x250(%rbp), %rdi
pushq $0x4
popq %rdx
movq %r14, %rsi
callq 0x55f0
leaq -0x1d8(%rbp), %r14
movq %r14, %rdi
callq 0x50d0
testb %al, %al
je 0x12bd7
movl $0x400, %edi            # imm = 0x400
callq 0x5030
movq %rax, %r15
movl $0x400, %edx            # imm = 0x400
movq %rax, %rdi
xorl %esi, %esi
callq 0x5270
leaq 0x2634(%rip), %rsi      # 0x15139
leaq -0x48(%rbp), %rdi
movq %r12, %rdx
callq 0x13079
movl 0x14(%rbx), %edi
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
xorl %ecx, %ecx
callq 0x5230
leaq 0x26fe(%rip), %r12      # 0x15228
leaq -0x250(%rbp), %r13
movq %r14, %rdi
callq 0x50d0
testb %al, %al
je 0x12bea
movq %r12, %rdi
callq 0x55b0
movl $0x400, %edx            # imm = 0x400
movq %r13, %rdi
movq %r15, %rsi
callq 0x5490
movq -0x250(%rbp), %rax
movq -0x18(%rax), %rax
testb $0x2, -0x230(%rbp,%rax)
jne 0x12b9d
leaq 0x26c0(%rip), %rdi      # 0x15235
callq 0x55b0
movl 0x14(%rbx), %edi
movl $0x400, %edx            # imm = 0x400
movq %r15, %rsi
xorl %ecx, %ecx
callq 0x5230
movl $0x400, %edx            # imm = 0x400
movq %r15, %rdi
xorl %esi, %esi
callq 0x5270
jmp 0x12b31
leaq 0x269e(%rip), %rdi      # 0x15242
callq 0x55b0
movl 0x14(%rbx), %edi
movl $0x400, %edx            # imm = 0x400
movq %r15, %rsi
xorl %ecx, %ecx
callq 0x5230
movl $0x400, %edx            # imm = 0x400
movq %r15, %rdi
xorl %esi, %esi
callq 0x5270
movq %r13, %rdi
callq 0x50b0
jmp 0x12b31
leaq 0x2548(%rip), %rdi      # 0x15126
xorl %eax, %eax
callq 0x5060
pushq $0x1
popq %rbx
jmp 0x12c01
leaq 0x25ee(%rip), %rdi      # 0x151df
callq 0x55b0
leaq -0x48(%rbp), %rdi
callq 0x51e0
xorl %ebx, %ebx
leaq -0x250(%rbp), %rdi
callq 0x5100
movl %ebx, %eax
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x12c2a
jmp 0x12c25
movq %rax, %rbx
jmp 0x12c36
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x51e0
leaq -0x250(%rbp), %rdi
callq 0x5100
movq %rbx, %rdi
callq 0x5660