// File: /workspace/github_c_makefile_star2_O2/mruby-zest[P]osc-bridge/src/mm_json.h
// Function: mm_json_query_del
MM_JSON_API struct mm_json_token*
mm_json_query_del(struct mm_json_token *toks, mm_json_size count,
    const mm_json_char *path, mm_json_char delemiter)
{
    mm_json_size i = 0;
    mm_json_int begin = 1;
    struct mm_json_token *iter = NULL;
    /* iterator to step over each token in the toks array */
    struct mm_json_token name;
    /* current segment in the path to search in the tree for */
    struct mm_json_token array;
    /* array token to store the current path segment array index */
    struct mm_json_object {mm_json_size index, size;} obj;
    /* current object iterator with current pair index and total pairs in object */

    MM_JSON_ASSERT(toks);
    MM_JSON_ASSERT(count);
    if (!toks || !count) return iter;
    if (!path) return &toks[i];

    iter = &toks[i];
    array.len = 0;
    array.str = NULL;

    path = mm_json_path_parse_name(&name, path, delemiter);
    while (1) {
        if (iter->type == MM_JSON_OBJECT || iter->type == MM_JSON_ARRAY || begin) {
            /* setup iteration over elements inside a object or array */
            obj.index = 0;
            if (begin) {
                begin = 0;
                obj.size = count;
            } else if (iter->type == MM_JSON_OBJECT) {
                obj.size = iter->children;
                if ((i + 1) > count) return NULL;
                iter = &toks[++i];
            } else {
                mm_json_number n;
                mm_json_size j = 0;

                /* array object so set iterator to array index */
                if (!mm_json_path_parse_array(&array, &name))
                    return NULL;
                if ((i+1) >= count)
                    return NULL;
                if (array.len < 1)
                    return NULL;
                if (mm_json_convert(&n, &array) != MM_JSON_NUMBER)
                    return NULL;
                if ((mm_json_size)n >= iter->children)
                    return NULL;
                array.str = NULL;
                array.len = 0;

                /* iterate over each array element and find the correct index */
                iter++; i++;
                for (j = 0; j < n; ++j) {
                    if (iter->type == MM_JSON_ARRAY || iter->type == MM_JSON_OBJECT) {
                        i = i + (iter->sub) + 1;
                    } else i += 1;
                    if (i > count)
                        return NULL;
                    iter = &toks[i];
                }
                if (!path) return iter;
                path = mm_json_path_parse_name(&name, path, delemiter);
            }
            continue;
        }
        {
            /* check if current table element is equal to the current path  */
            if (!mm_json_lcmp(iter, name.str, name.len)) {
                /* correct token found and end of path */
                if (!path) {
                    if ((i + 1) > count)
                        return NULL;
                    return (iter + 1);
                }
                /* check if path points to invalid token */
                if ((i+1) > count)
                    return NULL;
                if(toks[i+1].type != MM_JSON_OBJECT && toks[i+1].type != MM_JSON_ARRAY)
                    return NULL;

                /* look deeper into child object/array */
                iter = &toks[++i];
                path = mm_json_path_parse_name(&name, path, delemiter);
            } else {
                /* key is not correct iterate until end of object */
                if (++obj.index >= obj.size)
                    return NULL;
                if ((i + 1) >= count)
                    return NULL;
                if (iter[1].type == MM_JSON_ARRAY || iter[1].type == MM_JSON_OBJECT) {
                    i = i + (iter[1].sub + 2);
                } else i = i + 2;
                if (i >= count)
                    return NULL;
                iter = &toks[i];
            }
        }
    }
    return iter;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rsi, %r14
testq %rdi, %rdi
sete %al
testq %rsi, %rsi
sete %sil
orb %al, %sil
jne 0x5053
movq %rdi, %r12
testq %rdx, %rdx
je 0x505d
xorpd %xmm0, %xmm0
leaq -0xc0(%rbp), %rax
movapd %xmm0, (%rax)
movsbl %cl, %eax
leaq -0x98(%rbp), %rdi
movq %rdx, %rsi
movl %eax, -0x34(%rbp)
movl %eax, %edx
callq 0x5097
movb $0x1, %r9b
movq $0x0, -0x30(%rbp)
pushq $0x2
popq %r10
xorl %ebx, %ebx
xorl %ecx, %ecx
movq %r12, %r15
movq %r14, -0x68(%rbp)
movq %r12, -0x60(%rbp)
movl %ecx, %edi
xorl %r13d, %r13d
movq -0x98(%rbp), %rcx
movq -0x90(%rbp), %rdx
testq %rcx, %rcx
setne %r8b
testq %rdx, %rdx
setne %sil
andb %r8b, %sil
movl 0x20(%r15), %r8d
testb $0x1, %r9b
jne 0x4e8e
leal -0x1(%r8), %r9d
cmpl $0x1, %r9d
jbe 0x4e8e
testb %sil, %sil
je 0x4de4
movq 0x8(%r15), %r9
cmpq %r9, %rdx
cmovbq %rdx, %r9
xorl %edi, %edi
cmpq %rdi, %r9
je 0x4e31
movq (%r15), %r8
movb (%r8,%rdi), %r8b
cmpb (%rcx,%rdi), %r8b
jne 0x4de4
incq %rdi
jmp 0x4dcd
incq %r13
cmpq %r11, %r13
jae 0x507c
leaq 0x1(%rbx), %rdi
cmpq %r14, %rdi
jae 0x507c
movl 0x48(%r15), %edi
decl %edi
movq %r10, %r8
cmpl $0x1, %edi
ja 0x4e13
movq 0x40(%r15), %r8
addq $0x2, %r8
addq %r8, %rbx
cmpq %r14, %rbx
jae 0x507c
imulq $0x28, %rbx, %r15
addq %r12, %r15
movb $0x1, %dil
xorl %r9d, %r9d
jmp 0x4d9f
incq %rbx
testq %rax, %rax
je 0x506b
cmpq %r14, %rbx
ja 0x507c
imulq $0x28, %rbx, %r15
movl 0x20(%r12,%r15), %ecx
decl %ecx
cmpl $0x1, %ecx
ja 0x507c
addq %r12, %r15
leaq -0x98(%rbp), %rdi
movq %rax, %rsi
movl -0x34(%rbp), %edx
movq %r10, %r12
movq %r11, %r14
callq 0x5097
movq %r14, %r11
movq %r12, %r10
movq -0x60(%rbp), %r12
movq -0x68(%rbp), %r14
movb $0x1, %dil
xorl %r9d, %r9d
jmp 0x4d80
movb $0x1, %cl
testb $0x1, %dil
je 0x502d
cmpl $0x1, %r8d
je 0x5038
movq %r11, -0x48(%rbp)
movq %rax, -0x50(%rbp)
movq -0x98(%rbp), %r13
movq -0x90(%rbp), %rdx
movq %r13, -0xc0(%rbp)
movq %r13, %rdi
pushq $0x5b
popq %rsi
movq %rdx, -0x40(%rbp)
callq 0x5d16
testq %rax, %rax
je 0x5063
movq %rax, %rsi
subq %r13, %rsi
cmpq %rsi, -0x40(%rbp)
jbe 0x5063
movq -0x40(%rbp), %rcx
movl %ecx, %edx
subl %esi, %edx
movq %rax, -0x58(%rbp)
movq %rax, %rdi
pushq $0x5d
popq %rsi
callq 0x5d16
testq %rax, %rax
je 0x5063
movq %rax, %rdx
subq %r13, %rdx
movl $0x0, %ecx
cmpq -0x40(%rbp), %rdx
jae 0x5065
movq -0x58(%rbp), %rdx
leaq 0x1(%rdx), %rcx
movq %rcx, -0xc0(%rbp)
decq %rax
movq %rax, %rcx
subq %rdx, %rcx
movq %rcx, -0xb8(%rbp)
incq %rbx
cmpq %r14, %rbx
jae 0x5063
movl $0x0, %ecx
cmpq %rdx, %rax
je 0x5065
leaq -0x70(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x42c1
cmpl $0x3, %eax
jne 0x5063
movsd -0x70(%rbp), %xmm0
cvttsd2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
movapd %xmm0, %xmm1
subsd 0x30ab(%rip), %xmm1     # 0x8038
cvttsd2si %xmm1, %rdx
andq %rcx, %rdx
orq %rax, %rdx
cmpq %rdx, 0x10(%r15)
jbe 0x5063
addq $0x28, %r15
xorpd %xmm1, %xmm1
movapd %xmm1, -0xc0(%rbp)
xorl %eax, %eax
movq -0x50(%rbp), %rsi
movq %rax, %xmm1
punpckldq 0x304b(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x3053(%rip), %xmm1     # 0x8020
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
ucomisd %xmm2, %xmm0
jbe 0x5002
movl 0x20(%r15), %ecx
decl %ecx
cmpl $0x1, %ecx
ja 0x4fee
addq 0x18(%r15), %rbx
incq %rbx
cmpq %r14, %rbx
ja 0x5063
imulq $0x28, %rbx, %r15
addq %r12, %r15
incq %rax
jmp 0x4fb8
testq %rsi, %rsi
je 0x5092
leaq -0x98(%rbp), %rdi
movl -0x34(%rbp), %edx
callq 0x5097
movb $0x1, %dil
xorl %r9d, %r9d
pushq $0x2
popq %r10
movq -0x48(%rbp), %r11
jmp 0x4d7d
xorl %r9d, %r9d
movq %r14, %r11
jmp 0x4d7b
incq %rbx
cmpq %r14, %rbx
ja 0x507c
movq 0x10(%r15), %r11
imulq $0x28, %rbx, %r15
addq %r12, %r15
xorl %r9d, %r9d
jmp 0x4d7b
movq $0x0, -0x30(%rbp)
jmp 0x507c
movq %r12, -0x30(%rbp)
jmp 0x507c
xorl %ecx, %ecx
movq %rcx, -0x30(%rbp)
jmp 0x507c
addq $0x28, %r15
xorl %eax, %eax
cmpq %r14, %rbx
cmovbeq %r15, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rcx
jmp 0x5065