// File: /workspace/github_cpp_makefile_star2_O3/aalto-speech[P]ftk/util/str.hh
// Function: str::split_with_quotes(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, char const*, bool, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>*)
inline void
split_with_quotes(std::string *str, const char *delims, bool group,
                  std::vector<std::string> *fields)
{
    enum { NONE, BACKSLASH, SINGLE, DOUBLE } mode = NONE;
    size_t begin = 0;
    size_t src = 0;
    size_t tgt = 0;

    fields->clear();
    while (src < str->length()) {

        // Find the string before the next delim while processing
        // quotes.
        while (src < str->length()) {

            switch ((*str)[src]) {

            case '\\':
                if (mode == NONE)
                    mode = BACKSLASH;
                else
                    (*str)[tgt++] = '\\';
                break;

            case '\'':
                if (mode == NONE)
                    mode = SINGLE;
                else if (mode == SINGLE)
                    mode = NONE;
                else
                    (*str)[tgt++] = '\'';
                break;

            case '"':
                if (mode == NONE)
                    mode = DOUBLE;
                else if (mode == DOUBLE)
                    mode = NONE;
                else
                    (*str)[tgt++] = '"';
                break;

            default:
                (*str)[tgt++] = (*str)[src];
                if (mode == NONE && strchr(delims, (*str)[src])) {
                    src++;
                    tgt--;
                    goto end_of_field;
                }
                break;
            }
            if (mode == BACKSLASH && (*str)[src] != '\\')
                mode = NONE;
            src++;
        }

end_of_field:
        fields->push_back(str->substr(begin, tgt - begin));
        tgt++;

        // Eat the delim or group of delims
        if (group)
            while (src < str->length() && strchr(delims, (*str)[src]))
                src++;
        begin = tgt;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %edx, -0x2c(%rbp)
movq %rsi, -0x40(%rbp)
movq %rdi, %rbx
movq %rcx, -0x48(%rbp)
movq %rcx, %rdi
callq 0x82a2
movq %rbx, -0x38(%rbp)
movq 0x8(%rbx), %rax
testq %rax, %rax
je 0x8276
xorl %ebx, %ebx
xorl %r15d, %r15d
xorl %r14d, %r14d
cmpq %rax, %r14
movq %r15, -0x50(%rbp)
jae 0x81e5
movq %r15, %r13
movq -0x38(%rbp), %r12
movq (%r12), %rax
movzbl (%rax,%r14), %ecx
cmpl $0x22, %ecx
je 0x8177
cmpl $0x27, %ecx
je 0x8162
cmpl $0x5c, %ecx
jne 0x8184
testl %ebx, %ebx
jne 0x816b
movl $0x1, %ebx
jmp 0x81cf
testl %ebx, %ebx
je 0x81c3
cmpl $0x2, %ebx
je 0x8180
movb %cl, (%rax,%r13)
incq %r13
movq %r13, %r15
jmp 0x8190
testl %ebx, %ebx
je 0x81ca
cmpl $0x3, %ebx
jne 0x816b
xorl %ebx, %ebx
jmp 0x81cf
leaq 0x1(%r13), %r15
movb %cl, (%rax,%r13)
testl %ebx, %ebx
je 0x81a5
cmpl $0x1, %ebx
jne 0x81d2
movq (%r12), %rax
xorl %ebx, %ebx
cmpb $0x5c, (%rax,%r14)
sete %bl
jmp 0x81d2
movq (%r12), %rax
movsbl (%rax,%r14), %esi
movq -0x40(%rbp), %rdi
callq 0x4130
xorl %ebx, %ebx
testq %rax, %rax
je 0x81d2
jmp 0x8269
movl $0x2, %ebx
jmp 0x81cf
movl $0x3, %ebx
movq %r13, %r15
incq %r14
movq %r15, %r13
cmpq 0x8(%r12), %r14
jb 0x813f
jmp 0x81e9
movq -0x38(%rbp), %r12
movq %r15, %rcx
movq -0x50(%rbp), %rdx
subq %rdx, %rcx
leaq -0x70(%rbp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x43b0
movq -0x48(%rbp), %rdi
movq %r13, %rsi
callq 0x82e8
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x8220
callq 0x4350
movq 0x8(%r12), %rax
cmpb $0x0, -0x2c(%rbp)
je 0x825b
cmpq %rax, %r14
jae 0x825b
movq (%r12), %r13
movq %rax, %r12
movsbl (%r13,%r14), %esi
movq -0x40(%rbp), %rdi
callq 0x4130
testq %rax, %rax
je 0x8258
incq %r14
movq %r12, %rax
cmpq %r14, %r12
jne 0x8234
jmp 0x8276
movq %r12, %rax
incq %r15
cmpq %rax, %r14
jb 0x812b
jmp 0x8276
incq %r14
xorl %ebx, %ebx
movq %r13, %r15
jmp 0x81e9
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x829a
callq 0x4350
movq %rbx, %rdi
callq 0x4650