// File: /workspace/github_cpp_makefile_star2_O3/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 $0x98, %rsp
movq 0xe8(%rdi), %r15
leaq -0x1(%r15), %rsi
movq 0xd0(%rdi), %rbx
movq 0xd8(%rdi), %r14
subq %rbx, %r14
sarq $0x5, %r14
cmpq %rsi, %r14
jbe 0x1b697
movq %rdi, %r12
shlq $0x5, %rsi
movq 0x8(%rbx,%rsi), %rdx
movq 0x21bf0(%rip), %rax     # 0x3cef0
cmpq 0x8(%rax), %rdx
jne 0x1b324
testq %rdx, %rdx
je 0x1b329
addq %rbx, %rsi
movq (%rax), %rax
movq (%rsi), %rdi
movq %rax, %rsi
callq 0x17bc0
testl %eax, %eax
sete %r13b
jmp 0x1b32c
xorl %r13d, %r13d
jmp 0x1b32c
movb $0x1, %r13b
cmpq %r14, %r15
je 0x1b6a0
jae 0x1b6c8
shlq $0x5, %r15
addq %r15, %rbx
movq 0x21c8f(%rip), %rdx     # 0x3cfd8
movq %rbx, %rsi
callq 0x18280
movq 0xe8(%r12), %rsi
incq %rsi
movq %rsi, 0xe8(%r12)
movq 0xd0(%r12), %rax
movq 0xd8(%r12), %rdx
subq %rax, %rdx
sarq $0x5, %rdx
cmpq %rdx, %rsi
je 0x1b6d7
jae 0x1b6ff
shlq $0x5, %rsi
movq 0x8(%rax,%rsi), %rdx
movq 0x21ade(%rip), %rcx     # 0x3ce78
cmpq 0x8(%rcx), %rdx
jne 0x1b675
testq %rdx, %rdx
je 0x1b3bf
addq %rsi, %rax
movq (%rcx), %rsi
movq (%rax), %rdi
callq 0x17bc0
testl %eax, %eax
jne 0x1b675
movl %r13d, -0x4c(%rbp)
leaq -0x68(%rbp), %r15
movq %r15, %rdi
movq %r12, -0x70(%rbp)
movq %r12, %rsi
movq %rbx, %rdx
movl $0x7c, %ecx
callq 0x17d10
movq (%r15), %r14
movq 0x8(%r15), %rax
movq %rax, %rdx
subq %r14, %rdx
je 0x1b4c5
xorl %r13d, %r13d
leaq -0xa8(%rbp), %rbx
xorl %r15d, %r15d
movq (%r14,%r13), %rax
movq 0x8(%r14,%r13), %rcx
addq %rax, %rcx
movq %rcx, -0x48(%rbp)
movq %rax, -0xa8(%rbp)
leaq -0x88(%rbp), %rdi
leaq -0x48(%rbp), %rsi
movq %rbx, %rdx
callq 0x18090
addq %r13, %r14
movq -0x88(%rbp), %rax
movq %rax, %rcx
subq (%r14), %rcx
movq %rcx, 0x8(%r14)
movb $0x0, (%rax)
movq (%r14), %r12
movq 0x8(%r14), %rsi
addq %r12, %rsi
movq %r12, %rdi
callq 0x17640
movq (%r14), %rcx
movq %r12, %rsi
subq %rcx, %rsi
movq 0x8(%r14), %rdx
addq %rcx, %rdx
cmpq %rax, %rdx
je 0x1b476
subq %r12, %rax
movq %r14, %rdi
movq %rax, %rdx
callq 0x17d00
jmp 0x1b47e
movq %rsi, 0x8(%r14)
movb $0x0, (%rcx,%rsi)
movq -0x68(%rbp), %rdi
movq -0x60(%rbp), %rdx
subq %rdi, %rdx
sarq $0x5, %rdx
cmpq %r15, %rdx
jbe 0x1b664
addq %r13, %rdi
movq %r14, %rsi
callq 0x17550
incq %r15
movq -0x68(%rbp), %r14
movq -0x60(%rbp), %rax
movq %rax, %rdx
subq %r14, %rdx
sarq $0x5, %rdx
addq $0x20, %r13
cmpq %rdx, %r15
jb 0x1b3fe
jmp 0x1b4c9
sarq $0x5, %rdx
leaq -0x38(%rbp), %r15
movq %r15, -0x10(%r15)
movq $0x0, -0x8(%r15)
movb $0x0, (%r15)
cmpb $0x0, -0x4c(%rbp)
je 0x1b52b
cmpq %r14, %rax
movq -0x70(%rbp), %r12
je 0x1b71e
leaq -0xa8(%rbp), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x17fd0
leaq -0x48(%rbp), %rdi
leaq -0xa8(%rbp), %rbx
movq %rbx, %rsi
callq 0x17d60
movq (%rbx), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0x1b544
callq 0x17ae0
jmp 0x1b544
cmpq %r14, %rax
movq -0x70(%rbp), %r12
je 0x1b72e
leaq -0x48(%rbp), %rdi
movq %r14, %rsi
callq 0x17550
leaq 0x20(%r12), %rcx
leaq -0xa8(%rbp), %rdi
leaq -0x48(%rbp), %rdx
movq %r12, %rsi
callq 0x17cb0
leaq -0x88(%rbp), %rdi
leaq -0xa8(%rbp), %rdx
callq 0x17150
movq -0x60(%rbp), %rax
subq -0x68(%rbp), %rax
cmpq $0x21, %rax
jb 0x1b5af
leaq -0xc0(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x17ff0
leaq -0xc0(%rbp), %rsi
leaq -0x88(%rbp), %rdx
movq %r12, %rdi
callq 0x17680
leaq -0xc0(%rbp), %rdi
callq 0x17790
movq 0xe8(%r12), %rdx
movq 0xd0(%r12), %rax
movq 0xd8(%r12), %rcx
subq %rax, %rcx
sarq $0x5, %rcx
cmpq %rcx, %rdx
je 0x1b70d
addq $-0x2, %rdx
movq %rdx, 0xe8(%r12)
addq $0xd0, %r12
shlq $0x5, %rdx
leaq (%rax,%rdx), %rbx
addq %rax, %rdx
addq $0x60, %rdx
movq %r12, %rdi
movq %rbx, %rsi
callq 0x17850
movq -0x88(%rbp), %rdx
movq -0x80(%rbp), %rcx
movq %r12, %rdi
movq %rbx, %rsi
callq 0x17130
leaq -0x88(%rbp), %rdi
callq 0x17790
leaq -0x98(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1b63b
callq 0x17ae0
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
je 0x1b649
callq 0x17ae0
leaq -0x68(%rbp), %rdi
callq 0x17790
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x18069(%rip), %rdi     # 0x336d4
movq %r15, %rsi
xorl %eax, %eax
callq 0x180f0
leaq 0x14651(%rip), %rsi     # 0x2fccd
movq 0x217f5(%rip), %rdx     # 0x3ce78
leaq -0x48(%rbp), %rbx
movq %rbx, %rdi
callq 0x17a50
movq %rbx, %rsi
callq 0x17e50
leaq 0x18036(%rip), %rdi     # 0x336d4
jmp 0x1b6d2
leaq -0x38(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x14606(%rip), %rsi     # 0x2fcb5
leaq 0x14616(%rip), %rdx     # 0x2fccc
leaq -0x48(%rbp), %rdi
callq 0x173a0
leaq -0x48(%rbp), %rsi
callq 0x17e50
leaq 0x18005(%rip), %rdi     # 0x336d4
movq %r15, %rsi
movq %r14, %rdx
jmp 0x1b706
leaq -0x38(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x145cf(%rip), %rsi     # 0x2fcb5
leaq 0x145df(%rip), %rdx     # 0x2fccc
leaq -0x48(%rbp), %rdi
callq 0x173a0
leaq -0x48(%rbp), %rsi
callq 0x17e50
leaq 0x17fce(%rip), %rdi     # 0x336d4
xorl %eax, %eax
callq 0x180f0
leaq 0x17fc0(%rip), %rdi     # 0x336d4
movq %rdx, %rsi
xorl %eax, %eax
callq 0x180f0
leaq 0x17faf(%rip), %rdi     # 0x336d4
xorl %esi, %esi
xorl %eax, %eax
callq 0x180f0
leaq 0x17f9f(%rip), %rdi     # 0x336d4
xorl %esi, %esi
xorl %eax, %eax
callq 0x180f0
movq %rax, %rbx
leaq -0xc0(%rbp), %rdi
callq 0x17790
jmp 0x1b77b
jmp 0x1b753
jmp 0x1b761
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r14, %rdi
jne 0x1b7bc
jmp 0x1b7d1
movq %rax, %rbx
jmp 0x1b7d1
jmp 0x1b778
jmp 0x1b778
movq %rax, %rbx
jmp 0x1b787
jmp 0x1b773
jmp 0x1b773
movq %rax, %rbx
jmp 0x1b79c
movq %rax, %rbx
leaq -0x88(%rbp), %rdi
callq 0x17790
leaq -0x98(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1b79c
callq 0x17ae0
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
je 0x1b7c8
callq 0x17ae0
jmp 0x1b7c8
movq %rax, %rbx
leaq -0x38(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1b7d1
callq 0x17ae0
jmp 0x1b7d1
jmp 0x1b7c5
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x17790
movq %rbx, %rdi
callq 0x18490
nop