// File: /workspace/github_cpp_makefile_star2_O3/xelia-it[P]mustache/src/mustache-light.cpp
// Function: mustache::Mustache::partialSubstitute(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>&)
void Mustache::partialSubstitute(const Tokens partialParams, Tokens& newTokens) {
        Variables partialVariables;
        LOG_END("===============================================");

        for (std::vector<string>::size_type i = 1; i != partialParams.size(); i++) {
                LOG("Token: |");
                const string& token = partialParams.at(i);
                LOG(token);
                LOG_END("|");
                if (token.find_first_of("=") == std::string::npos) {
                        error("Bad substitution string: missing '=' in " + token);
                }
                vector<string> pair = split(token, '=');
                if (pair.size() != 2) {
                        error("Bad substitution string: missing separator in " + token);
                }

                VariableConstIterator lb = partialSearchVariable(partialVariables, pair.at(1));

                // map<string, string>::iterator lb = partialVariables.lower_bound(pair.at(0));
                // if (lb != partialVariables.end() && !(partialVariables.key_comp()(pair.at(0), lb->first))) {
                if (lb != partialVariables.end()) {
                        // key already exists
                        // update lb->second if you care to
                        partialVariables.insert(lb, map<string, string>::value_type(pair.at(0), lb->second ));
                } else {
                        // the key does not exist in the map
                        // add it to the map
                        partialVariables.insert(lb, map<string, string>::value_type(pair.at(0), pair.at(1)));
                        // Use lb as a hint to insert,
                        // so it can avoid another lookup
                }
        }

        LOG_END("===============================================");
        for (Tokens::size_type i = 1; i != newTokens.size(); i++) {
                //LOG("  New token: ");
                string tokenToCheck = newTokens.at(i);
                string tokenToCheckPrev = newTokens.at(i-1);
                //LOG_END(tokenToCheck);
                if ((tokenToCheck != TOKEN_START_VARIABLE) &&
                    (tokenToCheck != TOKEN_START_BEGIN_SECTION) &&
                    (tokenToCheck != TOKEN_START_END_SECTION) &&
                    (tokenToCheck != TOKEN_START_IF) &&
                    (tokenToCheck != TOKEN_START_UNLESS) &&
                    (tokenToCheck != TOKEN_START_PARTIAL) &&
                    (tokenToCheck != TOKEN_START_TEMPLATE) &&
                    (tokenToCheck != TOKEN_END)) {

                        // Searching
                        LOG("  Searching: ");
                        LOG(tokenToCheck);

                        VariableIterator lb = partialVariables.find(tokenToCheck);
                        if (lb == partialVariables.end()) {
                                LOG_END(" -> Not Found");
                                continue;
                        }
                        LOG(" -> { ");
                        LOG(lb->first);
                        LOG(" : ");
                        LOG(lb->second);
                        LOG_END(" }");

                        // Substitution
                        LOG("    Substitute: ");
                        string valueToSubstitute = lb->second;
                        LOG(newTokens.at(i));
                        LOG("    at position ");
                        LOG(i);

                        if (valueToSubstitute[0] != '\'' && valueToSubstitute[0] != '\"') {
                                // Simple substitution
                                LOG_END("    with nothing");
                                // newTokens.at(i) = valueToSubstitute;
                        } else {
                                // Substitute literal

                                if (tokenToCheckPrev != TOKEN_START_VARIABLE) {
                                        LOG_END("");
                                        LOG_END("NOT A VARIABLE SKIP LITERAL SUBSTITUTION!");
                                        continue;
                                }

                                if (valueToSubstitute[valueToSubstitute.size() - 1 ] != '\'' && valueToSubstitute[valueToSubstitute.size() - 1] != '\"') {
                                        error("Substitution string " + valueToSubstitute + " not properly closed");
                                }
                                LOG(" with literal ");
                                valueToSubstitute = valueToSubstitute.substr(1, valueToSubstitute.size() - 2);
                                LOG_END(valueToSubstitute);

                                // LOG_END("DUMP BEFORE:");
                                // for (std::vector<string>::size_type j = 0; j != newTokens.size(); j++) {
                                //     LOG(j);
                                //     LOG(" ");
                                //     LOG_END(newTokens.at(j));
                                // }

                                i = i - 1;
                                newTokens.erase(newTokens.begin() + i);
                                newTokens.erase(newTokens.begin() + i);

                                LOG_END("DUMP AFTER:");
                                for (std::vector<string>::size_type j = 0; j != newTokens.size(); j++) {
                                        LOG(j);
                                        LOG(" ");
                                        LOG_END(newTokens.at(j));
                                }

                                LOG("NOW i = ");
                                LOG_END(i);
                        }
                        newTokens.at(i) = valueToSubstitute;
                }
        }
        //partialVariables.clear();
        LOG_END("===============================================");
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %rdx, -0x30(%rbp)
movq %rdi, -0xe0(%rbp)
leaq -0x108(%rbp), %rcx
movl $0x0, (%rcx)
xorl %eax, %eax
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %rax, 0x20(%rcx)
movq (%rsi), %r15
movq 0x8(%rsi), %rdx
subq %r15, %rdx
cmpq $0x20, %rdx
jne 0x1c7a2
movq -0x30(%rbp), %r14
movq (%r14), %rax
movq 0x8(%r14), %rdx
subq %rax, %rdx
cmpq $0x20, %rdx
jne 0x1c956
leaq -0x110(%rbp), %rdi
callq 0x179e0
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rsi, %r14
sarq $0x5, %rdx
movl $0x1, %r13d
movl $0x20, %r12d
movq $0x0, -0xb8(%rbp)
cmpq %r13, %rdx
jbe 0x1cd8c
addq %r12, %r15
movl $0x1, %ecx
movq %r15, %rdi
leaq 0x1348c(%rip), %rsi     # 0x2fc67
xorl %edx, %edx
callq 0x18100
cmpq $-0x1, %rax
je 0x1cd4c
leaq -0xb0(%rbp), %rdi
movq -0xe0(%rbp), %rsi
movq %r15, %rdx
movl $0x3d, %ecx
callq 0x17d10
movq -0xb0(%rbp), %rsi
movq -0xa8(%rbp), %rax
movq %rax, %rcx
subq %rsi, %rcx
cmpq $0x40, %rcx
jne 0x1cd6c
movq 0x20(%rsi), %rcx
movzbl (%rcx), %ecx
movl $0x2, %edx
cmpl $0x22, %ecx
je 0x1c83b
cmpl $0x27, %ecx
jne 0x1c887
leaq -0x108(%rbp), %r15
cmpq %rsi, %rax
je 0x1cdcb
cmpq $0x2, %rdx
jb 0x1cdbf
leaq 0x20(%rsi), %rdx
leaq -0x70(%rbp), %rbx
movq %rbx, %rdi
callq 0x17a60
leaq -0x110(%rbp), %rdi
movq %rdi, -0x90(%rbp)
movq %r15, %rsi
movq %rbx, %rdx
leaq -0x90(%rbp), %rcx
callq 0x17320
jmp 0x1c8f4
addq $0x20, %rsi
leaq -0x110(%rbp), %rdi
callq 0x18190
movq %rax, %r15
movq -0xb0(%rbp), %rsi
movq -0xa8(%rbp), %rax
leaq -0x108(%rbp), %rcx
cmpq %rcx, %r15
je 0x1c947
cmpq %rsi, %rax
je 0x1cde0
movq %r15, %rdx
addq $0x40, %rdx
leaq -0x70(%rbp), %rbx
movq %rbx, %rdi
callq 0x18470
leaq -0x110(%rbp), %rdi
movq %rdi, -0x90(%rbp)
movq %r15, %rsi
movq %rbx, %rdx
leaq -0x90(%rbp), %rcx
callq 0x17320
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x1c906
callq 0x17ae0
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x1c918
callq 0x17ae0
leaq -0xb0(%rbp), %rdi
callq 0x17790
incq %r13
movq (%r14), %r15
movq 0x8(%r14), %rdx
subq %r15, %rdx
sarq $0x5, %rdx
addq $0x20, %r12
cmpq %rdx, %r13
jne 0x1c7c0
jmp 0x1c76c
movq %rax, %rdx
subq %rsi, %rdx
sarq $0x5, %rdx
jmp 0x1c842
sarq $0x5, %rdx
movl $0x1, %r15d
leaq -0xd8(%rbp), %rbx
cmpq %r15, %rdx
jbe 0x1cdae
movq %r15, %rcx
shlq $0x5, %rcx
leaq -0x60(%rbp), %rdx
movq %rdx, -0x70(%rbp)
movq (%rax,%rcx), %rsi
movq 0x8(%rax,%rcx), %rdx
addq %rsi, %rdx
leaq -0x70(%rbp), %rdi
callq 0x173d0
leaq -0x1(%r15), %r13
movq (%r14), %rax
movq 0x8(%r14), %rdx
subq %rax, %rdx
sarq $0x5, %rdx
cmpq %r13, %rdx
jbe 0x1cd9d
movq %r13, %r12
shlq $0x5, %r12
leaq -0xa0(%rbp), %rcx
movq %rcx, -0xb0(%rbp)
movq (%rax,%r12), %rsi
movq 0x8(%rax,%r12), %rdx
addq %rsi, %rdx
leaq -0xb0(%rbp), %rdi
callq 0x173d0
movq -0x68(%rbp), %r14
movq 0x204f9(%rip), %rax     # 0x3cee0
cmpq 0x8(%rax), %r14
jne 0x1ca14
testq %r14, %r14
je 0x1cc1e
movq 0x204e3(%rip), %rax     # 0x3cee0
movq (%rax), %rsi
movq -0x70(%rbp), %rdi
movq %r14, %rdx
callq 0x17bc0
testl %eax, %eax
je 0x1cc1e
movq 0x20545(%rip), %rax     # 0x3cf60
cmpq 0x8(%rax), %r14
jne 0x1ca48
testq %r14, %r14
je 0x1cc1e
movq 0x2052f(%rip), %rax     # 0x3cf60
movq (%rax), %rsi
movq -0x70(%rbp), %rdi
movq %r14, %rdx
callq 0x17bc0
testl %eax, %eax
je 0x1cc1e
movq 0x20561(%rip), %rax     # 0x3cfb0
cmpq 0x8(%rax), %r14
jne 0x1ca7c
testq %r14, %r14
je 0x1cc1e
movq 0x2054b(%rip), %rax     # 0x3cfb0
movq (%rax), %rsi
movq -0x70(%rbp), %rdi
movq %r14, %rdx
callq 0x17bc0
testl %eax, %eax
je 0x1cc1e
movq 0x20525(%rip), %rax     # 0x3cfa8
cmpq 0x8(%rax), %r14
jne 0x1cab0
testq %r14, %r14
je 0x1cc1e
movq 0x2050f(%rip), %rax     # 0x3cfa8
movq (%rax), %rsi
movq -0x70(%rbp), %rdi
movq %r14, %rdx
callq 0x17bc0
testl %eax, %eax
je 0x1cc1e
movq 0x203e9(%rip), %rax     # 0x3cea0
cmpq 0x8(%rax), %r14
jne 0x1cae4
testq %r14, %r14
je 0x1cc1e
movq 0x203d3(%rip), %rax     # 0x3cea0
movq (%rax), %rsi
movq -0x70(%rbp), %rdi
movq %r14, %rdx
callq 0x17bc0
testl %eax, %eax
je 0x1cc1e
movq 0x20495(%rip), %rax     # 0x3cf80
cmpq 0x8(%rax), %r14
jne 0x1cb18
testq %r14, %r14
je 0x1cc1e
movq 0x2047f(%rip), %rax     # 0x3cf80
movq (%rax), %rsi
movq -0x70(%rbp), %rdi
movq %r14, %rdx
callq 0x17bc0
testl %eax, %eax
je 0x1cc1e
movq 0x203d1(%rip), %rax     # 0x3cef0
cmpq 0x8(%rax), %r14
jne 0x1cb4c
testq %r14, %r14
je 0x1cc1e
movq 0x203bb(%rip), %rax     # 0x3cef0
movq (%rax), %rsi
movq -0x70(%rbp), %rdi
movq %r14, %rdx
callq 0x17bc0
testl %eax, %eax
je 0x1cc1e
movq 0x20325(%rip), %rax     # 0x3ce78
cmpq 0x8(%rax), %r14
jne 0x1cb80
testq %r14, %r14
je 0x1cc1e
movq 0x2030f(%rip), %rax     # 0x3ce78
movq (%rax), %rsi
movq -0x70(%rbp), %rdi
movq %r14, %rdx
callq 0x17bc0
testl %eax, %eax
je 0x1cc1e
leaq -0x110(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x176f0
leaq -0x108(%rbp), %rcx
cmpq %rcx, %rax
movq -0x30(%rbp), %r14
je 0x1cc71
leaq -0x80(%rbp), %rcx
movq %rcx, -0x90(%rbp)
movq 0x40(%rax), %rsi
movq 0x48(%rax), %rdx
addq %rsi, %rdx
leaq -0x90(%rbp), %rdi
callq 0x173d0
movq -0x90(%rbp), %r14
movzbl (%r14), %eax
cmpl $0x22, %eax
je 0x1cbdf
cmpl $0x27, %eax
jne 0x1cc76
movq -0xa8(%rbp), %rdx
movq 0x202f3(%rip), %rax     # 0x3cee0
cmpq 0x8(%rax), %rdx
jne 0x1cc16
testq %rdx, %rdx
je 0x1cc86
movq 0x202dd(%rip), %rax     # 0x3cee0
movq (%rax), %rsi
movq -0xb0(%rbp), %rdi
callq 0x17bc0
testl %eax, %eax
je 0x1cc86
movq %r15, %r13
jmp 0x1cd32
movq %r15, %r13
movq -0x30(%rbp), %r14
movq -0xb0(%rbp), %rdi
leaq -0xa0(%rbp), %rax
cmpq %rax, %rdi
je 0x1cc3d
callq 0x17ae0
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x1cc4f
callq 0x17ae0
incq %r13
movq (%r14), %rax
movq 0x8(%r14), %rdx
subq %rax, %rdx
sarq $0x5, %rdx
movq %r13, %r15
cmpq %rdx, %r13
jne 0x1c967
jmp 0x1c784
movq %r15, %r13
jmp 0x1cc25
movq %r15, %r13
leaq -0x90(%rbp), %r14
movq -0x30(%rbp), %r15
jmp 0x1cd02
movq -0x88(%rbp), %rcx
movzbl -0x1(%r14,%rcx), %eax
cmpl $0x22, %eax
je 0x1cca1
cmpl $0x27, %eax
jne 0x1ce03
addq $-0x2, %rcx
movl $0x1, %edx
movq %rbx, %r15
movq %rbx, %rdi
leaq -0x90(%rbp), %r14
movq %r14, %rsi
callq 0x17bd0
movq %r14, %rdi
movq %r15, %rsi
callq 0x17d60
movq -0xd8(%rbp), %rdi
leaq -0xc8(%rbp), %rax
cmpq %rax, %rdi
je 0x1cce2
callq 0x17ae0
movq -0x30(%rbp), %r15
movq (%r15), %rsi
addq %r12, %rsi
movq %r15, %rdi
callq 0x17610
addq (%r15), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x17610
movq (%r15), %rdi
movq 0x8(%r15), %rdx
subq %rdi, %rdx
sarq $0x5, %rdx
cmpq %r13, %rdx
jbe 0x1cdf2
movq %r13, %rax
shlq $0x5, %rax
addq %rax, %rdi
movq %r14, %rsi
callq 0x17550
movq -0x90(%rbp), %r14
leaq -0x80(%rbp), %rax
cmpq %rax, %r14
je 0x1cc21
movq %r14, %rdi
callq 0x17ae0
jmp 0x1cc21
leaq -0x60(%rbp), %r14
leaq 0x12fc8(%rip), %rsi     # 0x2fd1f
leaq -0x70(%rbp), %rdi
movq %r15, %rdx
callq 0x17a50
leaq -0x70(%rbp), %rsi
callq 0x17e50
leaq -0x60(%rbp), %r14
leaq 0x12fd1(%rip), %rsi     # 0x2fd48
leaq -0x70(%rbp), %rdi
movq %r15, %rdx
callq 0x17a50
leaq -0x70(%rbp), %rsi
callq 0x17e50
leaq 0x16941(%rip), %rdi     # 0x336d4
movq %r13, %rsi
xorl %eax, %eax
callq 0x180f0
leaq 0x16930(%rip), %rdi     # 0x336d4
movq %r13, %rsi
xorl %eax, %eax
callq 0x180f0
leaq 0x1691f(%rip), %rdi     # 0x336d4
movq %r15, %rsi
xorl %eax, %eax
callq 0x180f0
movl $0x1, %eax
movq %rax, -0xb8(%rbp)
leaq 0x16902(%rip), %rdi     # 0x336d4
movq -0xb8(%rbp), %rsi
xorl %eax, %eax
callq 0x180f0
leaq 0x168ed(%rip), %rdi     # 0x336d4
xorl %esi, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x180f0
leaq 0x168db(%rip), %rdi     # 0x336d4
movq %r13, %rsi
xorl %eax, %eax
callq 0x180f0
leaq 0x12f6d(%rip), %rsi     # 0x2fd77
leaq -0x130(%rbp), %rdi
leaq -0x90(%rbp), %rdx
callq 0x17a50
leaq 0x12f68(%rip), %rsi     # 0x2fd8c
leaq -0x130(%rbp), %rdi
callq 0x18660
leaq -0xc8(%rbp), %rcx
movq %rcx, -0xd8(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
jne 0x1ce5c
movups (%rcx), %xmm0
leaq -0xc8(%rbp), %rdx
movups %xmm0, (%rdx)
jmp 0x1ce6d
movq %rdx, -0xd8(%rbp)
movq (%rcx), %rdx
movq %rdx, -0xc8(%rbp)
movq 0x8(%rax), %rdx
leaq -0xd8(%rbp), %rsi
movq %rdx, 0x8(%rsi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
callq 0x17e50
movq %rax, %rbx
movq -0xd8(%rbp), %rdi
leaq -0xc8(%rbp), %rax
cmpq %rax, %rdi
je 0x1ceb0
callq 0x17ae0
jmp 0x1ceb0
movq %rax, %rbx
leaq -0x120(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1ced4
callq 0x17ae0
jmp 0x1ced4
jmp 0x1ced1
jmp 0x1ced1
jmp 0x1ced1
jmp 0x1ced1
jmp 0x1ced1
movq %rax, %rbx
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x1cef0
callq 0x17ae0
jmp 0x1cef0
jmp 0x1ceed
movq %rax, %rbx
movq -0xb0(%rbp), %rdi
leaq -0xa0(%rbp), %rax
cmpq %rax, %rdi
je 0x1cf50
callq 0x17ae0
jmp 0x1cf50
jmp 0x1cf6b
jmp 0x1cf37
jmp 0x1cf6b
jmp 0x1cf6b
movq %rax, %rbx
movq -0x70(%rbp), %rdi
cmpq %r14, %rdi
je 0x1cf6e
callq 0x17ae0
jmp 0x1cf6e
jmp 0x1cf6b
movq %rax, %rbx
movq -0x70(%rbp), %rdi
cmpq %r14, %rdi
jne 0x1cf5d
jmp 0x1cf7a
jmp 0x1cf66
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0x17160
jmp 0x1cf6e
jmp 0x1cf6b
jmp 0x1cf66
jmp 0x1cf66
jmp 0x1cf4d
movq %rax, %rbx
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x1cf7a
callq 0x17ae0
jmp 0x1cf7a
jmp 0x1cf66
movq %rax, %rbx
jmp 0x1cf7a
movq %rax, %rbx
leaq -0xb0(%rbp), %rdi
callq 0x17790
leaq -0x110(%rbp), %rdi
callq 0x179e0
movq %rbx, %rdi
callq 0x18490