// File: /workspace/github_c_makefile_star2_O3/tstword[P]MIPSAssemblerC/src/tokenizer.c
// Function: get_next_token
token_t get_next_token(struct tokenizer *tokenizer) {
    state_fsm next_state = init_state;
    
    /* Start finite state machine */
    while(1) {
        switch(next_state) {
            case init_state:
                tokenizer->bufpos = 0;
                next_state = init_fsm(tokenizer);
                break;
            case identifier_state:
                next_state = identifier_fsm(tokenizer);
                break;
            case integer_state:
                next_state = integer_fsm(tokenizer);
                break;
            case zero_state:
                next_state = zero_fsm(tokenizer);
                break;
            case hex_state:
                next_state = hex_fsm(tokenizer);
                break;
            case comment_state:
                next_state = comment_fsm(tokenizer);
                break;
            case negative_state:
                next_state = negative_fsm(tokenizer);
                break;
            case string_state:
                next_state = string_fsm(tokenizer);
                break;
            case comment_accept:
                next_state = init_state;
                break;
            case character_state:
                next_state = character_fsm(tokenizer);
                break;
            case escape_state:
                next_state = escape_fsm(tokenizer);
                break;
            case quote_state:
                next_state = quote_fsm(tokenizer);
                break;
            case string_escape:
                next_state = string_escape_fsm(tokenizer);
                break;
            case integer_accept:
            case character_accept:
                return return_token(TOK_INTEGER, tokenizer);
            case identifier_accept:
                return return_token(TOK_IDENTIFIER, tokenizer);
            case comma_accept:
                return return_token(TOK_COMMA, tokenizer);
            case colon_accept:
                return return_token(TOK_COLON, tokenizer);
            case eol_accept:
                return return_token(TOK_EOL, tokenizer);
            case left_paren_accept:
                return return_token(TOK_LPAREN, tokenizer);
            case right_paren_accept:
                return return_token(TOK_RPAREN, tokenizer);
            case string_accept:
                return return_token(TOK_STRING, tokenizer);
            case eof_accept:
                return return_token(TOK_NULL, tokenizer);
            case invalid_state:
                return return_token(TOK_INVALID, tokenizer);
        }
    }

    return TOK_INVALID;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
xorl %eax, %eax
leaq 0x1236(%rip), %r14      # 0x7e40
movl %eax, %eax
movslq (%r14,%rax,4), %rcx
addq %r14, %rcx
xorl %eax, %eax
jmpq *%rcx
movq $0x0, 0x28(%rbx)
movq %rbx, %rdi
callq 0x645e
jmp 0x6c0a
movq %rbx, %rdi
callq 0x6724
jmp 0x6c0a
movq %rbx, %rdi
callq 0x6795
jmp 0x6c0a
movq %rbx, %rdi
callq 0x6563
jmp 0x6c0a
movq %rbx, %rdi
callq 0x67fe
jmp 0x6c0a
movq %rbx, %rdi
callq 0x65a7
jmp 0x6c0a
movq %rbx, %rdi
callq 0x669b
jmp 0x6c0a
movq %rbx, %rdi
callq 0x6659
jmp 0x6c0a
movq %rbx, %rdi
callq 0x68de
jmp 0x6c0a
movq %rbx, %rdi
callq 0x686e
jmp 0x6c0a
movq %rbx, %rdi
callq 0x65d9
jmp 0x6c0a
movq %rbx, %rdi
callq 0x66cf
jmp 0x6c0a
movl $0x4, %edi
jmp 0x6cde
movl $0x7, %edi
jmp 0x6cde
movl $0x5, %edi
jmp 0x6cde
movl $0x2, %edi
jmp 0x6cde
movl $0x3, %edi
jmp 0x6cde
movl $0x6, %edi
jmp 0x6cde
movl $0x1, %edi
jmp 0x6cde
movl $0xa, %edi
jmp 0x6cde
xorl %edi, %edi
jmp 0x6cde
movl $0xb, %edi
movq %rbx, %rsi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x6929