// File: /workspace/github_c_makefile_star2_O2/liuhaotian[P]xmppsh/libstrophe/src/conn.c
// Function: xmpp_connect_client
int xmpp_connect_client(xmpp_conn_t * const conn, 
			  const char * const altdomain,
			  unsigned short altport,
			  xmpp_conn_handler callback,
			  void * const userdata)
{
    char connectdomain[2048];
    int connectport;
    const char * domain;

    conn->type = XMPP_CLIENT;

    conn->domain = xmpp_jid_domain(conn->ctx, conn->jid);
    if (!conn->domain) return -1;

    if (altdomain) {
        xmpp_debug(conn->ctx, "xmpp", "Connecting via altdomain.");
        strcpy(connectdomain, altdomain);
        connectport = altport ? altport : 5222;
    } else if (!sock_srv_lookup("xmpp-client", "tcp", conn->domain,
                                connectdomain, 2048, &connectport)) {
	    xmpp_debug(conn->ctx, "xmpp", "SRV lookup failed.");
	    if (!altdomain)
		    domain = conn->domain;
	    else
		    domain = altdomain;
	    xmpp_debug(conn->ctx, "xmpp", "Using alternate domain %s, port %d",
                   altdomain, altport);
	    strcpy(connectdomain, domain);
	    connectport = altport ? altport : 5222;
    }
    conn->sock = sock_connect(connectdomain, connectport);
    xmpp_debug(conn->ctx, "xmpp", "sock_connect to %s:%d returned %d",
               connectdomain, connectport, conn->sock);
    if (conn->sock == -1) return -1;

    /* setup handler */
    conn->conn_handler = callback;
    conn->userdata = userdata;

    /* FIXME: it could happen that the connect returns immediately as
     * successful, though this is pretty unlikely.  This would be a little
     * hard to fix, since we'd have to detect and fire off the callback
     * from within the event loop */

    conn->state = XMPP_STATE_CONNECTING;
    conn->timeout_stamp = time_stamp();
    xmpp_debug(conn->ctx, "xmpp", "attempting to connect to %s", connectdomain);

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x818, %rsp            # imm = 0x818
movq %r8, %r14
movq %rcx, %r15
movl %edx, %r12d
movq %rsi, %r13
movq %rdi, %rbx
movl $0x1, 0x10(%rdi)
movq 0x8(%rdi), %rdi
movq 0x78(%rbx), %rsi
callq 0x683e
movq %rax, 0x60(%rbx)
pushq $-0x1
popq %rbp
testq %rax, %rax
je 0x4ced
testq %r13, %r13
je 0x4c43
movq 0x8(%rbx), %rdi
leaq 0x7437(%rip), %rsi      # 0xc049
leaq 0x7da6(%rip), %rdx      # 0xc9bf
xorl %eax, %eax
callq 0x544e
leaq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0x2190
testw %r12w, %r12w
movl $0x1466, %eax           # imm = 0x1466
cmovnel %r12d, %eax
movzwl %ax, %esi
movl %esi, 0x4(%rsp)
jmp 0x4c75
leaq 0x7d8f(%rip), %rdi      # 0xc9d9
leaq 0x7d94(%rip), %rsi      # 0xc9e5
leaq 0x10(%rsp), %rcx
leaq 0x4(%rsp), %r9
movq %rax, %rdx
movl $0x800, %r8d            # imm = 0x800
callq 0xaf0a
testl %eax, %eax
je 0x4d01
movl 0x4(%rsp), %esi
leaq 0x10(%rsp), %r12
movq %r12, %rdi
callq 0xa750
movl %eax, 0x30(%rbx)
movq 0x8(%rbx), %rdi
movl 0x4(%rsp), %r8d
leaq 0x73b4(%rip), %rsi      # 0xc049
leaq 0x7d83(%rip), %rdx      # 0xca1f
movq %r12, %rcx
movl %eax, %r9d
xorl %eax, %eax
callq 0x544e
cmpl $-0x1, 0x30(%rbx)
je 0x4ced
movq %r15, 0xe0(%rbx)
movq %r14, 0xe8(%rbx)
movl $0x1, 0x14(%rbx)
callq 0xbd43
movq %rax, 0x18(%rbx)
movq 0x8(%rbx), %rdi
leaq 0x7371(%rip), %rsi      # 0xc049
leaq 0x7d62(%rip), %rdx      # 0xca41
leaq 0x10(%rsp), %rcx
xorl %eax, %eax
callq 0x544e
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x818, %rsp            # imm = 0x818
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rbx), %rdi
leaq 0x733d(%rip), %rsi      # 0xc049
leaq 0x7cd6(%rip), %rdx      # 0xc9e9
xorl %eax, %eax
callq 0x544e
movq 0x8(%rbx), %rdi
movq 0x60(%rbx), %rax
movq %rax, 0x8(%rsp)
movzwl %r12w, %r13d
leaq 0x7cca(%rip), %rdx      # 0xc9fc
leaq 0x7310(%rip), %rsi      # 0xc049
xorl %ecx, %ecx
movl %r13d, %r8d
xorl %eax, %eax
callq 0x544e
leaq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x2190
testw %r12w, %r12w
movl $0x1466, %esi           # imm = 0x1466
cmovnel %r13d, %esi
jmp 0x4c3d