// File: /workspace/github_c_makefile_star2_O1/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 0x222(%rip), %rsi       # 0x4203
callq 0x5fdb
leaq 0x9659(%rip), %rsi      # 0xd646
movq %r14, %rdi
callq 0xbd67
movq %rax, %r15
testq %rax, %rax
je 0x401f
movq %r15, %rdi
callq 0xbd2b
leaq 0x961e(%rip), %rsi      # 0xd62a
movq %rax, %rdi
callq 0x22e0
testl %eax, %eax
jne 0x401f
movl $0x1, 0x50(%rbx)
leaq 0x9641(%rip), %rsi      # 0xd667
movq %r14, %rdi
callq 0xbd67
testq %rax, %rax
je 0x4055
movq %rax, %rdi
callq 0xbd2b
leaq 0x9609(%rip), %rsi      # 0xd64b
movq %rax, %rdi
callq 0x22e0
testl %eax, %eax
jne 0x4055
movl $0x1, 0x54(%rbx)
cmpl $0x0, 0x50(%rbx)
je 0x41af
leaq 0x1c6(%rip), %rsi       # 0x422c
leaq 0x9602(%rip), %rdx      # 0xd66f
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x633f
leaq 0x3a1(%rip), %rsi       # 0x441f
movl $0x3a98, %edx           # imm = 0x3A98
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x6244
movq 0x8(%rbx), %rdi
callq 0xb5a0
testq %rax, %rax
je 0x41ea
movq %rax, %r14
leaq 0x8f7d(%rip), %rsi      # 0xd026
movq %rax, %rdi
callq 0xbac6
leaq 0x9da2(%rip), %rsi      # 0xde5a
movq %r14, %rdi
callq 0xbeea
leaq 0x95a8(%rip), %rsi      # 0xd66f
movq %r14, %rdi
callq 0xbedb
movq %r15, %rdi
callq 0xb5db
testq %rax, %rax
je 0x41e2
movq %rax, %r15
movq 0x8(%rbx), %rdi
movq 0x78(%rbx), %rsi
callq 0x6b22
testq %rax, %rax
je 0x4109
movq %rax, %r12
cmpb $0x0, (%rax)
jne 0x410c
movq 0x8(%rbx), %rdi
movq %r12, %rsi
callq 0x5293
xorl %r12d, %r12d
testq %r12, %r12
je 0x4187
movq 0x8(%rbx), %rdi
callq 0xb5a0
testq %rax, %rax
je 0x41da
movq %rax, %r13
leaq 0x9412(%rip), %rsi      # 0xd53f
movq %rax, %rdi
callq 0xbac6
movq 0x8(%rbx), %rdi
callq 0xb5a0
testq %rax, %rax
je 0x41d2
movq %rax, %rbp
movq %rax, %rdi
movq %r12, %rsi
callq 0xbc58
movq %r13, %rdi
movq %rbp, %rsi
callq 0xbc2c
movq %rbp, %rdi
callq 0xb73c
movq %r15, %rdi
movq %r13, %rsi
callq 0xbc2c
movq %r13, %rdi
callq 0xb73c
movq 0x8(%rbx), %rdi
movq %r12, %rsi
callq 0x5293
movq %r14, %rdi
movq %r15, %rsi
callq 0xbc2c
movq %r15, %rdi
callq 0xb73c
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5174
movq %r14, %rdi
callq 0xb73c
jmp 0x41f2
movq 0x8(%rbx), %rdi
leaq 0x8e8f(%rip), %rsi      # 0xd049
leaq 0x94ba(%rip), %rdx      # 0xd67b
xorl %eax, %eax
callq 0x539c
movq %rbx, %rdi
callq 0x4f0c
jmp 0x41f2
movq %r13, %rdi
callq 0xb73c
movq %r15, %rdi
callq 0xb73c
movq %r14, %rdi
callq 0xb73c
movq %rbx, %rdi
callq 0xc305
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq