// File: /workspace/github_c_makefile_star2_O3/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 0xb920
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, %r15
cmpl $0x1, %eax
jne 0xb774
movq 0x38(%r15), %rcx
testq %rcx, %rcx
je 0xb920
leaq 0x234e(%rip), %rdx      # 0xdaa6
movq %rbx, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0xa765
testl %eax, %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmovsl %ecx, %eax
jmp 0xb923
movq 0x38(%r15), %rcx
testq %rcx, %rcx
je 0xb920
leaq 0x299d(%rip), %rdx      # 0xe125
movq %rbx, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0xa765
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
testl %eax, %eax
js 0xb920
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 0xb864
callq 0x67d9
testl %eax, %eax
jle 0xb864
movq %r14, 0x8(%rsp)
movq 0x40(%r15), %rdi
callq 0x67dd
movq %rax, 0x10(%rsp)
movq %rax, %rdi
callq 0x6843
testq %rax, %rax
je 0xb855
movq %rax, %r14
movq 0x40(%r15), %rdi
movq %r14, %rsi
callq 0x6766
movq %rbx, %rdi
movq %r12, %rsi
leaq 0x2916(%rip), %rdx      # 0xe129
movq %r14, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0xa765
testl %eax, %eax
js 0xb920
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 0x6843
movq %rax, %r14
testq %rax, %rax
jne 0xb7fa
movq 0x10(%rsp), %rdi
callq 0x6811
movq 0x8(%rsp), %r14
cmpq $0x0, 0x28(%r15)
je 0xb8e4
leaq 0x229b(%rip), %rdx      # 0xdb0d
movq %rbx, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0xa765
testl %eax, %eax
js 0xb920
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 0xb8fa
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0xb717
movl %eax, %r13d
testl %eax, %eax
js 0xb920
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 0xb8a7
leaq 0x2847(%rip), %rdx      # 0xe132
movq %rbx, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0xa765
jmp 0xb912
movq 0x38(%r15), %rcx
leaq 0x2830(%rip), %rdx      # 0xe135
movq %rbx, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0xa765
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