// File: /workspace/github_c_makefile_star2_O2/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:
andl $0x0, (%r8)
movl (%r9), %edi
movl %edi, (%rcx)
cmpl %edx, %edi
jbe 0x21cf
movl $0x1, %eax
retq
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
cmpl %edx, %edi
jne 0x21ec
incl %edx
movl %edx, (%r9)
movl $0x2, %eax
jmp 0x22fb
movl $0x2, %eax
movl %edx, %r10d
movb $0x22, %r15b
xorl %r12d, %r12d
leaq 0x3e03(%rip), %r11      # 0x6004
leaq 0x3e0c(%rip), %r14      # 0x6014
xorl %r13d, %r13d
cmpq %r10, %rdi
jae 0x22c2
testl %r13d, %r13d
jne 0x22c2
movb (%rsi,%rdi), %bl
movzbl %bl, %ebp
movl %r12d, %r12d
movslq (%r11,%r12,4), %r12
addq %r11, %r12
jmpq *%r12
xorl %r12d, %r12d
leal -0x20(%rbp), %r13d
cmpl $0x7, %r13d
ja 0x22aa
movslq (%r14,%r13,4), %r13
addq %r14, %r13
jmpq *%r13
movl $0x3, %r12d
movl %ebx, %r15d
jmp 0x22b5
xorl %r13d, %r13d
cmpl $0xa, %ebp
je 0x2295
cmpl $0x20, %ebp
je 0x2295
movl %edi, (%r9)
movl %eax, %r12d
movl $0x1, %r13d
jmp 0x22ba
xorl %r13d, %r13d
cmpb %r15b, %bl
jne 0x229a
movl (%rcx), %ebx
movl %edi, %ebp
subl %ebx, %ebp
incl %ebp
jmp 0x2292
xorl %r13d, %r13d
cmpl $0x20, %ebp
je 0x228c
cmpl $0xa, %ebp
jne 0x22a2
movl (%rcx), %ebx
movl %edi, %ebp
subl %ebx, %ebp
movl %ebp, (%r8)
movl %eax, %r12d
jmp 0x22ba
movl $0x3, %r12d
jmp 0x22ba
movl $0x1, %r12d
jmp 0x22ba
cmpl $0xa, %ebp
je 0x22b5
movl $0x1, %r12d
movl %edi, (%rcx)
xorl %r13d, %r13d
incq %rdi
jmp 0x220b
movl $0x2, %eax
cmpl %edi, %r10d
jne 0x22fb
cmpl $0x2, %r12d
je 0x22e8
cmpl $0x1, %r12d
jne 0x21dd
movl %edx, %eax
subl (%rcx), %eax
movl %eax, (%r8)
jmp 0x21dd
leal -0x1(%rdx), %ecx
cmpl %ecx, (%r9)
jne 0x21dd
jmp 0x22fb
movl $0x1, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq