// File: /workspace/github_cpp_makefile_star2_O3/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 0x140bd(%rip), %rsi     # 0x2fda1
movq %rdx, %rdi
callq 0x17230
testl %eax, %eax
je 0x1be50
leaq 0x140ad(%rip), %rsi     # 0x2fda8
movq %r14, %rdi
callq 0x17230
testl %eax, %eax
je 0x1be6c
movq 0x128(%r15), %rsi
cmpq 0x130(%r15), %rsi
jne 0x1bd2b
movq 0x140(%r15), %rax
movl $0x200, %esi            # imm = 0x200
addq -0x8(%rax), %rsi
addq $-0x10, %rsi
leaq -0xc8(%rbp), %r15
movq %r15, %rdi
callq 0x17120
cmpb $0x0, (%r15)
je 0x1be9f
leaq -0x80(%rbp), %rax
movq %rax, -0x10(%rax)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq -0x90(%rbp), %rdi
callq 0x173d0
leaq 0x17b22(%rip), %rsi     # 0x3388f
movl $0x1, %ecx
movq %r14, %rdi
xorl %edx, %edx
callq 0x18100
cmpq $-0x1, %rax
je 0x1bef2
movq %rax, %r15
leaq 0x16867(%rip), %rsi     # 0x325f7
movl $0x1, %ecx
movq %r14, %rdi
xorl %edx, %edx
callq 0x18100
cmpq $-0x1, %rax
je 0x1c0b4
movq %rax, %r12
leaq 0x1(%r15), %r13
cmpq %rax, %r13
je 0x1c0dc
leaq -0x50(%rbp), %rdi
movq %r14, %rsi
xorl %edx, %edx
movq %r15, %rcx
callq 0x17bd0
decq %r12
leaq -0x70(%rbp), %rdi
movq %r14, %rsi
movq %r13, %rdx
movq %r12, %rcx
callq 0x17bd0
leaq -0x90(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x17550
movq -0x70(%rbp), %r13
callq 0x17040
movq %rax, %r12
movl (%rax), %eax
movl %eax, -0x2c(%rbp)
movl $0x0, (%r12)
leaq -0xb8(%rbp), %r15
movq %r13, %rdi
movq %r15, %rsi
movl $0xa, %edx
callq 0x172e0
movq %rax, -0x98(%rbp)
cmpq %r13, (%r15)
je 0x1c104
movl (%r12), %eax
testl %eax, %eax
je 0x1beff
cmpl $0x22, %eax
jne 0x1bf06
leaq 0x16ab8(%rip), %rdi     # 0x32903
callq 0x18040
movb $0x0, (%rbx)
movq $0x0, 0x8(%rbx)
movq 0xf0(%r15), %rsi
movq %rbx, %rdi
callq 0x17950
jmp 0x1be8d
xorl %esi, %esi
cmpq $0x0, 0xf0(%r15)
sete %sil
movb $0x0, (%rbx)
movq $0x0, 0x8(%rbx)
movq %rbx, %rdi
callq 0x17e70
movq %rbx, %rdi
movl $0x1, %esi
callq 0x17520
jmp 0x1c042
xorps %xmm0, %xmm0
leaq -0x90(%rbp), %rcx
movaps %xmm0, 0x10(%rcx)
movaps %xmm0, (%rcx)
leaq 0x13ef8(%rip), %rsi     # 0x2fdaf
leaq 0x13ef5(%rip), %rdx     # 0x2fdb3
movq %rbx, %rdi
movl $0x1, %r8d
xorl %r9d, %r9d
callq 0x18530
movq -0x80(%rbp), %rax
testq %rax, %rax
je 0x1c036
leaq -0x90(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x1c036
movq $-0x1, -0x98(%rbp)
jmp 0x1bf2a
movl -0x2c(%rbp), %eax
movl %eax, (%r12)
leaq -0x60(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1bf18
callq 0x17ae0
leaq -0x40(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1bf2a
callq 0x17ae0
leaq -0x70(%rbp), %rdi
leaq -0xc8(%rbp), %r12
leaq -0x90(%rbp), %rdx
movq %r12, %rsi
callq 0x17390
leaq -0x70(%rbp), %r15
movq (%r15), %rax
leaq -0x50(%rbp), %r13
movq %rax, (%r13)
movups 0x8(%r15), %xmm0
movups %xmm0, 0x8(%r13)
movq 0x18(%r15), %rax
movq %rax, 0x18(%r13)
movq %r12, (%r15)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%r15)
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
movq %rax, 0x18(%r15)
movq %r15, %rdi
callq 0x17200
movq %r13, %rdi
movq %r15, %rsi
callq 0x17bb0
testb %al, %al
jne 0x1c057
movq -0x98(%rbp), %r14
cmpq $-0x1, %r14
je 0x1bfdf
leaq -0x50(%rbp), %rdi
callq 0x18260
cmpb $0x2, (%rax)
jne 0x1c002
leaq -0x50(%rbp), %rdi
callq 0x18260
movzbl (%rax), %ecx
testl %ecx, %ecx
je 0x1bff9
cmpl $0x1, %ecx
je 0x1bfea
cmpl $0x2, %ecx
jne 0x1bff4
movq 0x8(%rax), %rax
movq 0x8(%rax), %rcx
subq (%rax), %rcx
sarq $0x4, %rcx
jmp 0x1bff9
leaq -0x50(%rbp), %rdi
callq 0x174a0
jmp 0x1c016
movq 0x8(%rax), %rax
movq 0x28(%rax), %rcx
jmp 0x1bff9
movl $0x1, %ecx
cmpq %rcx, %r14
jae 0x1c110
leaq -0x50(%rbp), %rdi
callq 0x174a0
movq %rax, %rdi
movq %r14, %rsi
callq 0x18370
movq %rbx, %rdi
movq %rax, %rsi
callq 0x17120
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x1c036
callq 0x17ae0
leaq -0xc8(%rbp), %rdi
callq 0x17d50
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 0x13d75(%rip), %rsi     # 0x2fde0
leaq -0xb8(%rbp), %rdi
movq %r14, %rdx
callq 0x17a50
leaq 0x13d69(%rip), %rsi     # 0x2fdea
leaq -0xb8(%rbp), %rdi
callq 0x18660
leaq -0x60(%rbp), %r14
movq %r14, -0x10(%r14)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
jne 0x1c17b
movups (%rcx), %xmm0
movups %xmm0, (%r14)
jmp 0x1c186
leaq -0x40(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x13cf1(%rip), %rsi     # 0x2fdb4
leaq 0x13d06(%rip), %rdx     # 0x2fdd0
leaq -0x50(%rbp), %rdi
callq 0x173a0
leaq -0x50(%rbp), %rsi
callq 0x17e50
leaq -0x40(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x13ce6(%rip), %rsi     # 0x2fdd1
leaq 0x13ced(%rip), %rdx     # 0x2fddf
leaq -0x50(%rbp), %rdi
callq 0x173a0
leaq -0x50(%rbp), %rsi
callq 0x17e50
leaq 0x167f8(%rip), %rdi     # 0x32903
callq 0x17600
movl $0x10, %edi
callq 0x17460
movq %r14, %rsi
movq %rax, %r14
leaq -0xe8(%rbp), %rdi
callq 0x17330
leaq 0x13cc2(%rip), %rsi     # 0x2fdf5
leaq -0xb8(%rbp), %rdi
leaq -0xe8(%rbp), %rdx
callq 0x183f0
leaq 0x13caf(%rip), %rsi     # 0x2fdfc
leaq -0xb8(%rbp), %rdi
callq 0x18660
leaq -0x60(%rbp), %r12
movq %r12, -0x10(%r12)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
jne 0x1c1c7
movups (%rcx), %xmm0
movups %xmm0, (%r12)
jmp 0x1c1d2
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, %r12b
movq %r15, %rdi
callq 0x18440
xorl %r12d, %r12d
movq 0x20e1a(%rip), %rsi     # 0x3cfd0
movq 0x20de3(%rip), %rdx     # 0x3cfa0
movq %r15, %rdi
callq 0x18420
jmp 0x1c211
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 0x18120
xorl %r15d, %r15d
movq 0x20db6(%rip), %rsi     # 0x3cfb8
movq 0x20d7f(%rip), %rdx     # 0x3cf88
movq %r14, %rdi
callq 0x18420
movq %rax, %rbx
movq -0x70(%rbp), %rdi
cmpq %r12, %rdi
je 0x1c22a
callq 0x17ae0
jmp 0x1c22a
movq %rax, %rbx
movb $0x1, %r15b
leaq -0xa8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1c23f
callq 0x17ae0
leaq -0xd8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1c254
callq 0x17ae0
testb %r15b, %r15b
jne 0x1c27b
jmp 0x1c36c
movq %rax, %rbx
leaq -0xd8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1c27b
callq 0x17ae0
jmp 0x1c27b
movq %rax, %rbx
movq %r14, %rdi
jmp 0x1c2ef
movq %rax, %rbx
movq -0x70(%rbp), %rdi
cmpq %r14, %rdi
je 0x1c291
callq 0x17ae0
leaq -0xa8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1c2a6
callq 0x17ae0
testb %r12b, %r12b
jne 0x1c2ec
jmp 0x1c36c
movq %rax, %rbx
leaq -0xa8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1c2ec
callq 0x17ae0
jmp 0x1c2ec
jmp 0x1c2d1
jmp 0x1c369
movq %rax, %rbx
movq -0x50(%rbp), %rdi
cmpq %r14, %rdi
jne 0x1c359
jmp 0x1c36c
jmp 0x1c369
jmp 0x1c315
movq %rax, %rbx
movq %r15, %rdi
callq 0x17780
jmp 0x1c36c
movq %rax, %rbx
movq -0x80(%rbp), %rax
testq %rax, %rax
je 0x1c381
leaq -0x90(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x1c381
movq %rax, %rdi
callq 0x1d3c1
movq %rax, %rbx
jmp 0x1c33a
movq %rax, %rbx
jmp 0x1c34c
jmp 0x1c369
movq %rax, %rbx
cmpl $0x0, (%r12)
jne 0x1c33a
movl -0x2c(%rbp), %eax
movl %eax, (%r12)
leaq -0x60(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1c34c
callq 0x17ae0
leaq -0x40(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1c36c
callq 0x17ae0
jmp 0x1c36c
jmp 0x1c369
jmp 0x1c369
movq %rax, %rbx
jmp 0x1c381
movq %rax, %rbx
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x1c381
callq 0x17ae0
leaq -0xc8(%rbp), %rdi
callq 0x17d50
movq %rbx, %rdi
callq 0x18490
nop