// File: smallmuou[P]tinyhtml/tinyhtml.cpp
// Function: FindByTag(TiHtmlElement*, char const*, bool)
TiHtmlResult* FindByTag( TiHtmlElement* htmlElement, const char* name,  bool deep ) {
    TiXmlElement* element = (TiXmlElement* )htmlElement->internal;
    TiXmlElement* node = NULL;
    TiHtmlResult* result = new TiHtmlResult();

    int arrayCount = 0;
    int arrayCapacity = 0;
    TiXmlElement** array = (TiXmlElement** )calloc(sizeof(TiXmlElement* ), MIN_CAPACITY);
    if (array) arrayCapacity = MIN_CAPACITY;
    int i = 0;

    /* 广度优先遍历 */
    array[i] = element;
    do {
        element = array[i];
        TIXML_FOR_EACH(element, node, name) {
            result->Append(new TiHtmlElement(node));

            //add to array
            if (deep && array) {
                if (arrayCount >= arrayCapacity) {
                    array = (TiXmlElement** )realloc(array, sizeof(TiXmlElement* )*arrayCapacity*2);
                    if (array) arrayCapacity *= 2;
                }

                if (array) {
                    array[arrayCount++] = node;
                }
            }
        }

        i++;
    } while(deep && element && i < arrayCount);

    if (array) free(array);

    return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movb %dl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
andb $0x1, %al
movb %al, -0x11(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movl $0x18, %edi
callq 0x3130
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x60(%rbp)
callq 0xc2d0
jmp 0xc718
movq -0x60(%rbp), %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movl $0x8, %edi
movl $0x40, %esi
callq 0x30f0
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0xc770
movl $0x40, -0x44(%rbp)
jmp 0xc770
movq -0x60(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
movl $0x18, %esi
callq 0x3140
jmp 0xc8d5
movl $0x0, -0x54(%rbp)
movq -0x20(%rbp), %rdx
movq -0x50(%rbp), %rax
movslq -0x54(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x50(%rbp), %rax
movslq -0x54(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x80c0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0xc881
movq -0x30(%rbp), %rax
movq %rax, -0x70(%rbp)
movl $0x8, %edi
callq 0x3130
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x68(%rbp)
movq -0x28(%rbp), %rsi
callq 0xc600
jmp 0xc7da
movq -0x68(%rbp), %rsi
movq -0x70(%rbp), %rdi
callq 0xc400
testb $0x1, -0x11(%rbp)
je 0xc869
cmpq $0x0, -0x50(%rbp)
je 0xc869
movl -0x40(%rbp), %eax
cmpl -0x44(%rbp), %eax
jl 0xc846
movq -0x50(%rbp), %rdi
movslq -0x44(%rbp), %rsi
shlq $0x3, %rsi
shlq %rsi
callq 0x3260
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0xc844
movl -0x44(%rbp), %eax
shll %eax
movl %eax, -0x44(%rbp)
jmp 0xc844
movq -0x68(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
movl $0x8, %esi
callq 0x3140
jmp 0xc8d5
jmp 0xc846
cmpq $0x0, -0x50(%rbp)
je 0xc867
movq -0x28(%rbp), %rdx
movq -0x50(%rbp), %rax
movl -0x40(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x40(%rbp)
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0xc869
jmp 0xc86b
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x8140
movq %rax, -0x28(%rbp)
jmp 0xc7a8
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
xorl %eax, %eax
testb $0x1, -0x11(%rbp)
movb %al, -0x71(%rbp)
je 0xc8ad
xorl %eax, %eax
cmpq $0x0, -0x20(%rbp)
movb %al, -0x71(%rbp)
je 0xc8ad
movl -0x54(%rbp), %eax
cmpl -0x40(%rbp), %eax
setl %al
movb %al, -0x71(%rbp)
movb -0x71(%rbp), %al
testb $0x1, %al
jne 0xc787
cmpq $0x0, -0x50(%rbp)
je 0xc8c8
movq -0x50(%rbp), %rdi
callq 0x3190
movq -0x30(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
movq -0x38(%rbp), %rdi
callq 0x3270
nop