// File: /workspace/github_c_makefile_star2_O3/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 0x28ff
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
jne 0x2808
incl %edx
movl %edx, (%r9)
movl $0x2, %eax
jmp 0x28f5
xorl %ebp, %ebp
cmpl %edx, %edi
jae 0x28c6
movl %edx, %r10d
xorl %ebp, %ebp
movb $0x22, %r14b
leaq 0x47e3(%rip), %r11      # 0x7004
leaq 0x47ec(%rip), %rbx      # 0x7014
movb (%rsi,%rdi), %r12b
movzbl %r12b, %r15d
movl %ebp, %r13d
movslq (%r11,%r13,4), %r13
addq %r11, %r13
jmpq *%r13
xorl %ebp, %ebp
leal -0x20(%r15), %r13d
cmpl $0x7, %r13d
ja 0x28ad
movslq (%rbx,%r13,4), %r15
addq %rbx, %r15
jmpq *%r15
movl $0x3, %ebp
movl %r12d, %r14d
jmp 0x28b8
movl $0x2, %ebp
cmpl $0xa, %r15d
je 0x28ba
cmpl $0x20, %r15d
je 0x28ba
jmp 0x2900
movl $0x3, %ebp
cmpb %r14b, %r12b
jne 0x28ba
movl (%rcx), %ebp
movl %edi, %r15d
subl %ebp, %r15d
incl %r15d
jmp 0x28a3
cmpl $0x20, %r15d
je 0x289b
movl $0x1, %ebp
cmpl $0xa, %r15d
jne 0x28ba
movl (%rcx), %ebp
movl %edi, %r15d
subl %ebp, %r15d
movl %r15d, (%r8)
movl $0x2, %ebp
jmp 0x28ba
cmpl $0xa, %r15d
je 0x28b8
movl $0x1, %ebp
movl %edi, (%rcx)
incq %rdi
cmpq %r10, %rdi
jb 0x2828
movl $0x2, %eax
cmpl %edx, %edi
jne 0x28f5
cmpl $0x2, %ebp
je 0x28e9
cmpl $0x1, %ebp
jne 0x27f9
movl %edx, %eax
subl (%rcx), %eax
movl %eax, (%r8)
jmp 0x27f9
leal -0x1(%rdx), %ecx
cmpl %ecx, (%r9)
jne 0x27f9
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %edi, (%r9)
incq %rdi
jmp 0x28c6