// File: /workspace/github_cpp_makefile_star2_O1/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 %r13
pushq %r12
pushq %rbx
subq $0x228, %rsp            # imm = 0x228
movl %edx, %r15d
movq %rsi, %r14
movq %rdi, %rbx
leaq -0x58(%rbp), %r13
movq %r13, -0x10(%r13)
movq (%rsi), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq -0x68(%rbp), %r12
movq %r12, %rdi
callq 0x621c
leaq 0x8(%rbx), %rdi
movq %r12, %rsi
callq 0x3150
movq -0x68(%rbp), %rdi
cmpq %r13, %rdi
je 0x4409
callq 0x3210
movw %r15w, 0x28(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%rbx)
movups %xmm0, 0x40(%rbx)
movups %xmm0, 0x50(%rbx)
movl $0x1, 0x38(%rbx)
movq %rbx, %rdi
callq 0x390c
movl $0x1, %r15d
testl %eax, %eax
jne 0x451d
movq 0x5b8f(%rip), %r15      # 0x9fd0
leaq 0x2c90(%rip), %rsi      # 0x70d8
movl $0x33, %edx
movq %r15, %rdi
callq 0x32b0
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq %r15, %rdi
callq 0x32b0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3220
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3170
leaq -0x140(%rbp), %r12
movq %r12, -0x10(%r12)
movq $0x0, -0x8(%r12)
movb $0x0, (%r12)
movl $0x80, 0xd0(%r12)
movw $0x4e20, 0x10(%r12)     # imm = 0x4E20
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%r12)
movups %xmm0, 0x28(%r12)
movups %xmm0, 0x38(%r12)
movl $0x1, %eax
movl %eax, 0x20(%r12)
movl %eax, 0x18(%r12)
leaq -0x158(%rbp), %rdi
callq 0x3a98
movl $0x2, %r15d
testl %eax, %eax
jne 0x450c
leaq -0x158(%rbp), %rdi
callq 0x3c60
movl $0x3, %r15d
testl %eax, %eax
je 0x4532
movq -0x150(%rbp), %rdi
cmpq %r12, %rdi
je 0x451d
callq 0x3210
movl %r15d, %eax
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movzwl -0x130(%rbp), %esi
leaq 0x2bcc(%rip), %rdi      # 0x710c
xorl %eax, %eax
callq 0x3050
leaq -0x48(%rbp), %rdi
movl $0x4e20, %esi           # imm = 0x4E20
callq 0x4661
leaq -0x48(%rbp), %rsi
movq %rbx, %rdi
callq 0x3ed2
movl %eax, %r14d
leaq -0x38(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4576
callq 0x3210
cmpl $-0x1, %r14d
je 0x4608
leaq -0x248(%rbp), %rdi
leaq -0x158(%rbp), %rsi
callq 0x3c8e
leaq -0x240(%rbp), %rsi
movl -0x8(%rsi), %eax
movl %eax, 0xf0(%rbx)
leaq 0xf8(%rbx), %rdi
callq 0x32f0
leaq 0x118(%rbx), %rdi
leaq -0x220(%rbp), %r14
movl $0xc4, %edx
movq %r14, %rsi
callq 0x31c0
movq -0x20(%r14), %rdi
leaq -0x230(%rbp), %rax
cmpq %rax, %rdi
je 0x45df
callq 0x3210
cmpl $-0x1, 0xf0(%rbx)
je 0x4613
leaq 0x30a6(%rip), %rdi      # 0x7695
callq 0x3390
leaq 0x30c6(%rip), %rdi      # 0x76c1
callq 0x3390
xorl %r15d, %r15d
jmp 0x450c
movl $0x4, %r15d
jmp 0x450c
movl $0x5, %r15d
jmp 0x450c
jmp 0x4637
movq %rax, %rbx
leaq -0x38(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x463a
callq 0x3210
jmp 0x463a
movq %rax, %rbx
movq -0x150(%rbp), %rdi
cmpq %r12, %rdi
jne 0x4654
jmp 0x4659
movq %rax, %rbx
movq -0x68(%rbp), %rdi
cmpq %r13, %rdi
je 0x4659
callq 0x3210
movq %rbx, %rdi
callq 0x3450