// File: /workspace/github_cpp_makefile_star2_O1/xelia-it[P]mustache/src/mustache-light.cpp
// Function: mustache::Mustache::tokenize(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
Mustache::Tokens Mustache::tokenize(const string& view) {
        std::string::size_type start = 0;
        std::string::size_type prev = 0;
        std::string::size_type pos;
        Tokens tokens;

        while ((pos = view.find_first_of("{}", prev)) != std::string::npos) {
                if (view[pos] == '{') {
                        if (view[pos + 1] == '{') {
                                // Insert into tokens text encountered until "{{"
                                tokens.push_back(view.substr(start, pos - start));
                                if (view[pos + 2] == '#') {
                                        tokens.push_back(TOKEN_START_BEGIN_SECTION);
                                        prev = pos + 3;
                                } else if (view[pos + 2] == '=') {
                                        tokens.push_back(TOKEN_START_IF);
                                        prev = pos + 3;
                                } else if (view[pos + 2] == '^') {
                                        tokens.push_back(TOKEN_START_UNLESS);
                                        prev = pos + 3;
                                } else if (view[pos + 2] == '0') {
                                        tokens.push_back(TOKEN_START_EXISTS_TEST);
                                        prev = pos + 3;
                                } else if (view[pos + 2] == '/') {
                                        tokens.push_back(TOKEN_START_END_SECTION);
                                        prev = pos + 3;
                                } else if (view[pos + 2] == '>') {
                                        tokens.push_back(TOKEN_START_PARTIAL);
                                        prev = pos + 3;
                                } else if (view[pos + 2] == '<') {
                                        tokens.push_back(TOKEN_START_TEMPLATE);
                                        prev = pos + 3;
                                } else if (view[pos + 2] == '!') {
                                        tokens.push_back(TOKEN_START_COMMENT);
                                        prev = pos + 3;
                                } else {
                                        if (view[pos + 2] == '{') {
                                                tokens.push_back(TOKEN_START_VARIABLE_UNESCAPED);
                                                prev = pos + 3;
                                        } else {
                                                tokens.push_back(TOKEN_START_VARIABLE);
                                                prev = pos + 2;
                                        }
                                }
                                start = prev;
                        } else {
                                // Single open {: continue..
                                prev = pos + 1;
                        }
                } else {
                        if (view[pos + 1] == '}') {
                                // Trim string inside parenthesis.
                                // Eg: "{{ some }}" => " some " => "some"
                                string token = view.substr(start, pos - start);
                                token = trim(token);
                                // Now save both token and closed parenthesis "}}"
                                tokens.push_back(token);
                                if (view[pos + 2] == '}') {
                                        tokens.push_back(TOKEN_END_UNESCAPED);
                                        prev = pos + 3;
                                } else {
                                        tokens.push_back(TOKEN_END);
                                        prev = pos + 2;
                                }
                                start = prev;
                        } else {
                                // Single close }: continue..
                                prev = pos + 1;
                        }
                }
        }
        // Save last part of the file (if any) as free text
        tokens.push_back(view.substr(start, pos - start));

        return tokens;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdx, %r14
movq %rdi, %rbx
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
leaq 0x17101(%rip), %rsi     # 0x30c89
xorl %r15d, %r15d
movl $0x2, %ecx
movq %rdx, %rdi
xorl %edx, %edx
callq 0x18120
cmpq $-0x1, %rax
je 0x19e4b
movq %rax, %r12
xorl %r15d, %r15d
movq (%r14), %rcx
leaq 0x1(%r12), %r13
movb 0x1(%rcx,%r12), %al
cmpb $0x7b, (%rcx,%r12)
jne 0x19c49
cmpb $0x7b, %al
jne 0x19e10
movq %r12, %rcx
subq %r15, %rcx
leaq -0x48(%rbp), %r13
movq %r13, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x17bf0
movq %rbx, %rdi
movq %r13, %rsi
callq 0x18610
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x19bff
callq 0x17b00
movq (%r14), %rax
movzbl 0x2(%rax,%r12), %eax
cmpl $0x3b, %eax
jle 0x19cd8
cmpl $0x3d, %eax
jle 0x19d94
cmpl $0x3e, %eax
je 0x19dd5
cmpl $0x5e, %eax
je 0x19df7
cmpl $0x7b, %eax
jne 0x19e36
movq %rbx, %rdi
movq 0x242f1(%rip), %rsi     # 0x3df30
callq 0x174f0
jmp 0x19e06
cmpb $0x7d, %al
jne 0x19e10
movq %r12, %rcx
subq %r15, %rcx
leaq -0x48(%rbp), %r13
movq %r13, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x17bf0
movq -0x48(%rbp), %rax
movq -0x40(%rbp), %rcx
addq %rax, %rcx
movq %rcx, -0x60(%rbp)
movq %rax, -0x58(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0x60(%rbp), %rsi
leaq -0x58(%rbp), %rdx
callq 0x180b0
movq -0x50(%rbp), %rax
movq %rax, %rcx
subq -0x48(%rbp), %rcx
movq %rcx, -0x40(%rbp)
movb $0x0, (%rax)
movq -0x48(%rbp), %r15
movq -0x40(%rbp), %rsi
addq %r15, %rsi
movq %r15, %rdi
callq 0x17650
movq -0x48(%rbp), %rcx
movq %r15, %rsi
subq %rcx, %rsi
movq -0x40(%rbp), %rdx
addq %rcx, %rdx
cmpq %rax, %rdx
je 0x19d07
subq %r15, %rax
movq %r13, %rdi
movq %rax, %rdx
callq 0x17d20
jmp 0x19d0f
cmpl $0x2e, %eax
jg 0x19d75
cmpl $0x21, %eax
je 0x19db3
cmpl $0x23, %eax
jne 0x19e36
movq %rbx, %rdi
movq 0x24263(%rip), %rsi     # 0x3df60
callq 0x174f0
jmp 0x19e06
movq %rsi, -0x40(%rbp)
movb $0x0, (%rcx,%rsi)
movq %r13, %rdi
movq %r13, %rsi
callq 0x17560
movq %rbx, %rdi
movq %r13, %rsi
callq 0x174f0
movq (%r14), %rax
cmpb $0x7d, 0x2(%rax,%r12)
jne 0x19d45
movq %rbx, %rdi
movq 0x2421e(%rip), %rsi     # 0x3df58
callq 0x174f0
addq $0x3, %r12
jmp 0x19d58
movq %rbx, %rdi
movq 0x24129(%rip), %rsi     # 0x3de78
callq 0x174f0
addq $0x2, %r12
movq %r12, %r13
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x19d6d
callq 0x17b00
movq %r13, %r15
jmp 0x19e10
cmpl $0x2f, %eax
je 0x19dc4
cmpl $0x30, %eax
jne 0x19e36
movq %rbx, %rdi
movq 0x24193(%rip), %rsi     # 0x3df20
callq 0x174f0
jmp 0x19e06
cmpl $0x3c, %eax
je 0x19de6
cmpl $0x3d, %eax
jne 0x19e36
movq %rbx, %rdi
movq 0x241fc(%rip), %rsi     # 0x3dfa8
callq 0x174f0
jmp 0x19e06
movq %rbx, %rdi
movq 0x241bb(%rip), %rsi     # 0x3df78
callq 0x174f0
jmp 0x19e06
movq %rbx, %rdi
movq 0x241e2(%rip), %rsi     # 0x3dfb0
callq 0x174f0
jmp 0x19e06
movq %rbx, %rdi
movq 0x241a1(%rip), %rsi     # 0x3df80
callq 0x174f0
jmp 0x19e06
movq %rbx, %rdi
movq 0x24100(%rip), %rsi     # 0x3def0
callq 0x174f0
jmp 0x19e06
movq %rbx, %rdi
movq 0x2409f(%rip), %rsi     # 0x3dea0
callq 0x174f0
addq $0x3, %r12
movq %r12, %r13
movq %r12, %r15
movl $0x2, %ecx
movq %r14, %rdi
leaq 0x16e6a(%rip), %rsi     # 0x30c89
movq %r13, %rdx
callq 0x18120
movq %rax, %r12
cmpq $-0x1, %rax
jne 0x19baa
jmp 0x19e4b
movq %rbx, %rdi
movq 0x240a0(%rip), %rsi     # 0x3dee0
callq 0x174f0
addq $0x2, %r12
jmp 0x19e0a
movq %r15, %rcx
notq %rcx
leaq -0x48(%rbp), %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x17bf0
leaq -0x48(%rbp), %rsi
movq %rbx, %rdi
callq 0x18610
leaq -0x38(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x19e7e
callq 0x17b00
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
leaq -0x38(%rbp), %rax
movq -0x10(%rax), %rdi
jmp 0x19eb5
jmp 0x19ea5
jmp 0x19ea5
jmp 0x19ea5
jmp 0x19eaa
movq %rax, %r14
jmp 0x19ebf
movq %rax, %r14
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x19ebf
callq 0x17b00
movq %rbx, %rdi
callq 0x177a0
movq %r14, %rdi
callq 0x184b0
nop