// File: /workspace/github_cpp_makefile_star2_O2/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 %rsi, -0x38(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movq %rdi, -0x30(%rbp)
andq $0x0, 0x10(%rdi)
xorl %r12d, %r12d
leaq -0x58(%rbp), %r13
xorl %ebx, %ebx
movq %r14, %rdi
leaq 0x147f2(%rip), %rsi     # 0x3cc62
movq %r12, %rdx
callq 0x25890
cmpq $-0x1, %rax
je 0x28673
movq %rax, %r15
movq (%r14), %rcx
leaq 0x1(%rax), %r12
movb 0x1(%rcx,%rax), %al
cmpb $0x7b, (%rcx,%r15)
jne 0x28538
cmpb $0x7b, %al
jne 0x28466
movq %r15, %rcx
subq %rbx, %rcx
movq %r13, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x26450
movq -0x30(%rbp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x27540
movq %r13, %rdi
callq 0x27788
movq (%r14), %rax
movzbl 0x2(%rax,%r15), %eax
cmpl $0x21, %eax
je 0x285f3
cmpl $0x7b, %eax
je 0x28637
cmpl $0x2f, %eax
je 0x28626
cmpl $0x30, %eax
je 0x285c0
cmpl $0x3c, %eax
je 0x285e2
cmpl $0x3d, %eax
je 0x28615
cmpl $0x3e, %eax
je 0x28604
cmpl $0x5e, %eax
je 0x285d1
cmpl $0x23, %eax
jne 0x28655
movq %rbx, %rdi
movq 0x23a2a(%rip), %rsi     # 0x4bf58
callq 0x25920
jmp 0x28646
cmpb $0x7d, %al
jne 0x28466
movq %r15, %rcx
subq %rbx, %rcx
movq %r13, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x26450
movq -0x38(%rbp), %rdi
movq %r13, %rsi
movq -0x30(%rbp), %rbx
callq 0x26300
movq %r13, %rdi
movq %rax, %rsi
callq 0x259e0
movq %rbx, %rdi
movq %r13, %rsi
callq 0x25920
movq (%r14), %rax
cmpb $0x7d, 0x2(%rax,%r15)
jne 0x2859a
movq %rbx, %rdi
movq 0x239c1(%rip), %rsi     # 0x4bf50
callq 0x25920
addq $0x3, %r15
jmp 0x285ad
movq %rbx, %rdi
movq 0x238dc(%rip), %rsi     # 0x4be80
callq 0x25920
addq $0x2, %r15
movq %r15, %r12
movq %r13, %rdi
callq 0x27788
movq %r15, %rbx
jmp 0x28466
movq %rbx, %rdi
movq 0x23956(%rip), %rsi     # 0x4bf20
callq 0x25920
jmp 0x28646
movq %rbx, %rdi
movq 0x238cd(%rip), %rsi     # 0x4bea8
callq 0x25920
jmp 0x28646
movq %rbx, %rdi
movq 0x2390c(%rip), %rsi     # 0x4bef8
callq 0x25920
jmp 0x28646
movq %rbx, %rdi
movq 0x23973(%rip), %rsi     # 0x4bf70
callq 0x25920
jmp 0x28646
movq %rbx, %rdi
movq 0x23972(%rip), %rsi     # 0x4bf80
callq 0x25920
jmp 0x28646
movq %rbx, %rdi
movq 0x23989(%rip), %rsi     # 0x4bfa8
callq 0x25920
jmp 0x28646
movq %rbx, %rdi
movq 0x23980(%rip), %rsi     # 0x4bfb0
callq 0x25920
jmp 0x28646
movq %rbx, %rdi
movq 0x238ef(%rip), %rsi     # 0x4bf30
callq 0x25920
addq $0x3, %r15
movq %r15, %r12
movq %r15, %rbx
jmp 0x28466
addq $0x2, %r15
movq %rbx, %rdi
movq 0x23885(%rip), %rsi     # 0x4bee8
callq 0x25920
movq %r15, %r12
movq %r15, %rbx
jmp 0x28466
movq %rbx, %rcx
notq %rcx
leaq -0x58(%rbp), %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x26450
leaq -0x58(%rbp), %rsi
movq -0x30(%rbp), %rbx
movq %rbx, %rdi
callq 0x27540
leaq -0x58(%rbp), %rdi
callq 0x27788
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x286c2
jmp 0x286bd
jmp 0x286bd
jmp 0x286bd
jmp 0x286c2
movq %rax, %rbx
jmp 0x286ce
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x27788
movq -0x30(%rbp), %rdi
callq 0x25d90
movq %rbx, %rdi
callq 0x27310
nop