// File: 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
subq $0xc0, %rsp
movb %dl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
andb $0x1, %al
movb %al, -0x11(%rbp)
movq %rcx, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x20(%rbp), %rdi
callq 0xb7e0
movq -0x38(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x8(%rbp), %rdi
callq 0x45e0
movq %rax, %rcx
movq -0x78(%rbp), %rax
cmpq %rcx, %rax
jae 0xb2d0
jmp 0xb009
movq -0x38(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x8(%rbp), %rdi
callq 0x45e0
movq %rax, %rcx
movq -0x80(%rbp), %rax
cmpq %rcx, %rax
jae 0xb1cf
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x47f0
movsbl (%rax), %eax
movl %eax, -0x84(%rbp)
subl $0x22, %eax
je 0xb0d8
jmp 0xb04b
movl -0x84(%rbp), %eax
subl $0x27, %eax
je 0xb098
jmp 0xb058
movl -0x84(%rbp), %eax
subl $0x5c, %eax
jne 0xb118
jmp 0xb069
cmpl $0x0, -0x24(%rbp)
jne 0xb078
movl $0x1, -0x24(%rbp)
jmp 0xb093
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq %rsi, %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
callq 0x47f0
movb $0x5c, (%rax)
jmp 0xb19c
cmpl $0x0, -0x24(%rbp)
jne 0xb0a7
movl $0x2, -0x24(%rbp)
jmp 0xb0d3
cmpl $0x2, -0x24(%rbp)
jne 0xb0b6
movl $0x0, -0x24(%rbp)
jmp 0xb0d1
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq %rsi, %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
callq 0x47f0
movb $0x27, (%rax)
jmp 0xb0d3
jmp 0xb19c
cmpl $0x0, -0x24(%rbp)
jne 0xb0e7
movl $0x3, -0x24(%rbp)
jmp 0xb113
cmpl $0x3, -0x24(%rbp)
jne 0xb0f6
movl $0x0, -0x24(%rbp)
jmp 0xb111
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq %rsi, %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
callq 0x47f0
movb $0x22, (%rax)
jmp 0xb113
jmp 0xb19c
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x47f0
movb (%rax), %al
movb %al, -0x85(%rbp)
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq %rsi, %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
callq 0x47f0
movb -0x85(%rbp), %cl
movb %cl, (%rax)
cmpl $0x0, -0x24(%rbp)
jne 0xb19a
movq -0x10(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x47f0
movq -0x90(%rbp), %rdi
movsbl (%rax), %esi
callq 0x4150
cmpq $0x0, %rax
je 0xb19a
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0xb1d1
jmp 0xb19c
cmpl $0x1, -0x24(%rbp)
jne 0xb1be
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x47f0
movsbl (%rax), %eax
cmpl $0x5c, %eax
je 0xb1be
movl $0x0, -0x24(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0xb009
jmp 0xb1d1
movq -0x20(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x8(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x40(%rbp), %rcx
subq %rdx, %rcx
leaq -0x60(%rbp), %rdi
movq %rdi, -0x98(%rbp)
callq 0x43e0
movq -0xa0(%rbp), %rdi
movq -0x98(%rbp), %rsi
callq 0xb800
jmp 0xb210
leaq -0x60(%rbp), %rdi
callq 0x4828
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
testb $0x1, -0x11(%rbp)
je 0xb2c3
jmp 0xb231
movq -0x38(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x8(%rbp), %rdi
callq 0x45e0
movq -0xb0(%rbp), %rcx
movq %rax, %rdx
xorl %eax, %eax
cmpq %rdx, %rcx
movb %al, -0xa1(%rbp)
jae 0xb290
movq -0x10(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x47f0
movq -0xb8(%rbp), %rdi
movsbl (%rax), %esi
callq 0x4150
cmpq $0x0, %rax
setne %al
movb %al, -0xa1(%rbp)
movb -0xa1(%rbp), %al
testb $0x1, %al
jne 0xb29c
jmp 0xb2c1
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0xb231
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x4828
jmp 0xb2d9
jmp 0xb2c3
movq -0x40(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0xafe6
addq $0xc0, %rsp
popq %rbp
retq
movq -0x68(%rbp), %rdi
callq 0x46e0
nopw %cs:(%rax,%rax)
nopl (%rax)