// File: /workspace/github_cpp_makefile_star2_O2/xelia-it[P]mustache/src/mustache-light.cpp
// Function: mustache::Mustache::produceSection()
void Mustache::produceSection() {
        bool useSection = (tokens_.at(currentToken_ - 1) == TOKEN_START_BEGIN_SECTION);
        bool useUnless = (tokens_.at(currentToken_ - 1) == TOKEN_START_UNLESS);
        bool useExistsTest = (tokens_.at(currentToken_ - 1) == TOKEN_START_EXISTS_TEST);

        LOG_START("");
        LOG_END("SECTION := ");
#ifdef DEBUG
        if (useSection) {
                LOG_START(TOKEN_START_BEGIN_SECTION);
        } else if (useUnless) {
                LOG_START(TOKEN_START_UNLESS);
        } else if (useExistsTest) {
                LOG_START(TOKEN_START_EXISTS_TEST);
        } else {
                LOG_START(TOKEN_START_IF);
        }
#endif

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

        // Save var name
        string variableName = tokens_.at(currentToken_);
        ensureValidIdentifier(variableName);
        LOG(" ");
        LOG(variableName);

        json variable;
        bool variable_exists;
        try {
            variable = searchVariableInContext(variableName);
            variable_exists = true;
        } catch(const std::out_of_range& ex) {
            variable = nullptr;
            variable_exists = false;
        } catch(const std::invalid_argument& ex) {
            variable = nullptr;
            variable_exists = false;
        }

        // Is variable malformed
        bool isCorrectType = variable.is_null() || variable.is_boolean() ||
                             variable.is_string() || variable.is_array() ||
                             variable.is_object() || variable.is_number();
        if (!isCorrectType) {
                error("Variable '" + variableName + "' is malformed");
                return;
        }

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

        CONSUME_TOKEN();
        // The logic of section block {{# }}
        // - [ a, b, c, .. ] ==> cycle
        // - [], {}, "", false, null ==> hide
        // - { something }, "something", true ==> view
        // Section always changes context. EG:
        //
        // context = {
        //   "var1": { "one": 1, "two": 2 },
        //   "var2": "value2"
        // }
        //
        // template =  {{# var1 }}{{ one }}{{/ var1 }}
        //
        // output = 1
        //
        if (useSection && variable.is_array() && variable.size() > 0) {
                const TokenIndex savedPosition = currentToken_;
                for (json::iterator it = variable.begin(); it != variable.end(); ++it) {
                        LOG_END(variable);
                        currentToken_ = savedPosition;
                        currentListCounter_ = std::distance(variable.begin(), it);
                        stack_.push(*it);
                        produceMessage();
                        stack_.pop();
                }
                // Reset to 0 after the main cycle
                currentListCounter_ = 0;
        } else {
                // The hide variable is used for {{= }} and {{# }} logic
                bool hide =
                        (variable.is_array() && variable.size() == 0) ||
                        (variable.is_object() && variable.size() == 0) ||
                        (variable.is_string() && variable.get<string>().size() == 0) ||
                        (variable.is_boolean() && !variable.get<bool>()) ||
                        (variable.is_number() && variable.get<int>() == 0) ||
                        (variable.is_null());

                if (useExistsTest) {
                        // The exist test {{0 }} uses a different logic:
                        // If the key do not exists the section is not shown.
                        hide = !variable_exists;
                } else if (useUnless) {
                        // The inverted section {{^ }} uses inverted logic
                        hide = !hide;
                }
                bool oldVisible = visible_;

                // Should the next message be visible?
                visible_ = visible_ && !hide;

                // The only difference from {{# }} and {{= }} {{^ }} {{? }}
                // is the fact that tag {{# }} changes context.
                if (useSection) {
                        stack_.push(variable);
                }
                produceMessage();
                if (useSection) {
                        stack_.pop();
                }

                // Retrieve the old visibility state
                visible_ = oldVisible;
        }

        CHECK_TOKEN_IS(TOKEN_START_END_SECTION);
        LOG(" ");
        LOG(TOKEN_START_END_SECTION);

        CONSUME_TOKEN();
        CHECK_TOKEN_NOT_EMPTY();
        const string& variableNameEnd = tokens_.at(currentToken_);
        LOG(" ");
        LOG(variableNameEnd);
        ensureValidIdentifier(variableName);
        if (variableNameEnd != variableName) {
                error("Expected '" + variableName + "' in closing block (found '" +
                      variableNameEnd + "')");
                return;
        }

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x158, %rsp            # imm = 0x158
movq %rdi, %r14
leaq 0xd0(%rdi), %r13
movq 0xe8(%rdi), %rsi
decq %rsi
movq %r13, %rdi
callq 0x25490
movq 0x232a7(%rip), %rsi     # 0x4bf58
movq %rax, %rdi
callq 0x25aa0
movl %eax, %r15d
movq 0xe8(%r14), %rsi
decq %rsi
movq %r13, %rdi
callq 0x25490
movq 0x231d3(%rip), %rsi     # 0x4bea8
movq %rax, %rdi
callq 0x25aa0
movl %eax, %r12d
movq 0xe8(%r14), %rsi
decq %rsi
movq %r13, %rdi
callq 0x25490
movq 0x23227(%rip), %rsi     # 0x4bf20
movq %rax, %rdi
callq 0x25aa0
movb %al, -0x68(%rbp)
movq 0xd8(%r14), %rax
movq 0xe8(%r14), %rsi
subq 0xd0(%r14), %rax
sarq $0x5, %rax
cmpq %rax, %rsi
je 0x29159
movq %r13, %rdi
callq 0x25490
leaq -0xb0(%rbp), %rbx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x26a70
movq 0x231a9(%rip), %rdx     # 0x4bef0
movq %rbx, %rsi
callq 0x26ff0
leaq -0x40(%rbp), %rdi
xorl %esi, %esi
callq 0x26800
leaq -0xe0(%rbp), %rdi
leaq -0xb0(%rbp), %rdx
movq %r14, %rsi
callq 0x264e0
leaq -0x40(%rbp), %rdi
leaq -0xe0(%rbp), %rbx
movq %rbx, %rsi
callq 0x259c0
movq %rbx, %rdi
callq 0x26730
xorl %ebx, %ebx
cmpb $0x8, -0x40(%rbp)
jae 0x2917f
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 0x291b9
movq %r13, %rdi
callq 0x25490
movq %r13, -0x90(%rbp)
movq 0x230a7(%rip), %rsi     # 0x4be80
movq %rax, %rdi
callq 0x273f0
testb %al, %al
jne 0x291dc
incq 0xe8(%r14)
testb %r15b, %r15b
je 0x28eea
movb -0x40(%rbp), %r13b
cmpb $0x2, %r13b
jne 0x28f0a
leaq -0x40(%rbp), %rdi
callq 0x26da0
testq %rax, %rax
je 0x28eea
movq 0xe8(%r14), %rax
movq %rax, -0x68(%rbp)
leaq -0x88(%rbp), %r15
leaq -0x40(%rbp), %rsi
movq %r15, %rdi
callq 0x25e30
leaq 0xf8(%r14), %r13
leaq -0x60(%rbp), %rbx
leaq -0x180(%rbp), %r12
movq %rbx, %rdi
leaq -0x40(%rbp), %rsi
callq 0x25970
movq %r15, %rdi
movq %rbx, %rsi
callq 0x25730
testb %al, %al
je 0x28f90
movq -0x68(%rbp), %rax
movq %rax, 0xe8(%r14)
movq %r12, %rdi
leaq -0x40(%rbp), %rsi
callq 0x25e30
movq -0x88(%rbp), %rax
movq %rax, -0x140(%rbp)
movq 0x18(%r15), %rax
leaq -0x138(%rbp), %rcx
movq %rax, 0x10(%rcx)
movups 0x8(%r15), %xmm0
movups %xmm0, (%rcx)
movq %r12, %rdi
leaq -0x140(%rbp), %rsi
callq 0x272f0
movq %rax, 0xf0(%r14)
movq %r15, %rdi
callq 0x26170
movq %r13, %rdi
movq %rax, %rsi
callq 0x26b20
movq %r14, %rdi
callq 0x259f0
movq %r13, %rdi
callq 0x26a60
movq %r15, %rdi
callq 0x27280
jmp 0x28e49
movb -0x40(%rbp), %r13b
cmpb $0x2, %r13b
jne 0x28f0a
leaq -0x40(%rbp), %rdi
callq 0x26da0
testq %rax, %rax
je 0x28fb7
movb -0x40(%rbp), %r13b
cmpb $0x1, %r13b
movb %r15b, -0x29(%rbp)
jne 0x28f2a
leaq -0x40(%rbp), %rdi
callq 0x26da0
testq %rax, %rax
je 0x28fbb
movb -0x40(%rbp), %r13b
movl %r13d, %eax
cmpb $0x3, %r13b
jne 0x28f4d
leaq -0x88(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x27210
cmpq $0x0, -0x80(%rbp)
je 0x28fa4
movb -0x40(%rbp), %al
cmpb $0x4, %al
jne 0x28f61
leaq -0x40(%rbp), %rdi
callq 0x25530
testb %al, %al
je 0x28f83
movb -0x40(%rbp), %al
leal -0x5(%rax), %ecx
cmpb $0x2, %cl
ja 0x28f79
leaq -0x40(%rbp), %rdi
callq 0x26060
testl %eax, %eax
je 0x28f83
movb -0x40(%rbp), %al
movl %ebx, %r15d
testb %al, %al
sete %bl
jmp 0x28f88
movl %ebx, %r15d
movb $0x1, %bl
cmpb $0x3, %r13b
je 0x28fa9
jmp 0x28fc0
andq $0x0, 0xf0(%r14)
movq -0x90(%rbp), %r12
jmp 0x29025
movl %ebx, %r15d
movb $0x1, %bl
leaq -0x88(%rbp), %rdi
callq 0x27788
jmp 0x28fc0
movb %r15b, -0x29(%rbp)
movl %ebx, %r15d
movb $0x1, %bl
xorb %bl, %r12b
movzbl %r12b, %eax
movzbl %r15b, %ecx
cmpb $0x0, -0x68(%rbp)
cmovel %eax, %ecx
movb 0x148(%r14), %bl
xorb $0x1, %cl
andb %bl, %cl
movb %cl, 0x148(%r14)
movb -0x29(%rbp), %r15b
testb %r15b, %r15b
movq -0x90(%rbp), %r12
je 0x29005
leaq 0xf8(%r14), %rdi
leaq -0x40(%rbp), %rsi
callq 0x26b20
movq %r14, %rdi
callq 0x259f0
testb %r15b, %r15b
je 0x2901e
leaq 0xf8(%r14), %rdi
callq 0x26a60
movb %bl, 0x148(%r14)
movq 0xd8(%r14), %rax
movq 0xe8(%r14), %rsi
subq 0xd0(%r14), %rax
sarq $0x5, %rax
cmpq %rax, %rsi
je 0x29139
movq %r12, %rdi
callq 0x25490
movq 0x22f5a(%rip), %rsi     # 0x4bfb0
movq %rax, %rdi
callq 0x273f0
testb %al, %al
jne 0x29139
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 0x29202
movq %r12, %rdi
callq 0x25490
movq %rax, %rbx
movq 0x22e4c(%rip), %rdx     # 0x4bef0
leaq -0xb0(%rbp), %rsi
callq 0x26ff0
leaq -0xb0(%rbp), %rsi
movq %rbx, %rdi
callq 0x273f0
testb %al, %al
jne 0x29222
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 0x2928c
movq %r12, %rdi
callq 0x25490
movq 0x22d7e(%rip), %rsi     # 0x4be80
movq %rax, %rdi
callq 0x273f0
testb %al, %al
jne 0x292ac
leaq -0x40(%rbp), %rdi
callq 0x26730
leaq -0xb0(%rbp), %rdi
callq 0x27788
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x13b7e(%rip), %rsi     # 0x3ccbe
movq 0x22e69(%rip), %rdx     # 0x4bfb0
leaq -0x60(%rbp), %rdi
callq 0x261d0
leaq -0x60(%rbp), %rsi
callq 0x26890
leaq 0x13b3a(%rip), %rsi     # 0x3cc9a
leaq -0xb0(%rbp), %rdi
leaq -0x88(%rbp), %rdx
callq 0x25670
leaq -0xb0(%rbp), %rsi
callq 0x26890
leaq 0x13b46(%rip), %rsi     # 0x3cccc
leaq -0x60(%rbp), %rdi
leaq -0xb0(%rbp), %rdx
callq 0x261d0
leaq 0x13b3a(%rip), %rdx     # 0x3ccd7
leaq -0x88(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x25300
leaq -0x88(%rbp), %rsi
callq 0x26890
leaq 0x13ada(%rip), %rsi     # 0x3cc9a
leaq -0x88(%rbp), %rdi
leaq -0x60(%rbp), %rdx
callq 0x25670
leaq -0x88(%rbp), %rsi
callq 0x26890
leaq 0x13adb(%rip), %rsi     # 0x3ccbe
movq 0x22c96(%rip), %rdx     # 0x4be80
leaq -0x88(%rbp), %rdi
callq 0x261d0
leaq -0x88(%rbp), %rsi
callq 0x26890
leaq 0x13a91(%rip), %rsi     # 0x3cc9a
leaq -0x60(%rbp), %rdi
leaq -0xd0(%rbp), %rdx
callq 0x25670
leaq -0x60(%rbp), %rsi
callq 0x26890
leaq 0x13abd(%rip), %rsi     # 0x3cce6
leaq -0x100(%rbp), %rdi
leaq -0xb0(%rbp), %rdx
callq 0x261d0
leaq 0x13aae(%rip), %rdx     # 0x3ccf1
leaq -0x120(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x25300
leaq -0xd0(%rbp), %rdi
leaq -0x120(%rbp), %rsi
movq %rbx, %rdx
callq 0x26d40
leaq 0x13a9a(%rip), %rdx     # 0x3cd0d
leaq -0x60(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x25300
leaq -0x60(%rbp), %rsi
callq 0x26890
leaq 0x13a07(%rip), %rsi     # 0x3cc9a
leaq -0x60(%rbp), %rdi
leaq -0xd0(%rbp), %rdx
callq 0x25670
leaq -0x60(%rbp), %rsi
callq 0x26890
leaq 0x13a0b(%rip), %rsi     # 0x3ccbe
movq 0x22bc6(%rip), %rdx     # 0x4be80
leaq -0x60(%rbp), %rdi
callq 0x261d0
leaq -0x60(%rbp), %rsi
callq 0x26890
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x27788
jmp 0x292dd
movq %rax, %rbx
leaq -0xd0(%rbp), %rdi
callq 0x27788
jmp 0x292ee
movq %rax, %rbx
leaq -0x120(%rbp), %rdi
callq 0x27788
jmp 0x292ff
movq %rax, %rbx
leaq -0x100(%rbp), %rdi
jmp 0x29379
movq %rax, %rbx
leaq -0x88(%rbp), %rdi
callq 0x27788
jmp 0x29375
jmp 0x29372
jmp 0x29418
movq %rax, %rbx
cmpb $0x3, %r13b
je 0x29352
jmp 0x2941b
jmp 0x29372
jmp 0x29418
jmp 0x29372
jmp 0x29418
jmp 0x29418
jmp 0x29372
jmp 0x29418
jmp 0x2934f
jmp 0x29418
movq %rax, %rbx
leaq -0x88(%rbp), %rdi
jmp 0x29379
jmp 0x29418
jmp 0x29418
jmp 0x2940b
movq %rax, %rbx
jmp 0x29430
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x27788
jmp 0x2941b
jmp 0x29418
movq %rax, %rbx
cmpl $0x2, %edx
jne 0x293c9
movq %rbx, %rdi
callq 0x25700
leaq -0x150(%rbp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x26800
leaq -0x40(%rbp), %rdi
movq %rbx, %rsi
callq 0x259c0
movq %rbx, %rdi
callq 0x26730
movb $0x1, %bl
callq 0x270b0
jmp 0x28d8d
cmpl $0x1, %edx
jne 0x2941b
movq %rbx, %rdi
callq 0x25700
leaq -0x160(%rbp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x26800
leaq -0x40(%rbp), %rdi
movq %rbx, %rsi
callq 0x259c0
movq %rbx, %rdi
callq 0x26730
movb $0x1, %bl
callq 0x270b0
jmp 0x28d8d
jmp 0x29418
jmp 0x29418
movq %rax, %rbx
jmp 0x29424
jmp 0x29418
jmp 0x29418
jmp 0x29418
jmp 0x29418
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
callq 0x26730
leaq -0xb0(%rbp), %rdi
callq 0x27788
movq %rbx, %rdi
callq 0x27310