// File: 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
subq $0xd0, %rsp
movq %rdi, -0xc0(%rbp)
movq %rdi, %rax
movq %rax, -0xb8(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movb $0x0, -0x31(%rbp)
callq 0x6d880
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rdx
leaq 0x39a6f(%rip), %rsi     # 0xa967a
callq 0x688f0
movq %rax, -0x30(%rbp)
cmpq $-0x1, %rax
je 0x70054
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x6afd0
movsbl (%rax), %eax
cmpl $0x7b, %eax
jne 0x6ff31
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rsi
addq $0x1, %rsi
callq 0x6afd0
movsbl (%rax), %eax
cmpl $0x7b, %eax
jne 0x6ff20
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x30(%rbp), %rcx
subq %rdx, %rcx
leaq -0x58(%rbp), %rdi
callq 0x6ac50
jmp 0x6fc6e
movq -0xc0(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x69a60
jmp 0x6fc80
leaq -0x58(%rbp), %rdi
callq 0x6e458
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rsi
addq $0x2, %rsi
callq 0x6afd0
movsbl (%rax), %eax
cmpl $0x23, %eax
jne 0x6fcf3
movq -0xc0(%rbp), %rdi
movq 0x56288(%rip), %rsi     # 0xc5f38
callq 0x68a60
jmp 0x6fcb7
movq -0x30(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x28(%rbp)
jmp 0x6ff16
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x700d4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x6e458
jmp 0x700d4
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rsi
addq $0x2, %rsi
callq 0x6afd0
movsbl (%rax), %eax
cmpl $0x3d, %eax
jne 0x6fd32
movq -0xc0(%rbp), %rdi
movq 0x5628e(%rip), %rsi     # 0xc5fa8
callq 0x68a60
jmp 0x6fd21
movq -0x30(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x28(%rbp)
jmp 0x6ff14
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rsi
addq $0x2, %rsi
callq 0x6afd0
movsbl (%rax), %eax
cmpl $0x5e, %eax
jne 0x6fd71
movq -0xc0(%rbp), %rdi
movq 0x560ff(%rip), %rsi     # 0xc5e58
callq 0x68a60
jmp 0x6fd60
movq -0x30(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x28(%rbp)
jmp 0x6ff12
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rsi
addq $0x2, %rsi
callq 0x6afd0
movsbl (%rax), %eax
cmpl $0x30, %eax
jne 0x6fdb0
movq -0xc0(%rbp), %rdi
movq 0x56160(%rip), %rsi     # 0xc5ef8
callq 0x68a60
jmp 0x6fd9f
movq -0x30(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x28(%rbp)
jmp 0x6ff10
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rsi
addq $0x2, %rsi
callq 0x6afd0
movsbl (%rax), %eax
cmpl $0x2f, %eax
jne 0x6fdef
movq -0xc0(%rbp), %rdi
movq 0x561d9(%rip), %rsi     # 0xc5fb0
callq 0x68a60
jmp 0x6fdde
movq -0x30(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x28(%rbp)
jmp 0x6ff0e
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rsi
addq $0x2, %rsi
callq 0x6afd0
movsbl (%rax), %eax
cmpl $0x3e, %eax
jne 0x6fe2e
movq -0xc0(%rbp), %rdi
movq 0x56152(%rip), %rsi     # 0xc5f68
callq 0x68a60
jmp 0x6fe1d
movq -0x30(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x28(%rbp)
jmp 0x6ff0c
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rsi
addq $0x2, %rsi
callq 0x6afd0
movsbl (%rax), %eax
cmpl $0x3c, %eax
jne 0x6fe6d
movq -0xc0(%rbp), %rdi
movq 0x5605b(%rip), %rsi     # 0xc5eb0
callq 0x68a60
jmp 0x6fe5c
movq -0x30(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x28(%rbp)
jmp 0x6ff0a
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rsi
addq $0x2, %rsi
callq 0x6afd0
movsbl (%rax), %eax
cmpl $0x21, %eax
jne 0x6fea9
movq -0xc0(%rbp), %rdi
movq 0x560c4(%rip), %rsi     # 0xc5f58
callq 0x68a60
jmp 0x6fe9b
movq -0x30(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x28(%rbp)
jmp 0x6ff08
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rsi
addq $0x2, %rsi
callq 0x6afd0
movsbl (%rax), %eax
cmpl $0x7b, %eax
jne 0x6fee5
movq -0xc0(%rbp), %rdi
movq 0x56040(%rip), %rsi     # 0xc5f10
callq 0x68a60
jmp 0x6fed7
movq -0x30(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x28(%rbp)
jmp 0x6ff06
movq -0xc0(%rbp), %rdi
movq 0x55fad(%rip), %rsi     # 0xc5ea0
callq 0x68a60
jmp 0x6fefa
movq -0x30(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x28(%rbp)
jmp 0x6ff08
jmp 0x6ff0a
jmp 0x6ff0c
jmp 0x6ff0e
jmp 0x6ff10
jmp 0x6ff12
jmp 0x6ff14
jmp 0x6ff16
movq -0x28(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x6ff2c
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x7004f
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rsi
addq $0x1, %rsi
callq 0x6afd0
movsbl (%rax), %eax
cmpl $0x7d, %eax
jne 0x70041
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x30(%rbp), %rcx
subq %rdx, %rcx
leaq -0x88(%rbp), %rdi
callq 0x6ac50
jmp 0x6ff6b
movq -0xb0(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x6a7e0
movq %rax, -0xc8(%rbp)
jmp 0x6ff87
movq -0xc8(%rbp), %rsi
leaq -0x88(%rbp), %rdi
callq 0x67190
jmp 0x6ff9c
movq -0xc0(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x68a60
jmp 0x6ffb1
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rsi
addq $0x2, %rsi
callq 0x6afd0
movsbl (%rax), %eax
cmpl $0x7d, %eax
jne 0x7000a
movq -0xc0(%rbp), %rdi
movq 0x55f50(%rip), %rsi     # 0xc5f28
callq 0x68a60
jmp 0x6ffdf
movq -0x30(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x28(%rbp)
jmp 0x7002b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x6e458
jmp 0x700d4
movq -0xc0(%rbp), %rdi
movq 0x55e10(%rip), %rsi     # 0xc5e28
callq 0x68a60
jmp 0x7001f
movq -0x30(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x20(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x6e458
jmp 0x7004d
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x7004f
jmp 0x6fbfc
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x30(%rbp), %rcx
subq %rdx, %rcx
leaq -0xa8(%rbp), %rdi
callq 0x6ac50
jmp 0x70071
movq -0xc0(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x69a60
jmp 0x70086
leaq -0xa8(%rbp), %rdi
callq 0x6e458
movb $0x1, -0x31(%rbp)
testb $0x1, -0x31(%rbp)
jne 0x700c4
jmp 0x700b8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x6e458
jmp 0x700d4
movq -0xc0(%rbp), %rdi
callq 0x69870
movq -0xb8(%rbp), %rax
addq $0xd0, %rsp
popq %rbp
retq
movq -0xc0(%rbp), %rdi
callq 0x69870
movq -0x60(%rbp), %rdi
callq 0x6d7b0
nopl (%rax)