// File: aalto-speech[P]ftk/util/str.hh
// Function: str::split(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, char const*, bool, unsigned int)
inline std::vector<std::string>
split(const std::string &str, const char *delims, bool group,
      unsigned int num_fields = 0)
{
    std::vector<std::string> fields;
    size_t begin = 0;
    size_t end = 0;

    fields.clear();
    bool delim_pending = false;
    while (begin < str.length()) {
        // If 'fields' fields was requested and, this is the last field,
        // include the rest.
        if (num_fields > 0 && fields.size() == num_fields - 1) {
            delim_pending = false;
            fields.push_back(str.substr(begin));
            break;
        }

        // Find the string before the next delim
        delim_pending = false;
        while (end < str.length()) {
            if (strchr(delims, str[end])) {
                delim_pending = true;
                break;
            }
            end++;
        }
        fields.push_back(str.substr(begin, end - begin));

        // Eat the delim or group of delims
        end++;
        if (group)
            while (end < str.length() && strchr(delims, str[end]))
                end++;

        begin = end;
    }

    if (delim_pending)
        fields.push_back("");

    return fields;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0xc0(%rbp)
movb %cl, %al
movq %rdi, %rcx
movq %rcx, -0xc8(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
andb $0x1, %al
movb %al, -0x19(%rbp)
movl %r8d, -0x20(%rbp)
movb $0x0, -0x21(%rbp)
callq 0xa160
movq -0xc0(%rbp), %rdi
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
callq 0xb7e0
movb $0x0, -0x39(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0x10(%rbp), %rdi
callq 0x45e0
movq %rax, %rcx
movq -0xd0(%rbp), %rax
cmpq %rcx, %rax
jae 0xa452
cmpl $0x0, -0x20(%rbp)
jbe 0xa2ef
movq -0xc0(%rbp), %rdi
callq 0x5f70
movl -0x20(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
cmpq %rcx, %rax
jne 0xa2ef
movb $0x0, -0x39(%rbp)
movq -0x10(%rbp), %rsi
movq -0x30(%rbp), %rdx
leaq -0x60(%rbp), %rdi
movq $-0x1, %rcx
callq 0x43e0
jmp 0xa2a4
movq -0xc0(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0xb800
jmp 0xa2b6
leaq -0x60(%rbp), %rdi
callq 0x4828
jmp 0xa452
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0xa514
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x4828
jmp 0xa514
movb $0x0, -0x39(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0x10(%rbp), %rdi
callq 0x45e0
movq %rax, %rcx
movq -0xd8(%rbp), %rax
cmpq %rcx, %rax
jae 0xa357
movq -0x18(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x4430
movq -0xe0(%rbp), %rdi
movsbl (%rax), %esi
callq 0x4150
cmpq $0x0, %rax
je 0xa349
movb $0x1, -0x39(%rbp)
jmp 0xa357
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0xa2f3
movq -0x10(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x38(%rbp), %rcx
subq %rdx, %rcx
leaq -0x90(%rbp), %rdi
callq 0x43e0
jmp 0xa374
movq -0xc0(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0xb800
jmp 0xa389
leaq -0x90(%rbp), %rdi
callq 0x4828
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
testb $0x1, -0x19(%rbp)
je 0xa445
jmp 0xa3ad
movq -0x38(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq -0x10(%rbp), %rdi
callq 0x45e0
movq -0xf0(%rbp), %rcx
movq %rax, %rdx
xorl %eax, %eax
cmpq %rdx, %rcx
movb %al, -0xe1(%rbp)
jae 0xa40c
movq -0x18(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x4430
movq -0xf8(%rbp), %rdi
movsbl (%rax), %esi
callq 0x4150
cmpq $0x0, %rax
setne %al
movb %al, -0xe1(%rbp)
movb -0xe1(%rbp), %al
testb $0x1, %al
jne 0xa418
jmp 0xa443
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0xa3ad
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x4828
jmp 0xa514
jmp 0xa445
movq -0x38(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0xa23c
testb $0x1, -0x39(%rbp)
je 0xa4ee
leaq -0xb1(%rbp), %rdi
movq %rdi, -0x100(%rbp)
callq 0x46f0
movq -0x100(%rbp), %rdx
leaq 0x5c07a(%rip), %rsi     # 0x664f7
leaq -0xb0(%rbp), %rdi
callq 0x4550
jmp 0xa48b
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0xb800
jmp 0xa4a0
leaq -0xb0(%rbp), %rdi
callq 0x4828
leaq -0xb1(%rbp), %rdi
callq 0x4420
jmp 0xa4ee
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0xa4e0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x4828
leaq -0xb1(%rbp), %rdi
callq 0x4420
jmp 0xa514
movb $0x1, -0x21(%rbp)
testb $0x1, -0x21(%rbp)
jne 0xa504
movq -0xc0(%rbp), %rdi
callq 0x6970
movq -0xc8(%rbp), %rax
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
movq -0xc0(%rbp), %rdi
callq 0x6970
movq -0x68(%rbp), %rdi
callq 0x46e0
nopl (%rax)