// File: /workspace/github_c_makefile_star2_O2/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 0x18e3(%rip), %r14      # 0x7e40
movl %eax, %eax
movslq (%r14,%rax,4), %rcx
addq %r14, %rcx
xorl %eax, %eax
jmpq *%rcx
andq $0x0, 0x28(%rbx)
movq %rbx, %rdi
callq 0x5ee8
jmp 0x655d
movq %rbx, %rdi
callq 0x6103
jmp 0x655d
movq %rbx, %rdi
callq 0x6158
jmp 0x655d
movq %rbx, %rdi
callq 0x5faf
jmp 0x655d
movq %rbx, %rdi
callq 0x61b1
jmp 0x655d
movq %rbx, %rdi
callq 0x5fe3
jmp 0x655d
movq %rbx, %rdi
callq 0x6096
jmp 0x655d
movq %rbx, %rdi
callq 0x6062
jmp 0x655d
movq %rbx, %rdi
callq 0x6271
jmp 0x655d
movq %rbx, %rdi
callq 0x6211
jmp 0x655d
movq %rbx, %rdi
callq 0x6007
jmp 0x655d
movq %rbx, %rdi
callq 0x60bc
jmp 0x655d
pushq $0x4
jmp 0x6610
pushq $0x7
jmp 0x6610
pushq $0x5
jmp 0x6610
pushq $0x2
jmp 0x6610
pushq $0x3
jmp 0x6610
pushq $0x6
jmp 0x6610
pushq $0x1
jmp 0x6610
pushq $0xa
jmp 0x6610
xorl %edi, %edi
jmp 0x6611
pushq $0xb
popq %rdi
movq %rbx, %rsi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x62ab