// File: smallmuou[P]tinyhtml/tinyhtml.cpp
// Function: FindByAttribute(TiHtmlElement*, char const*, char const*, bool)
TiHtmlResult* FindByAttribute( TiHtmlElement* htmlElement, const char* name, const char* value, 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_ALL(element, node) {
            const char* aValue = node->Attribute(name);

            //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;
                }
            }

            if (aValue && 0 == strcasecmp(aValue, value)) {
                result->Append(new TiHtmlElement(node));
            }
        }

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

    if (array) free(array);

    return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movb %cl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
andb $0x1, %al
movb %al, -0x19(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movl $0x18, %edi
callq 0x3130
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x70(%rbp)
callq 0xc2d0
jmp 0xc92c
movq -0x70(%rbp), %rax
movq %rax, -0x38(%rbp)
movl $0x0, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movl $0x8, %edi
movl $0x40, %esi
callq 0x30f0
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0xc984
movl $0x40, -0x4c(%rbp)
jmp 0xc984
movq -0x70(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
movl $0x18, %esi
callq 0x3140
jmp 0xcb17
movl $0x0, -0x5c(%rbp)
movq -0x28(%rbp), %rdx
movq -0x58(%rbp), %rax
movslq -0x5c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x58(%rbp), %rax
movslq -0x5c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0x80a0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0xcab7
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x4980
movq %rax, -0x68(%rbp)
testb $0x1, -0x19(%rbp)
je 0xca35
cmpq $0x0, -0x58(%rbp)
je 0xca35
movl -0x48(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jl 0xca12
movq -0x58(%rbp), %rdi
movslq -0x4c(%rbp), %rsi
shlq $0x3, %rsi
shlq %rsi
callq 0x3260
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0xca10
movl -0x4c(%rbp), %eax
shll %eax
movl %eax, -0x4c(%rbp)
jmp 0xca12
cmpq $0x0, -0x58(%rbp)
je 0xca33
movq -0x30(%rbp), %rdx
movq -0x58(%rbp), %rax
movl -0x48(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x48(%rbp)
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0xca35
cmpq $0x0, -0x68(%rbp)
je 0xcaa3
movq -0x68(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x3160
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0xcaa3
movq -0x38(%rbp), %rax
movq %rax, -0x80(%rbp)
movl $0x8, %edi
callq 0x3130
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x78(%rbp)
movq -0x30(%rbp), %rsi
callq 0xc600
jmp 0xca78
movq -0x78(%rbp), %rsi
movq -0x80(%rbp), %rdi
callq 0xc400
jmp 0xcaa3
movq -0x78(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
movl $0x8, %esi
callq 0x3140
jmp 0xcb17
jmp 0xcaa5
movq -0x30(%rbp), %rdi
callq 0x8120
movq %rax, -0x30(%rbp)
jmp 0xc9b8
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
xorl %eax, %eax
testb $0x1, -0x19(%rbp)
movb %al, -0x81(%rbp)
je 0xcaec
xorl %eax, %eax
cmpq $0x0, -0x28(%rbp)
movb %al, -0x81(%rbp)
je 0xcaec
movl -0x5c(%rbp), %eax
cmpl -0x48(%rbp), %eax
setl %al
movb %al, -0x81(%rbp)
movb -0x81(%rbp), %al
testb $0x1, %al
jne 0xc99b
cmpq $0x0, -0x58(%rbp)
je 0xcb0a
movq -0x58(%rbp), %rdi
callq 0x3190
movq -0x38(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x3270