// File: /workspace/github_c_makefile_star2_O3/liuhaotian[P]xmppsh/libstrophe/src/auth.c
// Function: handle_features_sasl
static int _handle_features_sasl(xmpp_conn_t * const conn,
				 xmpp_stanza_t * const stanza,
				 void * const userdata)
{
    xmpp_stanza_t *bind, *session, *iq, *res, *text;
    char *resource;

    /* remove missing features handler */
    xmpp_timed_handler_delete(conn, _handle_missing_features_sasl);

    /* we are expecting <bind/> and <session/> since this is a
       XMPP style connection */

    bind = xmpp_stanza_get_child_by_name(stanza, "bind");
    if (bind && strcmp(xmpp_stanza_get_ns(bind), XMPP_NS_BIND) == 0) {
	/* resource binding is required */
	conn->bind_required = 1;
    }

    session = xmpp_stanza_get_child_by_name(stanza, "session");
    if (session && strcmp(xmpp_stanza_get_ns(session), XMPP_NS_SESSION) == 0) {
	/* session establishment required */
	conn->session_required = 1;
    }

    /* if bind is required, go ahead and start it */
    if (conn->bind_required) {
	/* bind resource */
	
	/* setup response handlers */
	handler_add_id(conn, _handle_bind, "_xmpp_bind1", NULL);
	handler_add_timed(conn, _handle_missing_bind,
			  BIND_TIMEOUT, NULL);

	/* send bind request */
	iq = xmpp_stanza_new(conn->ctx);
	if (!iq) {
	    disconnect_mem_error(conn);
	    return 0;
	}

	xmpp_stanza_set_name(iq, "iq");
	xmpp_stanza_set_type(iq, "set");
	xmpp_stanza_set_id(iq, "_xmpp_bind1");

	bind = xmpp_stanza_copy(bind);
	if (!bind) {
	    xmpp_stanza_release(iq);
	    disconnect_mem_error(conn);
	    return 0;
	}

	/* request a specific resource if we have one */
        resource = xmpp_jid_resource(conn->ctx, conn->jid);
	if ((resource != NULL) && (strlen(resource) == 0)) {
	    /* jabberd2 doesn't handle an empty resource */
	    xmpp_free(conn->ctx, resource);
	    resource = NULL;
	}

	/* if we have a resource to request, do it. otherwise the 
	   server will assign us one */
	if (resource) {
	    res = xmpp_stanza_new(conn->ctx);
	    if (!res) {
		xmpp_stanza_release(bind);
		xmpp_stanza_release(iq);
		disconnect_mem_error(conn);
		return 0;
	    }
	    xmpp_stanza_set_name(res, "resource");
	    text = xmpp_stanza_new(conn->ctx);
	    if (!text) {
		xmpp_stanza_release(res);
		xmpp_stanza_release(bind);
		xmpp_stanza_release(iq);
		disconnect_mem_error(conn);
		return 0;
	    }
	    xmpp_stanza_set_text(text, resource);
	    xmpp_stanza_add_child(res, text);
            xmpp_stanza_release(text);
	    xmpp_stanza_add_child(bind, res);
            xmpp_stanza_release(res);
	    xmpp_free(conn->ctx, resource);
	}

	xmpp_stanza_add_child(iq, bind);
	xmpp_stanza_release(bind);

	/* send bind request */
	xmpp_send(conn, iq);
	xmpp_stanza_release(iq);
    } else {
	/* can't bind, disconnect */
	xmpp_error(conn->ctx, "xmpp", "Stream features does not allow "\
		   "resource bind.");
	xmpp_disconnect(conn);
    }

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x20e(%rip), %rsi       # 0x41c7
callq 0x5f99
leaq 0x9681(%rip), %rsi      # 0xd646
movq %r14, %rdi
callq 0xbbd3
movq %rax, %r15
testq %rax, %rax
je 0x3ff7
movq %r15, %rdi
callq 0xbb97
leaq 0x9646(%rip), %rsi      # 0xd62a
movq %rax, %rdi
callq 0x22e0
testl %eax, %eax
jne 0x3ff7
movl $0x1, 0x50(%rbx)
leaq 0x9669(%rip), %rsi      # 0xd667
movq %r14, %rdi
callq 0xbbd3
testq %rax, %rax
je 0x402d
movq %rax, %rdi
callq 0xbb97
leaq 0x9631(%rip), %rsi      # 0xd64b
movq %rax, %rdi
callq 0x22e0
testl %eax, %eax
jne 0x402d
movl $0x1, 0x54(%rbx)
cmpl $0x0, 0x50(%rbx)
je 0x4173
leaq 0x1b2(%rip), %rsi       # 0x41f0
leaq 0x962a(%rip), %rdx      # 0xd66f
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x62fd
leaq 0x38d(%rip), %rsi       # 0x43e3
movl $0x3a98, %edx           # imm = 0x3A98
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x6202
movq 0x8(%rbx), %rdi
callq 0xb40c
testq %rax, %rax
je 0x41ae
movq %rax, %r14
leaq 0x8fa5(%rip), %rsi      # 0xd026
movq %rax, %rdi
callq 0xb932
leaq 0x9dca(%rip), %rsi      # 0xde5a
movq %r14, %rdi
callq 0xbd5d
leaq 0x95d0(%rip), %rsi      # 0xd66f
movq %r14, %rdi
callq 0xbd4e
movq %r15, %rdi
callq 0xb447
testq %rax, %rax
je 0x41a6
movq %rax, %r15
movq 0x8(%rbx), %rdi
movq 0x78(%rbx), %rsi
callq 0x6adf
testq %rax, %rax
je 0x414b
movq %rax, %r12
cmpb $0x0, (%rax)
movq 0x8(%rbx), %rdi
je 0x4143
callq 0xb40c
testq %rax, %rax
je 0x419e
movq %rax, %r13
leaq 0x944e(%rip), %rsi      # 0xd53f
movq %rax, %rdi
callq 0xb932
movq 0x8(%rbx), %rdi
callq 0xb40c
testq %rax, %rax
je 0x4196
movq %rax, %rbp
movq %rax, %rdi
movq %r12, %rsi
callq 0xbac4
movq %r13, %rdi
movq %rbp, %rsi
callq 0xba98
movq %rbp, %rdi
callq 0xb5a8
movq %r15, %rdi
movq %r13, %rsi
callq 0xba98
movq %r13, %rdi
callq 0xb5a8
movq 0x8(%rbx), %rdi
movq %r12, %rsi
callq 0x5263
movq %r14, %rdi
movq %r15, %rsi
callq 0xba98
movq %r15, %rdi
callq 0xb5a8
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5145
movq %r14, %rdi
callq 0xb5a8
jmp 0x41b6
movq 0x8(%rbx), %rdi
leaq 0x8ecb(%rip), %rsi      # 0xd049
leaq 0x94f6(%rip), %rdx      # 0xd67b
xorl %eax, %eax
callq 0x536c
movq %rbx, %rdi
callq 0x4edd
jmp 0x41b6
movq %r13, %rdi
callq 0xb5a8
movq %r15, %rdi
callq 0xb5a8
movq %r14, %rdi
callq 0xb5a8
movq %rbx, %rdi
callq 0xc184
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq