// File: /workspace/github_cpp_makefile_star2_O2/xelia-it[P]mustache/src/mustache-light.cpp
// Function: mustache::Mustache::producePartial()
void Mustache::producePartial() {
        bool useTemplate = (tokens_.at(currentToken_ - 1) == TOKEN_START_TEMPLATE);
        LOG("PARTIAL := ");
        LOG_END("");
        LOG_START("  ");

        // Token must be (txt)
        CHECK_TOKEN_IS_TEXT();

        // Variable completePartialToken should be something like:
        //   paragraph.mustache|title=SampleTitle|text=SampleText
        // The first part is the partial file name.
        const string& partialToken = tokens_.at(currentToken_);
        LOG(" ");
        LOG(partialToken);
        LOG(" ");
        ensureValidIdentifier(partialToken, VALID_CHARS_FOR_PARTIALS);

        CONSUME_TOKEN();
        CHECK_TOKEN_NOT_EMPTY();
        CHECK_TOKEN_IS(TOKEN_END);
        LOG(" ");
        LOG_END(TOKEN_END);

        // Split token using partial variable separator.
        Tokens splitted = split(partialToken, '|');
        for (size_t i = 0; i < splitted.size(); i++) {
                splitted.at(i) = trim(splitted.at(i));
        }

        // Tokenize
        string fileToRead;
        if (useTemplate) {
                LOG_END("  Use template");
                fileToRead = getTemplateNameFromContext(splitted.at(0));
        } else {
                LOG_END("  Use normal partial");
                fileToRead = splitted.at(0);
        }
        LOG("  File to read: ");
        LOG_END(fileToRead);
        string viewFromPartial = fileRead(fileToRead);
        Tokens newTokens = tokenize(viewFromPartial);

        // TODO: can we do better?
        if (splitted.size() > 1) {
                partialSubstitute(splitted, newTokens);
        }

        // Redundant but useful
        CHECK_TOKEN_IS_NOT(TOKEN_START_PARTIAL);

        // TODO: Can we avoid iterators?
        currentToken_ = (currentToken_ - 2);
        Tokens::iterator current = std::next( tokens_.begin(), currentToken_);
        tokens_.erase(current, current + 3);
        tokens_.insert(current, newTokens.begin(), newTokens.end());
    #ifdef DEBUG
        LOG_END("TOKEN AFTER SUBSTITUTION");
        dumpTokens();
    #endif
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rdi, %r14
leaq 0xd0(%rdi), %rbx
movq 0xe8(%rdi), %rsi
decq %rsi
movq %rbx, %rdi
callq 0x25490
movq 0x22a89(%rip), %rsi     # 0x4bef8
movq %rax, %rdi
callq 0x25aa0
movb %al, -0x29(%rbp)
movq 0xd8(%r14), %rax
movq 0xe8(%r14), %rsi
subq 0xd0(%r14), %rax
sarq $0x5, %rax
cmpq %rax, %rsi
je 0x296e8
movq %rbx, %rdi
callq 0x25490
movq %rax, %r13
movq 0x22b2a(%rip), %rdx     # 0x4bfd8
movq %rax, %rsi
callq 0x26ff0
movq 0xd8(%r14), %rax
movq 0xe8(%r14), %rsi
incq %rsi
movq %rsi, 0xe8(%r14)
subq 0xd0(%r14), %rax
sarq $0x5, %rax
cmpq %rax, %rsi
je 0x29708
movq %rbx, %rdi
callq 0x25490
movq 0x2298f(%rip), %rsi     # 0x4be80
movq %rax, %rdi
callq 0x273f0
testb %al, %al
jne 0x29728
leaq -0x68(%rbp), %r12
pushq $0x7c
popq %rcx
movq %r12, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x266d0
xorl %r13d, %r13d
movq -0x60(%rbp), %rax
subq -0x68(%rbp), %rax
sarq $0x5, %rax
cmpq %rax, %r13
jae 0x2955e
movq %r12, %rdi
movq %r13, %rsi
callq 0x25490
movq %r14, %rdi
movq %rax, %rsi
callq 0x26300
movq %rax, %r15
movq %r12, %rdi
movq %r13, %rsi
callq 0x25490
movq %rax, %rdi
movq %r15, %rsi
callq 0x259e0
incq %r13
jmp 0x29519
leaq -0x40(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
cmpb $0x0, -0x29(%rbp)
je 0x295ae
leaq -0x68(%rbp), %rdi
xorl %esi, %esi
callq 0x25490
leaq -0xa0(%rbp), %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x26b80
leaq -0x50(%rbp), %rdi
leaq -0xa0(%rbp), %r15
movq %r15, %rsi
callq 0x26740
movq %r15, %rdi
callq 0x27788
jmp 0x295c5
leaq -0x68(%rbp), %rdi
xorl %esi, %esi
callq 0x25490
leaq -0x50(%rbp), %rdi
movq %rax, %rsi
callq 0x259e0
leaq -0xa0(%rbp), %rdi
leaq -0x50(%rbp), %rdx
movq %r14, %rsi
callq 0x26f70
leaq -0x80(%rbp), %rdi
leaq -0xa0(%rbp), %rdx
movq %r14, %rsi
callq 0x25210
movq -0x60(%rbp), %rax
subq -0x68(%rbp), %rax
cmpq $0x21, %rax
jb 0x29628
leaq -0xb8(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x26bb0
leaq -0xb8(%rbp), %rsi
leaq -0x80(%rbp), %rdx
movq %r14, %rdi
callq 0x25bb0
leaq -0xb8(%rbp), %rdi
callq 0x25d90
movq 0xe8(%r14), %rsi
movq 0xd0(%r14), %rax
movq 0xd8(%r14), %rcx
subq %rax, %rcx
sarq $0x5, %rcx
cmpq %rcx, %rsi
jne 0x29676
movq %rbx, %rdi
callq 0x25490
movq 0x22928(%rip), %rsi     # 0x4bf80
movq %rax, %rdi
callq 0x25aa0
testb %al, %al
jne 0x2974a
movq 0xd0(%r14), %rax
movq 0xe8(%r14), %rsi
addq $-0x2, %rsi
movq %rsi, 0xe8(%r14)
shlq $0x5, %rsi
leaq (%rax,%rsi), %r14
leaq (%rax,%rsi), %rdx
addq $0x60, %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x26bd0
movq -0x80(%rbp), %rdx
movq -0x78(%rbp), %rcx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x264d0
leaq -0x80(%rbp), %rdi
callq 0x25d90
leaq -0xa0(%rbp), %rdi
callq 0x27788
leaq -0x50(%rbp), %rdi
callq 0x27788
leaq -0x68(%rbp), %rdi
callq 0x25d90
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x135ab(%rip), %rsi     # 0x3cc9a
leaq -0x50(%rbp), %rdi
leaq -0xa0(%rbp), %rdx
callq 0x25670
leaq -0x50(%rbp), %rsi
callq 0x26890
leaq 0x1358b(%rip), %rsi     # 0x3cc9a
leaq -0x50(%rbp), %rdi
leaq -0xa0(%rbp), %rdx
callq 0x25670
leaq -0x50(%rbp), %rsi
callq 0x26890
leaq 0x1358f(%rip), %rsi     # 0x3ccbe
movq 0x2274a(%rip), %rdx     # 0x4be80
leaq -0x50(%rbp), %rbx
movq %rbx, %rdi
callq 0x261d0
movq %rbx, %rsi
callq 0x26890
leaq 0x13561(%rip), %rsi     # 0x3ccb2
movq 0x22828(%rip), %rdx     # 0x4bf80
leaq -0xd8(%rbp), %rdi
callq 0x261d0
leaq -0xd8(%rbp), %rsi
callq 0x26890
movq %rax, %rbx
leaq -0xd8(%rbp), %rdi
callq 0x27788
jmp 0x297a6
jmp 0x297a3
movq %rax, %rbx
leaq -0xb8(%rbp), %rdi
callq 0x25d90
jmp 0x297a6
jmp 0x297d4
jmp 0x2979a
jmp 0x297d4
movq %rax, %rbx
jmp 0x297ee
jmp 0x297a3
jmp 0x297a3
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
callq 0x25d90
jmp 0x297b4
movq %rax, %rbx
leaq -0xa0(%rbp), %rdi
callq 0x27788
jmp 0x297c9
jmp 0x297c6
jmp 0x297c6
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x27788
jmp 0x297e5
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x27788
jmp 0x297ee
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x25d90
movq %rbx, %rdi
callq 0x27310