// File: /workspace/github_cpp_makefile_star2_O1/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 0x1b5ae
movq %rdi, %r12
shlq $0x5, %rsi
movq 0x8(%rbx,%rsi), %rdx
movq 0x22cda(%rip), %rax     # 0x3def0
cmpq 0x8(%rax), %rdx
jne 0x1b23a
testq %rdx, %rdx
je 0x1b23f
addq %rbx, %rsi
movq (%rax), %rax
movq (%rsi), %rdi
movq %rax, %rsi
callq 0x17be0
testl %eax, %eax
sete %r13b
jmp 0x1b242
xorl %r13d, %r13d
jmp 0x1b242
movb $0x1, %r13b
cmpq %r14, %r15
je 0x1b5b7
jae 0x1b5df
shlq $0x5, %r15
addq %r15, %rbx
movq 0x22d79(%rip), %rdx     # 0x3dfd8
movq %rbx, %rsi
callq 0x182a0
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 0x1b5ee
jae 0x1b616
shlq $0x5, %rsi
movq 0x8(%rax,%rsi), %rdx
movq 0x22bc8(%rip), %rcx     # 0x3de78
cmpq 0x8(%rcx), %rdx
jne 0x1b58c
testq %rdx, %rdx
je 0x1b2d5
addq %rsi, %rax
movq (%rcx), %rsi
movq (%rax), %rdi
callq 0x17be0
testl %eax, %eax
jne 0x1b58c
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 0x17d30
movq (%r15), %r14
movq 0x8(%r15), %rax
movq %rax, %rdx
subq %r14, %rdx
je 0x1b3db
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 0x180b0
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 0x17650
movq (%r14), %rcx
movq %r12, %rsi
subq %rcx, %rsi
movq 0x8(%r14), %rdx
addq %rcx, %rdx
cmpq %rax, %rdx
je 0x1b38c
subq %r12, %rax
movq %r14, %rdi
movq %rax, %rdx
callq 0x17d20
jmp 0x1b394
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 0x1b57b
addq %r13, %rdi
movq %r14, %rsi
callq 0x17560
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 0x1b314
jmp 0x1b3df
sarq $0x5, %rdx
leaq -0x38(%rbp), %r15
movq %r15, -0x10(%r15)
movq $0x0, -0x8(%r15)
movb $0x0, (%r15)
cmpb $0x0, -0x4c(%rbp)
je 0x1b441
cmpq %r14, %rax
movq -0x70(%rbp), %r12
je 0x1b632
leaq -0xa8(%rbp), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x17ff0
leaq -0x48(%rbp), %rdi
leaq -0xa8(%rbp), %rbx
movq %rbx, %rsi
callq 0x17d80
movq (%rbx), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0x1b45a
callq 0x17b00
jmp 0x1b45a
cmpq %r14, %rax
movq -0x70(%rbp), %r12
je 0x1b642
leaq -0x48(%rbp), %rdi
movq %r14, %rsi
callq 0x17560
leaq 0x20(%r12), %rcx
leaq -0xa8(%rbp), %rdi
leaq -0x48(%rbp), %rdx
movq %r12, %rsi
callq 0x17cd0
leaq -0x88(%rbp), %rdi
leaq -0xa8(%rbp), %rdx
callq 0x17150
movq -0x60(%rbp), %rax
subq -0x68(%rbp), %rax
cmpq $0x21, %rax
jb 0x1b4c5
leaq -0xc0(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x18010
leaq -0xc0(%rbp), %rsi
leaq -0x88(%rbp), %rdx
movq %r12, %rdi
callq 0x17690
leaq -0xc0(%rbp), %rdi
callq 0x177a0
movq 0xe8(%r12), %rsi
movq 0xd0(%r12), %rax
movq 0xd8(%r12), %rdx
subq %rax, %rdx
sarq $0x5, %rdx
cmpq %rdx, %rsi
je 0x1b624
addq $-0x2, %rsi
movq %rsi, 0xe8(%r12)
addq $0xd0, %r12
shlq $0x5, %rsi
leaq (%rax,%rsi), %rbx
leaq (%rax,%rsi), %rdx
addq $0x60, %rdx
movq %r12, %rdi
movq %rbx, %rsi
callq 0x17870
movq -0x88(%rbp), %rdx
movq -0x80(%rbp), %rcx
movq %r12, %rdi
movq %rbx, %rsi
callq 0x17130
leaq -0x88(%rbp), %rdi
callq 0x177a0
leaq -0x98(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1b552
callq 0x17b00
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
je 0x1b560
callq 0x17b00
leaq -0x68(%rbp), %rdi
callq 0x177a0
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1915e(%rip), %rdi     # 0x346e0
movq %r15, %rsi
xorl %eax, %eax
callq 0x18110
leaq 0x15746(%rip), %rsi     # 0x30cd9
movq 0x228de(%rip), %rdx     # 0x3de78
leaq -0x48(%rbp), %rbx
movq %rbx, %rdi
callq 0x17a70
movq %rbx, %rsi
callq 0x17e70
leaq 0x1912b(%rip), %rdi     # 0x346e0
jmp 0x1b5e9
leaq -0x38(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x156fb(%rip), %rsi     # 0x30cc1
leaq 0x1570b(%rip), %rdx     # 0x30cd8
leaq -0x48(%rbp), %rdi
callq 0x173a0
leaq -0x48(%rbp), %rsi
callq 0x17e70
leaq 0x190fa(%rip), %rdi     # 0x346e0
movq %r15, %rsi
movq %r14, %rdx
jmp 0x1b61d
leaq -0x38(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x156c4(%rip), %rsi     # 0x30cc1
leaq 0x156d4(%rip), %rdx     # 0x30cd8
leaq -0x48(%rbp), %rdi
callq 0x173a0
leaq -0x48(%rbp), %rsi
callq 0x17e70
leaq 0x190c3(%rip), %rdi     # 0x346e0
xorl %eax, %eax
callq 0x18110
leaq 0x190b5(%rip), %rdi     # 0x346e0
xorl %eax, %eax
callq 0x18110
leaq 0x190a7(%rip), %rdi     # 0x346e0
xorl %esi, %esi
xorl %eax, %eax
callq 0x18110
leaq 0x19097(%rip), %rdi     # 0x346e0
xorl %esi, %esi
xorl %eax, %eax
callq 0x18110
movq %rax, %rbx
leaq -0xc0(%rbp), %rdi
callq 0x177a0
jmp 0x1b68f
jmp 0x1b667
jmp 0x1b675
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r14, %rdi
jne 0x1b6d0
jmp 0x1b6e5
movq %rax, %rbx
jmp 0x1b6e5
jmp 0x1b68c
jmp 0x1b68c
movq %rax, %rbx
jmp 0x1b69b
jmp 0x1b687
jmp 0x1b687
movq %rax, %rbx
jmp 0x1b6b0
movq %rax, %rbx
leaq -0x88(%rbp), %rdi
callq 0x177a0
leaq -0x98(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1b6b0
callq 0x17b00
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
je 0x1b6dc
callq 0x17b00
jmp 0x1b6dc
movq %rax, %rbx
leaq -0x38(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1b6e5
callq 0x17b00
jmp 0x1b6e5
jmp 0x1b6d9
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x177a0
movq %rbx, %rdi
callq 0x184b0
nop