// File: /workspace/github_c_makefile_star2_O1/liuhaotian[P]xmppsh/libstrophe/src/stanza.c
// Function: render_stanza_recursive
static int _render_stanza_recursive(xmpp_stanza_t *stanza,
			     char * const buf, size_t const buflen)
{
    char *ptr = buf;
    size_t left = buflen;
    int ret, written;
    xmpp_stanza_t *child;
    hash_iterator_t *iter;
    const char *key;

    written = 0;

    if (stanza->type == XMPP_STANZA_UNKNOWN) return XMPP_EINVOP;

    if (stanza->type == XMPP_STANZA_TEXT) {
	if (!stanza->data) return XMPP_EINVOP;

	ret = xmpp_snprintf(ptr, left, "%s", stanza->data);
	if (ret < 0) return XMPP_EMEM;
	_render_update(&written, buflen, ret, &left, &ptr);
    } else { /* stanza->type == XMPP_STANZA_TAG */
	if (!stanza->data) return XMPP_EINVOP;

	/* write begining of tag and attributes */
	ret = xmpp_snprintf(ptr, left, "<%s", stanza->data);
	if (ret < 0) return XMPP_EMEM;
	_render_update(&written, buflen, ret, &left, &ptr);

	if (stanza->attributes && hash_num_keys(stanza->attributes) > 0) {
	    iter = hash_iter_new(stanza->attributes);
	    while ((key = hash_iter_next(iter))) {
		ret = xmpp_snprintf(ptr, left, " %s=\"%s\"", key,
			       (char *)hash_get(stanza->attributes, key));
		if (ret < 0) return XMPP_EMEM;
		_render_update(&written, buflen, ret, &left, &ptr);
	    }
	    hash_iter_release(iter);
	}

	if (!stanza->children) {
	    /* write end if singleton tag */
	    ret = xmpp_snprintf(ptr, left, "/>");
	    if (ret < 0) return XMPP_EMEM;
	    _render_update(&written, buflen, ret, &left, &ptr);
	} else {
	    /* this stanza has child stanzas */

	    /* write end of start tag */
	    ret = xmpp_snprintf(ptr, left, ">");
	    if (ret < 0) return XMPP_EMEM;
	    _render_update(&written, buflen, ret, &left, &ptr);
	    
	    /* iterate and recurse over child stanzas */
	    child = stanza->children;
	    while (child) {
		ret = _render_stanza_recursive(child, ptr, left);
		if (ret < 0) return ret;

		_render_update(&written, buflen, ret, &left, &ptr);

		child = child->next;
	    }

	    /* write end tag */
	    ret = xmpp_snprintf(ptr, left, "</%s>", stanza->data);
	    if (ret < 0) return XMPP_EMEM;
	    
	    _render_update(&written, buflen, ret, &left, &ptr);
	}
    }

    return written;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl 0x10(%rdi), %eax
movl $0xfffffffe, %r13d      # imm = 0xFFFFFFFE
testl %eax, %eax
je 0xbab4
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, %r15
cmpl $0x1, %eax
jne 0xb908
movq 0x38(%r15), %rcx
testq %rcx, %rcx
je 0xbab4
leaq 0x21ba(%rip), %rdx      # 0xdaa6
movq %rbx, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0xa930
testl %eax, %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmovsl %ecx, %eax
jmp 0xbab7
movq 0x38(%r15), %rcx
testq %rcx, %rcx
je 0xbab4
leaq 0x2809(%rip), %rdx      # 0xe125
movq %rbx, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0xa930
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
testl %eax, %eax
js 0xbab4
movl %eax, %ebp
movl %eax, %eax
movq %r14, %r12
subq %rax, %r12
addq %rax, %rbx
xorl %eax, %eax
cmpl %r14d, %ebp
cmovgq %rax, %r12
cmovgq %rax, %rbx
movq 0x40(%r15), %rdi
testq %rdi, %rdi
je 0xb9f8
callq 0x6816
testl %eax, %eax
jle 0xb9f8
movq %r14, 0x8(%rsp)
movq 0x40(%r15), %rdi
callq 0x681a
movq %rax, 0x10(%rsp)
movq %rax, %rdi
callq 0x6880
testq %rax, %rax
je 0xb9e9
movq %rax, %r14
movq 0x40(%r15), %rdi
movq %r14, %rsi
callq 0x67a3
movq %rbx, %rdi
movq %r12, %rsi
leaq 0x2782(%rip), %rdx      # 0xe129
movq %r14, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0xa930
testl %eax, %eax
js 0xbab4
addl %eax, %ebp
movl %eax, %eax
subq %rax, %r12
addq %rax, %rbx
cmpl 0x8(%rsp), %ebp
movl $0x0, %eax
cmovgq %rax, %r12
cmovgq %rax, %rbx
movq 0x10(%rsp), %rdi
callq 0x6880
movq %rax, %r14
testq %rax, %rax
jne 0xb98e
movq 0x10(%rsp), %rdi
callq 0x684e
movq 0x8(%rsp), %r14
cmpq $0x0, 0x28(%r15)
je 0xba78
leaq 0x2107(%rip), %rdx      # 0xdb0d
movq %rbx, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0xa930
testl %eax, %eax
js 0xbab4
addl %eax, %ebp
movl %eax, %eax
subq %rax, %r12
addq %rax, %rbx
xorl %eax, %eax
movq %r14, 0x8(%rsp)
cmpl %r14d, %ebp
cmovgq %rax, %r12
cmovgq %rax, %rbx
movq 0x28(%r15), %r14
testq %r14, %r14
je 0xba8e
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0xb8ab
movl %eax, %r13d
testl %eax, %eax
js 0xbab4
addl %r13d, %ebp
movl %r13d, %eax
subq %rax, %r12
addq %rax, %rbx
cmpl 0x8(%rsp), %ebp
movl $0x0, %eax
cmovgq %rax, %r12
cmovgq %rax, %rbx
movq 0x20(%r14), %r14
jmp 0xba3b
leaq 0x26b3(%rip), %rdx      # 0xe132
movq %rbx, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0xa930
jmp 0xbaa6
movq 0x38(%r15), %rcx
leaq 0x269c(%rip), %rdx      # 0xe135
movq %rbx, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0xa930
addl %eax, %ebp
testl %eax, %eax
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
cmovnsl %ebp, %r13d
movl %r13d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq