// File: dak98[P]SocketIO/src/client.cpp
// Function: socket_io::client::client(socket_io::socket&&, boost::variant<socket_io::socket_address<sockaddr_in>, socket_io::socket_address<sockaddr_in6>> const&)
client::client(socket&& client,
	       ip_socket_address const& address_of_server)
    : main_socket{std::move(client)}, address_of_server{address_of_server}
{
    bool is_ipv4 = address_of_server.type() == typeid(ipv4_socket_address);
    auto ip_version = main_socket.get_ip_protocol();

    if ((is_ipv4 && ip_version == ip_protocol::IPv6) ||
	(!is_ipv4 && ip_version == ip_protocol::IPv4))
	throw std::logic_error{"Socket and address have different protocols"};
    
    if (is_ipv4)
    {
	auto to_connect = boost::get<ipv4_socket_address>(address_of_server);
	sockaddr_in addr_in = to_connect.get_native_handle();
	socket_io::connect(main_socket, reinterpret_cast<sockaddr*>(&addr_in),
			   sizeof(sockaddr_in));
    }
    else
    {
	auto to_connect = boost::get<ipv6_socket_address>(address_of_server);	
	sockaddr_in6 addr_in6 = to_connect.get_native_handle();
	socket_io::connect(main_socket, reinterpret_cast<sockaddr*>(&addr_in6),
			   sizeof(sockaddr_in6));
    }


    std::string idStr;
    main_socket.make_view() >> idStr;
    id = string_to_integer<int>(idStr);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0xe8(%rbp)
movq %rdi, %rax
movq %rax, -0xf0(%rbp)
movq -0x10(%rbp), %rsi
callq 0x1f450
movq -0xe8(%rbp), %rdi
addq $0x8, %rdi
movq %rdi, -0xe0(%rbp)
movq -0x18(%rbp), %rsi
callq 0x20490
jmp 0x24212
movq -0x18(%rbp), %rdi
callq 0x1e080
movq %rax, -0xf8(%rbp)
jmp 0x24224
movq -0xf8(%rbp), %rdi
movq 0x16da6(%rip), %rsi     # 0x3afd8
callq 0x1eec0
movq -0xf0(%rbp), %rdi
movb %al, -0x25(%rbp)
callq 0x200d0
movl %eax, -0xfc(%rbp)
jmp 0x2424e
movl -0xfc(%rbp), %eax
movl %eax, -0x2c(%rbp)
testb $0x1, -0x25(%rbp)
je 0x24263
cmpl $0xa, -0x2c(%rbp)
je 0x24277
testb $0x1, -0x25(%rbp)
jne 0x242fa
cmpl $0x2, -0x2c(%rbp)
jne 0x242fa
movl $0x10, %edi
callq 0x1ea70
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x108(%rbp)
leaq 0xcf3b(%rip), %rsi      # 0x311d0
callq 0x200f0
jmp 0x2429c
movq -0x108(%rbp), %rdi
movq 0x16d06(%rip), %rsi     # 0x3afb0
movq 0x16ca7(%rip), %rdx     # 0x3af58
callq 0x20690
jmp 0x24468
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x24453
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x24447
movq -0x108(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
callq 0x1efc0
jmp 0x24447
testb $0x1, -0x25(%rbp)
je 0x24352
movq -0x18(%rbp), %rdi
callq 0x1ed70
movq %rax, -0x110(%rbp)
jmp 0x24312
movq -0x110(%rbp), %rax
movq 0x10(%rax), %rcx
movq %rcx, -0x40(%rbp)
movups (%rax), %xmm0
movaps %xmm0, -0x50(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x1e520
movq -0xf0(%rbp), %rdi
movq %rax, -0x60(%rbp)
movq %rdx, -0x58(%rbp)
leaq -0x60(%rbp), %rsi
movl $0x10, %edx
callq 0x24470
jmp 0x24350
jmp 0x243bb
movq -0x18(%rbp), %rdi
callq 0x20980
movq %rax, -0x118(%rbp)
jmp 0x24364
movq -0x118(%rbp), %rax
movq 0x20(%rax), %rcx
movq %rcx, -0x70(%rbp)
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movaps %xmm1, -0x80(%rbp)
movaps %xmm0, -0x90(%rbp)
leaq -0xac(%rbp), %rdi
movq %rdi, -0x120(%rbp)
leaq -0x90(%rbp), %rsi
callq 0x1fab0
movq -0xf0(%rbp), %rdi
movq -0x120(%rbp), %rsi
movl $0x1c, %edx
callq 0x24470
jmp 0x243b9
jmp 0x243bb
leaq -0xd0(%rbp), %rdi
movq %rdi, -0x128(%rbp)
callq 0x1fed0
movq -0xf0(%rbp), %rdi
callq 0x1e3c0
movq -0x128(%rbp), %rsi
movq %rax, -0xd8(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x1e7e0
jmp 0x243f6
leaq -0xd0(%rbp), %rdi
callq 0x20280
movl %eax, -0x12c(%rbp)
jmp 0x2440a
movq -0xf0(%rbp), %rax
movl -0x12c(%rbp), %ecx
movl %ecx, 0x38(%rax)
leaq -0xd0(%rbp), %rdi
callq 0x1ed60
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x1ed60
movq -0xe0(%rbp), %rdi
callq 0x20700
movq -0xe8(%rbp), %rdi
callq 0x1f7d0
movq -0x20(%rbp), %rdi
callq 0x20840
nopl (%rax,%rax)