// File: /workspace/github_c_makefile_star2_O2/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       # 0x415c
callq 0x5e3e
leaq 0x86ec(%rip), %rsi      # 0xc646
movq %r14, %rdi
callq 0xb81c
movq %rax, %r15
testq %rax, %rax
je 0x3f8c
movq %r15, %rdi
callq 0xb7e0
leaq 0x86b1(%rip), %rsi      # 0xc62a
movq %rax, %rdi
callq 0x22e0
testl %eax, %eax
jne 0x3f8c
movl $0x1, 0x50(%rbx)
leaq 0x86d4(%rip), %rsi      # 0xc667
movq %r14, %rdi
callq 0xb81c
testq %rax, %rax
je 0x3fc2
movq %rax, %rdi
callq 0xb7e0
leaq 0x869c(%rip), %rsi      # 0xc64b
movq %rax, %rdi
callq 0x22e0
testl %eax, %eax
jne 0x3fc2
movl $0x1, 0x54(%rbx)
cmpl $0x0, 0x50(%rbx)
je 0x4108
leaq 0x1b2(%rip), %rsi       # 0x4185
leaq 0x8695(%rip), %rdx      # 0xc66f
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x6180
leaq 0x38d(%rip), %rsi       # 0x4378
movl $0x3a98, %edx           # imm = 0x3A98
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x608f
movq 0x8(%rbx), %rdi
callq 0xb0b4
testq %rax, %rax
je 0x4143
movq %rax, %r14
leaq 0x8010(%rip), %rsi      # 0xc026
movq %rax, %rdi
callq 0xb57d
leaq 0x8e35(%rip), %rsi      # 0xce5a
movq %r14, %rdi
callq 0xb995
leaq 0x863b(%rip), %rsi      # 0xc66f
movq %r14, %rdi
callq 0xb986
movq %r15, %rdi
callq 0xb0ea
testq %rax, %rax
je 0x413b
movq %rax, %r15
movq 0x8(%rbx), %rdi
movq 0x78(%rbx), %rsi
callq 0x68b3
testq %rax, %rax
je 0x40e0
movq %rax, %r12
cmpb $0x0, (%rax)
movq 0x8(%rbx), %rdi
je 0x40d8
callq 0xb0b4
testq %rax, %rax
je 0x4133
movq %rax, %r13
leaq 0x84b9(%rip), %rsi      # 0xc53f
movq %rax, %rdi
callq 0xb57d
movq 0x8(%rbx), %rdi
callq 0xb0b4
testq %rax, %rax
je 0x412b
movq %rax, %rbp
movq %rax, %rdi
movq %r12, %rsi
callq 0xb711
movq %r13, %rdi
movq %rbp, %rsi
callq 0xb6e5
movq %rbp, %rdi
callq 0xb220
movq %r15, %rdi
movq %r13, %rsi
callq 0xb6e5
movq %r13, %rdi
callq 0xb220
movq 0x8(%rbx), %rdi
movq %r12, %rsi
callq 0x51a1
movq %r14, %rdi
movq %r15, %rsi
callq 0xb6e5
movq %r15, %rdi
callq 0xb220
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5084
movq %r14, %rdi
callq 0xb220
jmp 0x414b
movq 0x8(%rbx), %rdi
leaq 0x7f36(%rip), %rsi      # 0xc049
leaq 0x8561(%rip), %rdx      # 0xc67b
xorl %eax, %eax
callq 0x52aa
movq %rbx, %rdi
callq 0x4e1e
jmp 0x414b
movq %r13, %rdi
callq 0xb220
movq %r15, %rdi
callq 0xb220
movq %r14, %rdi
callq 0xb220
movq %rbx, %rdi
callq 0xbd7a
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq