// File: /workspace/github_cpp_makefile_star2_O2/amit-mittal[P]FTP/ftpClient.cpp
// Function: ftpClient::connect(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int)
int ftpClient::connect(string serverIP, int controlPort){
	c_socket.setIp(serverIP);
	c_socket.setPort(controlPort);
	c_socket.setHints(0);
	if(c_socket.connect() != 0)
		return 1;
	cout << "Successfully connected to server (control socket): " << serverIP << endl;

	tcpSocket d_socket_init;
	d_socket_init.setPort(CLIENT_PORT);
	d_socket_init.setHints(1);
	if(d_socket_init.bind() != 0){
		return 2;
	}
	if(d_socket_init.listen() != 0){
		return 3;
	}

	printf("Successfully started on PORT: %d\n", d_socket_init.getPort());
	
	//sending this new_port to the server
	if(sendControl(getStrFromInt(CLIENT_PORT)) == -1){
		return 4;
	}

	d_socket = d_socket_init.accept();
	if(d_socket.getSocket() == -1){
		return 5;
	}
	
	printf("Successfully connected to server(data port)\n");
	printf("Type 'help' for more info\n\n");

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x220, %rsp            # imm = 0x220
movl %edx, %r15d
movq %rsi, %rbx
movq %rdi, %r14
leaq -0x60(%rbp), %r12
movq %r12, %rdi
callq 0x22e0
leaq 0x8(%r14), %rdi
movq %r12, %rsi
callq 0x2140
leaq -0x60(%rbp), %rdi
callq 0x2110
movw %r15w, 0x28(%r14)
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%r14)
movups %xmm0, 0x40(%r14)
movups %xmm0, 0x50(%r14)
movl $0x1, 0x38(%r14)
movq %r14, %rdi
callq 0x2712
testl %eax, %eax
je 0x3050
pushq $0x1
popq %r14
jmp 0x30e8
movq 0x4f71(%rip), %rdi      # 0x7fc8
leaq 0x207a(%rip), %rsi      # 0x50d8
callq 0x2210
movq %rax, %rdi
movq %rbx, %rsi
callq 0x21e0
movq %rax, %rdi
callq 0x2120
leaq -0x148(%rbp), %rbx
leaq -0x138(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movl $0x80, 0xd0(%rax)
movw $0x4e20, 0x10(%rax)     # imm = 0x4E20
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%rax)
movups %xmm0, 0x28(%rax)
movups %xmm0, 0x38(%rax)
pushq $0x1
popq %rcx
movl %ecx, 0x20(%rax)
movl %ecx, 0x18(%rax)
leaq -0x150(%rbp), %rdi
callq 0x2894
testl %eax, %eax
je 0x30cc
pushq $0x2
jmp 0x30de
leaq -0x150(%rbp), %rdi
callq 0x2a44
testl %eax, %eax
je 0x30fb
pushq $0x3
popq %r14
movq %rbx, %rdi
callq 0x2110
movl %r14d, %eax
addq $0x220, %rsp            # imm = 0x220
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movzwl -0x128(%rbp), %esi
leaq 0x2003(%rip), %rdi      # 0x510c
xorl %eax, %eax
callq 0x2040
leaq -0x40(%rbp), %rdi
movl $0x4e20, %esi           # imm = 0x4E20
callq 0x31d2
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
callq 0x2be6
movl %eax, %r15d
leaq -0x40(%rbp), %rdi
callq 0x2110
cmpl $-0x1, %r15d
je 0x3198
leaq -0x240(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0x2a6e
leaq 0xf0(%r14), %rdi
leaq -0x240(%rbp), %rsi
callq 0x46e6
leaq -0x238(%rbp), %rdi
callq 0x2110
cmpl $-0x1, 0xf0(%r14)
je 0x319f
leaq 0x24ec(%rip), %rdi      # 0x566b
callq 0x2350
leaq 0x250c(%rip), %rdi      # 0x5697
callq 0x2350
xorl %r14d, %r14d
jmp 0x30e0
pushq $0x4
jmp 0x30de
pushq $0x5
jmp 0x30de
jmp 0x31b6
movq %rax, %r14
leaq -0x40(%rbp), %rdi
callq 0x2110
jmp 0x31b9
movq %rax, %r14
movq %rbx, %rdi
jmp 0x31c5
movq %rax, %r14
leaq -0x60(%rbp), %rdi
callq 0x2110
movq %r14, %rdi
callq 0x23d0