// File: /workspace/github_c_makefile_star2_O2/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
pushq $-0x2
popq %r13
testl %eax, %eax
je 0xb56b
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, %r15
cmpl $0x1, %eax
jne 0xb3dd
movq 0x38(%r15), %rcx
testq %rcx, %rcx
je 0xb56b
leaq 0x16e3(%rip), %rdx      # 0xcaa6
movq %rbx, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0xa4fd
testl %eax, %eax
pushq $-0x1
popq %rcx
cmovsl %ecx, %eax
jmp 0xb56e
movq 0x38(%r15), %rcx
testq %rcx, %rcx
je 0xb56b
leaq 0x1d34(%rip), %rdx      # 0xd125
movq %rbx, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0xa4fd
pushq $-0x1
popq %r13
testl %eax, %eax
js 0xb56b
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
movq %r14, 0x8(%rsp)
je 0xb4b1
callq 0x65c2
testl %eax, %eax
jle 0xb4b1
movq 0x40(%r15), %rdi
callq 0x65c6
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rdi
callq 0x6624
testq %rax, %rax
je 0xb4a2
movq %rax, %r14
movq 0x40(%r15), %rdi
movq %rax, %rsi
callq 0x657f
movq %rbx, %rdi
movq %r12, %rsi
leaq 0x1cb5(%rip), %rdx      # 0xd129
movq %r14, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0xa4fd
testl %eax, %eax
js 0xb56b
addl %eax, %ebp
cmpl 0x8(%rsp), %ebp
jg 0xb49b
movl %eax, %eax
subq %rax, %r12
addq %rax, %rbx
jmp 0xb449
xorl %r12d, %r12d
xorl %ebx, %ebx
jmp 0xb449
movq 0x10(%rsp), %rdi
callq 0x65f2
movq 0x8(%rsp), %r14
cmpq $0x0, 0x28(%r15)
je 0xb531
leaq 0x164e(%rip), %rdx      # 0xcb0d
movq %rbx, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0xa4fd
testl %eax, %eax
js 0xb56b
movq %r14, %rcx
leaq 0x28(%r15), %r14
addl %eax, %ebp
movl %eax, %eax
subq %rax, %r12
addq %rax, %rbx
xorl %eax, %eax
cmpl %ecx, %ebp
cmovgq %rax, %r12
cmovgq %rax, %rbx
movq (%r14), %r14
testq %r14, %r14
je 0xb547
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0xb384
movl %eax, %r13d
testl %eax, %eax
js 0xb56b
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
addq $0x20, %r14
jmp 0xb4f1
leaq 0x1bfa(%rip), %rdx      # 0xd132
movq %rbx, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0xa4fd
jmp 0xb55f
movq 0x38(%r15), %rcx
leaq 0x1be3(%rip), %rdx      # 0xd135
movq %rbx, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0xa4fd
addl %eax, %ebp
testl %eax, %eax
pushq $-0x1
popq %r13
cmovnsl %ebp, %r13d
movl %r13d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq