// File: 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
subq $0x390, %rsp            # imm = 0x390
movq %rsi, -0x2b0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x2a8(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x6a5a0
movq $0x1, -0x50(%rbp)
movq -0x2b0(%rbp), %rdi
movq -0x50(%rbp), %rax
movq %rax, -0x2b8(%rbp)
callq 0x6dab0
movq %rax, %rcx
movq -0x2b8(%rbp), %rax
cmpq %rcx, %rax
je 0x75b6d
movq -0x2b0(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x6a180
movq %rax, -0x2c0(%rbp)
jmp 0x7584d
movq -0x2c0(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
leaq 0x33df8(%rip), %rsi     # 0xa965b
xorl %eax, %eax
movl %eax, %edx
callq 0x688f0
cmpq $-0x1, %rax
jne 0x758ce
movq -0x58(%rbp), %rdx
leaq 0x33eab(%rip), %rsi     # 0xa9728
leaq -0x88(%rbp), %rdi
callq 0x6a3b0
jmp 0x7588b
movq -0x2a8(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x6ba10
jmp 0x758a0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x7617c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x6e458
jmp 0x7617c
movq -0x2a8(%rbp), %rsi
movq -0x58(%rbp), %rdx
leaq -0xa0(%rbp), %rdi
movl $0x3d, %ecx
callq 0x6b520
jmp 0x758ec
leaq -0xa0(%rbp), %rdi
callq 0x6dab0
cmpq $0x2, %rax
je 0x7595a
movq -0x58(%rbp), %rdx
leaq 0x33e48(%rip), %rsi     # 0xa9751
leaq -0xc0(%rbp), %rdi
callq 0x6a3b0
jmp 0x75917
movq -0x2a8(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x6ba10
jmp 0x7592c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x75b5c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x6e458
jmp 0x75b5c
leaq -0xa0(%rbp), %rdi
movl $0x1, %esi
callq 0x67da0
movq %rax, -0x2c8(%rbp)
jmp 0x75974
movq -0x2c8(%rbp), %rdx
movq -0x2a8(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x68ce0
movq %rax, -0x2d0(%rbp)
jmp 0x75994
movq -0x2d0(%rbp), %rax
movq %rax, -0xc8(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x696e0
movq %rax, -0xd8(%rbp)
leaq -0xd0(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x6c430
leaq -0xc8(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x6d310
testb $0x1, %al
jne 0x759e1
jmp 0x75a8c
movq -0xc8(%rbp), %rax
movq %rax, -0xe0(%rbp)
xorl %eax, %eax
movl %eax, %esi
leaq -0xa0(%rbp), %rdi
callq 0x67da0
movq %rax, -0x2d8(%rbp)
jmp 0x75a08
leaq -0xc8(%rbp), %rdi
callq 0x6e120
movq -0x2d8(%rbp), %rsi
movq %rax, %rdx
addq $0x20, %rdx
leaq -0x120(%rbp), %rdi
callq 0x6d650
jmp 0x75a30
movq -0xe0(%rbp), %rsi
leaq -0x48(%rbp), %rdi
leaq -0x120(%rbp), %rdx
callq 0x67b10
movq %rax, -0x2e0(%rbp)
jmp 0x75a50
movq -0x2e0(%rbp), %rax
movq %rax, -0x128(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x676a0
jmp 0x75b3f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x676a0
jmp 0x75b5c
movq -0xc8(%rbp), %rax
movq %rax, -0x130(%rbp)
xorl %eax, %eax
movl %eax, %esi
leaq -0xa0(%rbp), %rdi
callq 0x67da0
movq %rax, -0x2e8(%rbp)
jmp 0x75ab3
leaq -0xa0(%rbp), %rdi
movl $0x1, %esi
callq 0x67da0
movq %rax, -0x2f0(%rbp)
jmp 0x75acd
movq -0x2f0(%rbp), %rdx
movq -0x2e8(%rbp), %rsi
leaq -0x170(%rbp), %rdi
callq 0x6a430
jmp 0x75ae9
movq -0x130(%rbp), %rsi
leaq -0x48(%rbp), %rdi
leaq -0x170(%rbp), %rdx
callq 0x67b10
movq %rax, -0x2f8(%rbp)
jmp 0x75b09
movq -0x2f8(%rbp), %rax
movq %rax, -0x178(%rbp)
leaq -0x170(%rbp), %rdi
callq 0x676a0
jmp 0x75b3f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x170(%rbp), %rdi
callq 0x676a0
jmp 0x75b5c
leaq -0xa0(%rbp), %rdi
callq 0x69870
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x7580a
leaq -0xa0(%rbp), %rdi
callq 0x69870
jmp 0x7617c
movq $0x1, -0x180(%rbp)
movq -0x180(%rbp), %rax
movq %rax, -0x300(%rbp)
movq -0x18(%rbp), %rdi
callq 0x6dab0
movq %rax, %rcx
movq -0x300(%rbp), %rax
cmpq %rcx, %rax
je 0x7616a
movq -0x18(%rbp), %rdi
movq -0x180(%rbp), %rsi
callq 0x67da0
movq %rax, -0x308(%rbp)
jmp 0x75bbb
movq -0x308(%rbp), %rsi
leaq -0x1a0(%rbp), %rdi
callq 0x685c0
jmp 0x75bd0
movq -0x18(%rbp), %rdi
movq -0x180(%rbp), %rsi
decq %rsi
callq 0x67da0
movq %rax, -0x310(%rbp)
jmp 0x75bec
movq -0x310(%rbp), %rsi
leaq -0x1c0(%rbp), %rdi
callq 0x685c0
jmp 0x75c01
leaq -0x1a0(%rbp), %rdi
movq 0x50291(%rip), %rsi     # 0xc5ea0
callq 0x6da60
testb $0x1, %al
jne 0x75c1d
jmp 0x76107
leaq -0x1a0(%rbp), %rdi
movq 0x5030d(%rip), %rsi     # 0xc5f38
callq 0x6da60
testb $0x1, %al
jne 0x75c39
jmp 0x76107
leaq -0x1a0(%rbp), %rdi
movq 0x50369(%rip), %rsi     # 0xc5fb0
callq 0x6da60
testb $0x1, %al
jne 0x75c55
jmp 0x76107
leaq -0x1a0(%rbp), %rdi
movq 0x50345(%rip), %rsi     # 0xc5fa8
callq 0x6da60
testb $0x1, %al
jne 0x75c71
jmp 0x76107
leaq -0x1a0(%rbp), %rdi
movq 0x501d9(%rip), %rsi     # 0xc5e58
callq 0x6da60
testb $0x1, %al
jne 0x75c8d
jmp 0x76107
leaq -0x1a0(%rbp), %rdi
movq 0x502cd(%rip), %rsi     # 0xc5f68
callq 0x6da60
testb $0x1, %al
jne 0x75ca9
jmp 0x76107
leaq -0x1a0(%rbp), %rdi
movq 0x501f9(%rip), %rsi     # 0xc5eb0
callq 0x6da60
testb $0x1, %al
jne 0x75cc5
jmp 0x76107
leaq -0x1a0(%rbp), %rdi
movq 0x50155(%rip), %rsi     # 0xc5e28
callq 0x6da60
testb $0x1, %al
jne 0x75ce1
jmp 0x76107
leaq -0x48(%rbp), %rdi
leaq -0x1a0(%rbp), %rsi
callq 0x68c20
movq %rax, -0x318(%rbp)
jmp 0x75cfa
movq -0x318(%rbp), %rax
movq %rax, -0x1c8(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x696e0
movq %rax, -0x1d0(%rbp)
leaq -0x1c8(%rbp), %rdi
leaq -0x1d0(%rbp), %rsi
callq 0x6c5b0
testb $0x1, %al
jne 0x75d31
jmp 0x75d62
movl $0x7, -0x1d4(%rbp)
jmp 0x76111
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x7615c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x76150
leaq -0x1c8(%rbp), %rdi
callq 0x6b200
movq %rax, %rsi
addq $0x20, %rsi
leaq -0x1f8(%rbp), %rdi
callq 0x685c0
jmp 0x75d83
xorl %eax, %eax
movl %eax, %esi
leaq -0x1f8(%rbp), %rdi
callq 0x6e320
movq %rax, -0x320(%rbp)
jmp 0x75d9c
movq -0x320(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x27, %eax
je 0x75de9
xorl %eax, %eax
movl %eax, %esi
leaq -0x1f8(%rbp), %rdi
callq 0x6e320
movq %rax, -0x328(%rbp)
jmp 0x75dc4
movq -0x328(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x22, %eax
je 0x75de9
jmp 0x760a7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x760f9
leaq -0x1c0(%rbp), %rdi
movq 0x500a9(%rip), %rsi     # 0xc5ea0
callq 0x6da60
testb $0x1, %al
jne 0x75e02
jmp 0x75e11
movl $0x7, -0x1d4(%rbp)
jmp 0x760df
leaq -0x1f8(%rbp), %rdi
movq %rdi, -0x338(%rbp)
callq 0x69740
movq -0x338(%rbp), %rdi
movq %rax, %rsi
decq %rsi
callq 0x6e320
movq %rax, -0x330(%rbp)
jmp 0x75e3f
movq -0x330(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x27, %eax
je 0x75f17
leaq -0x1f8(%rbp), %rdi
movq %rdi, -0x348(%rbp)
callq 0x69740
movq -0x348(%rbp), %rdi
movq %rax, %rsi
decq %rsi
callq 0x6e320
movq %rax, -0x340(%rbp)
jmp 0x75e80
movq -0x340(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x22, %eax
je 0x75f17
leaq 0x338e6(%rip), %rsi     # 0xa9780
leaq -0x238(%rbp), %rdi
leaq -0x1f8(%rbp), %rdx
callq 0x6a3b0
jmp 0x75eaf
leaq 0x338df(%rip), %rdx     # 0xa9795
leaq -0x218(%rbp), %rdi
leaq -0x238(%rbp), %rsi
callq 0x678d0
jmp 0x75ecb
movq -0x2a8(%rbp), %rdi
leaq -0x218(%rbp), %rsi
callq 0x6ba10
jmp 0x75ee0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x75f06
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x218(%rbp), %rdi
callq 0x6e458
leaq -0x238(%rbp), %rdi
callq 0x6e458
jmp 0x760f9
leaq -0x1f8(%rbp), %rdi
movq %rdi, -0x350(%rbp)
callq 0x69740
movq -0x350(%rbp), %rsi
movq %rax, %rcx
addq $-0x2, %rcx
leaq -0x258(%rbp), %rdi
movl $0x1, %edx
callq 0x6ac50
jmp 0x75f4b
leaq -0x1f8(%rbp), %rdi
leaq -0x258(%rbp), %rsi
movq %rsi, -0x368(%rbp)
callq 0x6b6a0
movq -0x368(%rbp), %rdi
callq 0x6e458
movq -0x180(%rbp), %rax
decq %rax
movq %rax, -0x180(%rbp)
movq -0x18(%rbp), %rdi
movq %rdi, -0x360(%rbp)
callq 0x6d0e0
movq %rax, -0x270(%rbp)
movq -0x180(%rbp), %rsi
leaq -0x270(%rbp), %rdi
callq 0x68e60
movq %rax, -0x268(%rbp)
leaq -0x260(%rbp), %rdi
leaq -0x268(%rbp), %rsi
callq 0x6adf0
movq -0x360(%rbp), %rdi
movq -0x260(%rbp), %rsi
callq 0x6abb0
movq %rax, -0x358(%rbp)
jmp 0x75fe2
movq -0x358(%rbp), %rax
movq %rax, -0x278(%rbp)
movq -0x18(%rbp), %rdi
movq %rdi, -0x378(%rbp)
callq 0x6d0e0
movq %rax, -0x290(%rbp)
movq -0x180(%rbp), %rsi
leaq -0x290(%rbp), %rdi
callq 0x68e60
movq %rax, -0x288(%rbp)
leaq -0x280(%rbp), %rdi
leaq -0x288(%rbp), %rsi
callq 0x6adf0
movq -0x378(%rbp), %rdi
movq -0x280(%rbp), %rsi
callq 0x6abb0
movq %rax, -0x370(%rbp)
jmp 0x76050
movq -0x370(%rbp), %rax
movq %rax, -0x298(%rbp)
movq $0x0, -0x2a0(%rbp)
movq -0x2a0(%rbp), %rax
movq %rax, -0x380(%rbp)
movq -0x18(%rbp), %rdi
callq 0x6dab0
movq %rax, %rcx
movq -0x380(%rbp), %rax
cmpq %rcx, %rax
je 0x760a5
jmp 0x76091
movq -0x2a0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x2a0(%rbp)
jmp 0x76069
jmp 0x760a7
movq -0x18(%rbp), %rdi
movq -0x180(%rbp), %rsi
callq 0x67da0
movq %rax, -0x388(%rbp)
jmp 0x760c0
movq -0x388(%rbp), %rdi
leaq -0x1f8(%rbp), %rsi
callq 0x67190
jmp 0x760d5
movl $0x0, -0x1d4(%rbp)
leaq -0x1f8(%rbp), %rdi
callq 0x6e458
movl -0x1d4(%rbp), %eax
testl %eax, %eax
jne 0x76111
jmp 0x760f7
jmp 0x76107
leaq -0x1f8(%rbp), %rdi
callq 0x6e458
jmp 0x76150
movl $0x0, -0x1d4(%rbp)
leaq -0x1c0(%rbp), %rdi
callq 0x6e458
leaq -0x1a0(%rbp), %rdi
callq 0x6e458
movl -0x1d4(%rbp), %eax
testl %eax, %eax
je 0x76137
jmp 0x76135
jmp 0x76139
jmp 0x76139
movq -0x180(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x180(%rbp)
jmp 0x75b78
leaq -0x1c0(%rbp), %rdi
callq 0x6e458
leaq -0x1a0(%rbp), %rdi
callq 0x6e458
jmp 0x7617c
leaq -0x48(%rbp), %rdi
callq 0x6b990
addq $0x390, %rsp            # imm = 0x390
popq %rbp
retq
leaq -0x48(%rbp), %rdi
callq 0x6b990
movq -0x60(%rbp), %rdi
callq 0x6d7b0
nop