// File: /workspace/github_c_makefile_star2_O1/MuvikLabs[P]runt/runt.c
// Function: runt_tokenize
runt_int runt_tokenize(runt_vm *vm,
        const char *str,
        runt_uint size,
        runt_uint *pos,
        runt_uint *wsize,
        runt_uint *next)
{
    runt_uint s;
    runt_uint p;
    runt_uint mode = 0;
    runt_uint stop = 0;
    char m = '"';
    *wsize = 0;

    *pos = *next;
    p = *pos;


    if(*pos > size) return RUNT_OK;

    if(*pos == size) {
        *next = size + 1;
        return RUNT_CONTINUE;
    }

    for(s = p; s < size; s++) {

        if(stop != 0) {
            break;
        }
        switch (mode) {
            case 3:
                if(str[s] == m) {
                    mode = 2;
                    *wsize = (s - *pos) + 1;
                }
                continue;
            case 2:
                if(str[s] != ' ' && str[s] != '\n') {
                    *next = s;
                    stop = 1;
                    break;
                }
                continue;
            case 1:
                if(str[s] == ' ' || str[s] == '\n') {
                    mode = 2;
                    *wsize = (s - *pos);
                }
                continue;
            case 0:
                if(str[s] == '#') return RUNT_OK;

                if(str[s] != ' ' && str[s] != '\n') {
                    if(str[s] == '\'' || str[s] == '\"') {
                        mode = 3;
                        m = str[s];
                    } else {
                        mode = 1;
                        *pos = s;
                    }
                }
                *pos = s;
                continue;
            default: break;
        }

    }
    /* if we are at the end, make next larger than the size */
    if(s == size) {
        if(mode == 1) {
            *wsize = (s - *pos);
        } if(mode == 2 && *next == size - 1) {
            return RUNT_CONTINUE;
        }
        *next = size + 1;
    }
    return RUNT_CONTINUE;
}

// Assembly:
movl $0x0, (%r8)
movl (%r9), %edi
movl %edi, (%rcx)
movl $0x1, %eax
cmpl %edx, %edi
ja 0x29e0
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
jne 0x28c8
incl %edx
movl %edx, (%r9)
movl $0x2, %eax
jmp 0x29d6
xorl %r15d, %r15d
cmpl %edx, %edi
jae 0x29a7
movl %edx, %r10d
leaq 0x1(%rdi), %r11
xorl %r15d, %r15d
movb $0x22, %bpl
leaq 0x471d(%rip), %rbx      # 0x7004
movb -0x1(%rsi,%r11), %r12b
movzbl %r12b, %r13d
movl %r15d, %r14d
movslq (%rbx,%r14,4), %r14
addq %rbx, %r14
jmpq *%r14
xorl %r15d, %r15d
leal -0x20(%r13), %r14d
cmpl $0x7, %r14d
ja 0x2981
leaq 0x4703(%rip), %r13      # 0x7014
movslq (%r13,%r14,4), %r14
addq %r13, %r14
jmpq *%r14
movl $0x3, %r15d
movl %r12d, %ebp
jmp 0x298f
movl $0x2, %r15d
xorl %r12d, %r12d
cmpl $0xa, %r13d
je 0x2994
cmpl $0x20, %r13d
je 0x2994
movl %edi, (%r9)
movb $0x1, %r12b
jmp 0x2994
cmpb %bpl, %r12b
jne 0x2971
movl %edi, %r14d
subl (%rcx), %r14d
incl %r14d
jmp 0x2966
cmpl $0x20, %r13d
je 0x2960
cmpl $0xa, %r13d
jne 0x2979
movl %edi, %r14d
subl (%rcx), %r14d
movl %r14d, (%r8)
movl $0x2, %r15d
jmp 0x2991
movl $0x3, %r15d
jmp 0x2991
movl $0x1, %r15d
jmp 0x2991
cmpl $0xa, %r13d
je 0x298f
movl %edi, (%rcx)
movl $0x1, %r15d
movl %edi, (%rcx)
xorl %r12d, %r12d
incl %edi
cmpq %r10, %r11
jae 0x29a7
incq %r11
testb %r12b, %r12b
je 0x28e7
movl $0x2, %eax
cmpl %edx, %edi
jne 0x29d6
cmpl $0x2, %r15d
je 0x29ca
cmpl $0x1, %r15d
jne 0x28b9
subl (%rcx), %edi
movl %edi, (%r8)
jmp 0x28b9
leal -0x1(%rdx), %ecx
cmpl %ecx, (%r9)
jne 0x28b9
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq