// File: /workspace/github_cpp_makefile_star2_O1/xelia-it[P]mustache/src/mustache-light.cpp
// Function: mustache::Mustache::searchVariableInContext(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
json Mustache::searchVariableInContext(const string& key) {
        // TODO: better to use a constant
        if (key == "@index") {
                json value = currentListCounter_;
                return value;
        }
        if (key == "@first") {
                json value = (currentListCounter_ == 0);
                return value;
        }
        // Get the current context
        json top = stack_.top();
        LOG_END("SEARCH CONTEXT:");
        LOG_END(top.dump(2));
        if (top.is_null()) {
                return "null"_json;
        }

        string::size_type start;
        string::size_type stop;
        string::size_type index = string::npos;
        string newKey = key;

        if ((start = key.find_first_of("[")) != string::npos) {
                if ((stop = key.find_first_of("]")) == string::npos) {
                        error("Missing ] in array selection");
                }
                if (start + 1 == stop) {
                        error("Index is empty");
                }
                string array = key.substr(0, start);
                string indexAsString = key.substr(start + 1, stop - 1);

                newKey = array;
                index = std::stoul(indexAsString);
        }

        json::const_iterator it = top.find(newKey);
        if (it == top.end()) {
                LOG_END("NOT FOUND:");
                throw std::invalid_argument("Variable " + key + " not found");
        } else if (index == string::npos) {
                LOG_END("NORMAL USE *it:");
                json value = *it;
                return value;
        } else {
                LOG_END("USE INDEX:");
                // top exists at this point
                if (it->is_array()) {
                    LOG_END("USE ARRAY:");
                    if (index >= it->size()) {
                      LOG_END("OUT OF RANGE:");
                      throw std::out_of_range("Index " + std::to_string(index) + " is out of range");
                    } else {
                      LOG_END("IN RANGE:");
                    }
                }
                json value = (*it)[index];
                return value;
        }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x151a1(%rip), %rsi     # 0x30dad
movq %rdx, %rdi
callq 0x17230
testl %eax, %eax
je 0x1bd7c
leaq 0x15191(%rip), %rsi     # 0x30db4
movq %r14, %rdi
callq 0x17230
testl %eax, %eax
je 0x1bd98
movq 0x128(%r15), %rsi
cmpq 0x130(%r15), %rsi
jne 0x1bc53
movq 0x140(%r15), %rax
movl $0x200, %esi            # imm = 0x200
addq -0x8(%rax), %rsi
addq $-0x10, %rsi
leaq -0xa8(%rbp), %r15
movq %r15, %rdi
callq 0x17120
cmpb $0x0, (%r15)
je 0x1bdcb
leaq -0x80(%rbp), %r13
movq %r13, -0x10(%r13)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq -0x90(%rbp), %rdi
callq 0x173d0
leaq 0x18c06(%rip), %rsi     # 0x3489b
movl $0x1, %ecx
movq %r14, %rdi
xorl %edx, %edx
callq 0x18120
cmpq $-0x1, %rax
je 0x1be1e
movq %rax, %r15
leaq 0x1794b(%rip), %rsi     # 0x33603
movl $0x1, %ecx
movq %r14, %rdi
xorl %edx, %edx
callq 0x18120
cmpq $-0x1, %rax
je 0x1bfcb
movq %rax, %r12
leaq 0x1(%r15), %r13
cmpq %rax, %r13
je 0x1bff3
leaq -0x50(%rbp), %rdi
movq %r14, %rsi
xorl %edx, %edx
movq %r15, %rcx
callq 0x17bf0
decq %r12
leaq -0x70(%rbp), %rdi
movq %r14, %rsi
movq %r13, %rdx
movq %r12, %rcx
callq 0x17bf0
leaq -0x90(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x17560
movq -0x70(%rbp), %r13
callq 0x17040
movq %rax, %r12
movl (%rax), %eax
movl %eax, -0x2c(%rbp)
movl $0x0, (%r12)
leaq -0xc8(%rbp), %r15
movq %r13, %rdi
movq %r15, %rsi
movl $0xa, %edx
callq 0x172e0
movq %rax, -0x98(%rbp)
cmpq %r13, (%r15)
je 0x1c01b
movl (%r12), %eax
testl %eax, %eax
leaq -0x80(%rbp), %r13
je 0x1be2b
cmpl $0x22, %eax
jne 0x1be32
leaq 0x17b98(%rip), %rdi     # 0x3390f
callq 0x18060
movb $0x0, (%rbx)
movq $0x0, 0x8(%rbx)
movq 0xf0(%r15), %rsi
movq %rbx, %rdi
callq 0x17970
jmp 0x1bdb9
xorl %esi, %esi
cmpq $0x0, 0xf0(%r15)
sete %sil
movb $0x0, (%rbx)
movq $0x0, 0x8(%rbx)
movq %rbx, %rdi
callq 0x17e90
movq %rbx, %rdi
movl $0x1, %esi
callq 0x17530
jmp 0x1bf57
xorps %xmm0, %xmm0
leaq -0x90(%rbp), %rcx
movaps %xmm0, 0x10(%rcx)
movaps %xmm0, (%rcx)
leaq 0x14fd8(%rip), %rsi     # 0x30dbb
leaq 0x14fd5(%rip), %rdx     # 0x30dbf
movq %rbx, %rdi
movl $0x1, %r8d
xorl %r9d, %r9d
callq 0x18550
movq -0x80(%rbp), %rax
testq %rax, %rax
je 0x1bf4b
leaq -0x90(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x1bf4b
movq $-0x1, -0x98(%rbp)
jmp 0x1be56
movl -0x2c(%rbp), %eax
movl %eax, (%r12)
leaq -0x60(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1be44
callq 0x17b00
leaq -0x40(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1be56
callq 0x17b00
leaq -0x70(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
leaq -0x90(%rbp), %rdx
callq 0x17390
leaq -0x70(%rbp), %r15
movq (%r15), %rax
leaq -0x50(%rbp), %r12
movq %rax, (%r12)
movups 0x8(%r15), %xmm0
movups %xmm0, 0x8(%r12)
movq 0x18(%r15), %rax
movq %rax, 0x18(%r12)
leaq -0xa8(%rbp), %rsi
movq %r15, %rdi
callq 0x17510
movq %r12, %rdi
movq %r15, %rsi
callq 0x17bd0
testb %al, %al
jne 0x1bf6c
movq -0x98(%rbp), %r14
cmpq $-0x1, %r14
je 0x1bef8
leaq -0x50(%rbp), %rdi
callq 0x18280
cmpb $0x2, (%rax)
jne 0x1bf1b
leaq -0x50(%rbp), %rdi
callq 0x18280
movzbl (%rax), %ecx
testl %ecx, %ecx
je 0x1bf12
cmpl $0x1, %ecx
je 0x1bf03
cmpl $0x2, %ecx
jne 0x1bf0d
movq 0x8(%rax), %rax
movq 0x8(%rax), %rcx
subq (%rax), %rcx
sarq $0x4, %rcx
jmp 0x1bf12
leaq -0x50(%rbp), %rdi
callq 0x174a0
jmp 0x1bf2f
movq 0x8(%rax), %rax
movq 0x28(%rax), %rcx
jmp 0x1bf12
movl $0x1, %ecx
cmpq %rcx, %r14
jae 0x1c027
leaq -0x50(%rbp), %rdi
callq 0x174a0
movq %rax, %rdi
movq %r14, %rsi
callq 0x18390
movq %rbx, %rdi
movq %rax, %rsi
callq 0x17120
movq -0x90(%rbp), %rdi
cmpq %r13, %rdi
je 0x1bf4b
callq 0x17b00
leaq -0xa8(%rbp), %rdi
callq 0x17d70
movq %rbx, %rax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x10, %edi
callq 0x17460
movq %rax, %r15
leaq 0x14e6c(%rip), %rsi     # 0x30dec
leaq -0xc8(%rbp), %rdi
movq %r14, %rdx
callq 0x17a70
leaq 0x14e60(%rip), %rsi     # 0x30df6
leaq -0xc8(%rbp), %rdi
callq 0x18680
leaq -0x60(%rbp), %r12
movq %r12, -0x10(%r12)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
jne 0x1c092
movups (%rcx), %xmm0
movups %xmm0, (%r12)
jmp 0x1c09d
leaq -0x40(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x14de6(%rip), %rsi     # 0x30dc0
leaq 0x14dfb(%rip), %rdx     # 0x30ddc
leaq -0x50(%rbp), %rdi
callq 0x173a0
leaq -0x50(%rbp), %rsi
callq 0x17e70
leaq -0x40(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x14ddb(%rip), %rsi     # 0x30ddd
leaq 0x14de2(%rip), %rdx     # 0x30deb
leaq -0x50(%rbp), %rdi
callq 0x173a0
leaq -0x50(%rbp), %rsi
callq 0x17e70
leaq 0x178ed(%rip), %rdi     # 0x3390f
callq 0x17610
movl $0x10, %edi
callq 0x17460
movq %r14, %rsi
movq %rax, %r14
leaq -0xe8(%rbp), %rdi
callq 0x17330
leaq 0x14db7(%rip), %rsi     # 0x30e01
leaq -0xc8(%rbp), %rdi
leaq -0xe8(%rbp), %rdx
callq 0x18410
leaq 0x14da4(%rip), %rsi     # 0x30e08
leaq -0xc8(%rbp), %rdi
callq 0x18680
leaq -0x60(%rbp), %r12
movq %r12, -0x10(%r12)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
jne 0x1c0de
movups (%rcx), %xmm0
movups %xmm0, (%r12)
jmp 0x1c0e9
movq %rdx, -0x70(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x60(%rbp)
movq 0x8(%rax), %rdx
leaq -0x70(%rbp), %rsi
movq %rdx, 0x8(%rsi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movb $0x1, %r14b
movq %r15, %rdi
callq 0x18460
xorl %r14d, %r14d
movq 0x21f03(%rip), %rsi     # 0x3dfd0
movq 0x21ecc(%rip), %rdx     # 0x3dfa0
movq %r15, %rdi
callq 0x18440
jmp 0x1c128
movq %rdx, -0x70(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x60(%rbp)
movq 0x8(%rax), %rdx
leaq -0x70(%rbp), %rsi
movq %rdx, 0x8(%rsi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movb $0x1, %r15b
movq %r14, %rdi
callq 0x18140
xorl %r15d, %r15d
movq 0x21e9f(%rip), %rsi     # 0x3dfb8
movq 0x21e68(%rip), %rdx     # 0x3df88
movq %r14, %rdi
callq 0x18440
movq %rax, %rbx
movq -0x70(%rbp), %rdi
cmpq %r12, %rdi
je 0x1c141
callq 0x17b00
jmp 0x1c141
movq %rax, %rbx
movb $0x1, %r15b
leaq -0xb8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1c15e
callq 0x17b00
jmp 0x1c15e
movq %rax, %rbx
movb $0x1, %r15b
leaq -0xd8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1c17b
callq 0x17b00
jmp 0x1c17b
movq %rax, %rbx
movb $0x1, %r15b
testb %r15b, %r15b
je 0x1c26b
movq %r14, %rdi
jmp 0x1c1ee
movq %rax, %rbx
movq -0x70(%rbp), %rdi
cmpq %r12, %rdi
je 0x1c1a2
callq 0x17b00
jmp 0x1c1a2
movq %rax, %rbx
movb $0x1, %r14b
leaq -0xb8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1c1e2
callq 0x17b00
jmp 0x1c1e2
jmp 0x1c1c0
jmp 0x1c268
movq %rax, %rbx
movq -0x50(%rbp), %rdi
cmpq %r14, %rdi
jne 0x1c258
jmp 0x1c26b
jmp 0x1c268
jmp 0x1c214
movq %rax, %rbx
movb $0x1, %r14b
testb %r14b, %r14b
je 0x1c26b
movq %r15, %rdi
callq 0x17790
jmp 0x1c26b
movq %rax, %rbx
movq -0x80(%rbp), %rax
testq %rax, %rax
je 0x1c280
leaq -0x90(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x1c280
movq %rax, %rdi
callq 0x1d285
movq %rax, %rbx
jmp 0x1c239
movq %rax, %rbx
jmp 0x1c24b
jmp 0x1c268
movq %rax, %rbx
cmpl $0x0, (%r12)
jne 0x1c239
movl -0x2c(%rbp), %eax
movl %eax, (%r12)
leaq -0x60(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1c24b
callq 0x17b00
leaq -0x40(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1c26b
callq 0x17b00
jmp 0x1c26b
jmp 0x1c268
jmp 0x1c268
movq %rax, %rbx
jmp 0x1c280
movq %rax, %rbx
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x1c280
callq 0x17b00
leaq -0xa8(%rbp), %rdi
callq 0x17d70
movq %rbx, %rdi
callq 0x184b0