// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq %rax, -0x20(%rbp)
subq $0x17, %rax
ja 0x9170
movq -0x20(%rbp), %rax
leaq 0x2491(%rip), %rcx      # 0xb450
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x10(%rbp), %rax
movq $0x0, 0x28(%rax)
movq -0x10(%rbp), %rdi
callq 0x83a0
movl %eax, -0x14(%rbp)
jmp 0x9170
movq -0x10(%rbp), %rdi
callq 0x8550
movl %eax, -0x14(%rbp)
jmp 0x9170
movq -0x10(%rbp), %rdi
callq 0x85c0
movl %eax, -0x14(%rbp)
jmp 0x9170
movq -0x10(%rbp), %rdi
callq 0x8610
movl %eax, -0x14(%rbp)
jmp 0x9170
movq -0x10(%rbp), %rdi
callq 0x86c0
movl %eax, -0x14(%rbp)
jmp 0x9170
movq -0x10(%rbp), %rdi
callq 0x8730
movl %eax, -0x14(%rbp)
jmp 0x9170
movq -0x10(%rbp), %rdi
callq 0x87a0
movl %eax, -0x14(%rbp)
jmp 0x9170
movq -0x10(%rbp), %rdi
callq 0x8830
movl %eax, -0x14(%rbp)
jmp 0x9170
movl $0x0, -0x14(%rbp)
jmp 0x9170
movq -0x10(%rbp), %rdi
callq 0x88e0
movl %eax, -0x14(%rbp)
jmp 0x9170
movq -0x10(%rbp), %rdi
callq 0x8a00
movl %eax, -0x14(%rbp)
jmp 0x9170
movq -0x10(%rbp), %rdi
callq 0x8a90
movl %eax, -0x14(%rbp)
jmp 0x9170
movq -0x10(%rbp), %rdi
callq 0x8970
movl %eax, -0x14(%rbp)
jmp 0x9170
movq -0x10(%rbp), %rsi
movl $0x4, %edi
callq 0x8b00
movl %eax, -0x4(%rbp)
jmp 0x9175
movq -0x10(%rbp), %rsi
movl $0x3, %edi
callq 0x8b00
movl %eax, -0x4(%rbp)
jmp 0x9175
movq -0x10(%rbp), %rsi
movl $0x2, %edi
callq 0x8b00
movl %eax, -0x4(%rbp)
jmp 0x9175
movq -0x10(%rbp), %rsi
movl $0x1, %edi
callq 0x8b00
movl %eax, -0x4(%rbp)
jmp 0x9175
movq -0x10(%rbp), %rsi
movl $0x7, %edi
callq 0x8b00
movl %eax, -0x4(%rbp)
jmp 0x9175
movq -0x10(%rbp), %rsi
movl $0x5, %edi
callq 0x8b00
movl %eax, -0x4(%rbp)
jmp 0x9175
movq -0x10(%rbp), %rsi
movl $0x6, %edi
callq 0x8b00
movl %eax, -0x4(%rbp)
jmp 0x9175
movq -0x10(%rbp), %rsi
movl $0xa, %edi
callq 0x8b00
movl %eax, -0x4(%rbp)
jmp 0x9175
movq -0x10(%rbp), %rsi
xorl %edi, %edi
callq 0x8b00
movl %eax, -0x4(%rbp)
jmp 0x9175
movq -0x10(%rbp), %rsi
movl $0xb, %edi
callq 0x8b00
movl %eax, -0x4(%rbp)
jmp 0x9175
jmp 0x8fa3
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nop