// File: /workspace/github_cpp_makefile_star2_O2/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, -0x38(%rbp)
movq %rdi, %r12
movq %rcx, -0x40(%rbp)
movq %rcx, %rdi
callq 0x7532
xorl %ebx, %ebx
xorl %ecx, %ecx
xorl %r13d, %r13d
movq 0x8(%r12), %rax
cmpq %rax, %rbx
jae 0x74d1
movq %rcx, -0x48(%rbp)
movq %rcx, %r15
leaq -0x68(%rbp), %rsi
cmpq %rax, %rbx
jae 0x745e
movq (%r12), %rax
movzbl (%rax,%rbx), %ecx
cmpl $0x22, %ecx
je 0x73e0
cmpl $0x27, %ecx
je 0x73cd
cmpl $0x5c, %ecx
jne 0x73f7
testl %r13d, %r13d
jne 0x73eb
movq %r15, %r14
pushq $0x1
jmp 0x7446
testl %r13d, %r13d
je 0x743a
cmpl $0x2, %r13d
jne 0x73eb
xorl %r13d, %r13d
movq %r15, %r14
jmp 0x7448
testl %r13d, %r13d
je 0x7441
cmpl $0x3, %r13d
je 0x73d8
movb %cl, (%rax,%r15)
incq %r15
movq %r15, %r14
jmp 0x7404
leaq 0x1(%r15), %r14
movb %cl, (%rax,%r15)
testl %r13d, %r13d
je 0x741b
cmpl $0x1, %r13d
jne 0x7448
movq (%r12), %rax
xorl %r13d, %r13d
cmpb $0x5c, (%rax,%rbx)
sete %r13b
jmp 0x7448
movq (%r12), %rax
movsbl (%rax,%rbx), %esi
movq -0x38(%rbp), %rdi
callq 0x4120
leaq -0x68(%rbp), %rsi
xorl %r13d, %r13d
testq %rax, %rax
je 0x7448
jmp 0x7458
movq %r15, %r14
pushq $0x2
jmp 0x7446
movq %r15, %r14
pushq $0x3
popq %r13
incq %rbx
movq 0x8(%r12), %rax
movq %r14, %r15
jmp 0x73a1
incq %rbx
xorl %r13d, %r13d
movq %r15, %rcx
movq -0x48(%rbp), %rdx
subq %rdx, %rcx
movq %rsi, %r14
movq %rsi, %rdi
movq %r12, %rsi
callq 0x4360
movq -0x40(%rbp), %rdi
movq %r14, %rsi
callq 0x7570
movq %r14, %rdi
callq 0x46b8
incq %r15
movq %r15, %rcx
cmpb $0x0, -0x2c(%rbp)
je 0x7388
movq 0x8(%r12), %r14
cmpq %r14, %rbx
cmovaq %rbx, %r14
cmpq %rbx, %r14
je 0x74c6
movq (%r12), %rax
movsbl (%rax,%rbx), %esi
movq -0x38(%rbp), %rdi
callq 0x4120
testq %rax, %rax
je 0x74c9
incq %rbx
jmp 0x74a6
movq %r14, %rbx
movq %r15, %rcx
jmp 0x7388
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x46b8
movq %rbx, %rdi
callq 0x45f0