// File: /workspace/github_c_makefile_star2_O0/MaoKo[P]FGFX/tools/src/lexer.c
// Function: advance_token
long
advance_token(lexer_t* lex) {
    if (!lex)
        { return (ERROR); }
    long found_token;
    if (lex->last_token != -1)
        { found_token = lex->last_token; }
    else {
        reset_buffer(lex->last_lexeme);
        while (1) {
            found_token = get_next_token(lex);
            if (!check_present_table(fgfx_skip_table, found_token))
                { break; }
            reset_buffer(lex->last_lexeme);
        }
    }

    if (found_token == T_DIRECTIVE) {
        static void* directive_tab[][2] = {
            { (void*)T_SKIP,        "$SKIP" },
            { (void*)T_TOKEN,       "$TOKEN" },
            { (void*)T_KEYWORD,     "$KEYWORD" },
            { (void*)T_STATE,       "$STATE" },
            { (void*)T_BEGIN,       "$BEGIN" },
            { (void*)T_PUSH,        "$PUSH" },
            { (void*)T_POP,         "$POP" },
            { (void*)T_FRAGMENT,    "$FRAGMENT" },
            { (void*)T_INITIAL,     "$INITIAL" },
            { (void*)T_EXTERN,      "$EXTERN" },
            { (void*)T_ALIAS,       "$ALIAS" },
            { (void*)T_PRODUCTION,  "$PRODUCTION" },
            { (void*)T_PRECEDENCE,  "$PRECEDENCE" },
            { (void*)T_MIMIC,       "$MIMIC" },
            { (void*)T_EMPTY,       "$EMPTY" },
            { (void*)T_START,       "$START" },
            { (void*)T_LEFT,        "$LEFT" },
            { (void*)T_RIGHT,       "$RIGHT" },
            { (void*)T_NONASSOC,    "$NONASSOC" },
            { (void*)T_STAY,        "$STAY" },
        };
        for (size_t i = 0; i < *(&directive_tab + 1) - directive_tab; ++i) {
            if (!strcmp(C_LEXEME(lex), directive_tab[i][1]))
                { return ((long)*directive_tab[i]); }
        }
        errorf(CURRENT_LINE(lex), "Bad directive %s.", C_LEXEME(lex));
        return (T_ERROR);
    }
    else if (found_token == T_CCE) {
        static void* cce_tab[][2] = {
            { (void*)T_CCE_ALNUM,   "[:alnum:]"  },
            { (void*)T_CCE_ALPHA,   "[:alpha:]"  },
            { (void*)T_CCE_CNTRL,   "[:cntrl:]"  },
            { (void*)T_CCE_DIGIT,   "[:digit:]"  },
            { (void*)T_CCE_GRAPH,   "[:graph:]"  },
            { (void*)T_CCE_LOWER,   "[:lower:]"  },
            { (void*)T_CCE_PRINT,   "[:print:]"  },
            { (void*)T_CCE_PUNCT,   "[:punct:]"  },
            { (void*)T_CCE_SPACE,   "[:space:]"  },
            { (void*)T_CCE_BLANK,   "[:blank:]"  },
            { (void*)T_CCE_UPPER,   "[:upper:]"  },
            { (void*)T_CCE_XDIGIT,  "[:xdigit:]" },
        };
        for (size_t i = 0; i < *(&cce_tab + 1) - cce_tab; ++i) {
            if (!strcmp(C_LEXEME(lex), cce_tab[i][1]))
                { return ((long)*cce_tab[i]); }
        }
        errorf(CURRENT_LINE(lex),
                        "Bad character class expression %s.", C_LEXEME(lex));
        return (T_ERROR);
    }
    else if (found_token == T_N_CCE) {
        static void* n_cce_tab[][2] = {
            { (void*)T_N_CCE_ALNUM,     "[:^alnum:]"  },
            { (void*)T_N_CCE_ALPHA,     "[:^alpha:]"  },
            { (void*)T_N_CCE_CNTRL,     "[:^cntrl:]"  },
            { (void*)T_N_CCE_DIGIT,     "[:^digit:]"  },
            { (void*)T_N_CCE_GRAPH,     "[:^graph:]"  },
            { (void*)T_N_CCE_LOWER,     "[:^lower:]"  },
            { (void*)T_N_CCE_PRINT,     "[:^print:]"  },
            { (void*)T_N_CCE_PUNCT,     "[:^punct:]"  },
            { (void*)T_N_CCE_SPACE,     "[:^space:]"  },
            { (void*)T_N_CCE_BLANK,     "[:^blank:]"  },
            { (void*)T_N_CCE_UPPER,     "[:^upper:]"  },
            { (void*)T_N_CCE_XDIGIT,    "[:^xdigit:]" },
        };
        for (size_t i = 0; i < *(&n_cce_tab + 1) - n_cce_tab; ++i) {
            if (!strcmp(C_LEXEME(lex), n_cce_tab[i][1]))
                { return ((long)*n_cce_tab[i]); }
        }
        errorf(CURRENT_LINE(lex),
                    "Bad negate character class expression %s.", C_LEXEME(lex));
        return (T_ERROR);
    }
    lex->last_token = -1;
    return (found_token);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x2cc0
movq $-0x1, -0x8(%rbp)
jmp 0x2f5f
movq -0x10(%rbp), %rax
cmpl $-0x1, 0x4(%rax)
je 0x2cd8
movq -0x10(%rbp), %rax
movslq 0x4(%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0x2d1d
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x28f0
movq -0x10(%rbp), %rdi
callq 0x2f70
cltq
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movl %eax, %esi
leaq 0xe4df(%rip), %rdi      # 0x111e0
callq 0x2c40
testb $0x1, %al
jne 0x2d0c
jmp 0x2d1b
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x28f0
jmp 0x2ce5
jmp 0x2d1d
cmpq $0x2c, -0x18(%rbp)
jne 0x2dd8
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
leaq 0xe4b5(%rip), %rdx      # 0x111f0
movq %rdx, %rcx
addq $0x140, %rcx            # imm = 0x140
subq %rdx, %rcx
sarq $0x4, %rcx
cmpq %rcx, %rax
jae 0x2daa
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rdi
movq -0x20(%rbp), %rcx
leaq 0xe489(%rip), %rax      # 0x111f0
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rsi
callq 0x10f0
cmpl $0x0, %eax
jne 0x2d9a
movq -0x20(%rbp), %rcx
leaq 0xe469(%rip), %rax      # 0x111f0
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0x8(%rbp)
jmp 0x2f5f
jmp 0x2d9c
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x2d30
movq -0x10(%rbp), %rax
movslq 0x28(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rdx
leaq 0x931f(%rip), %rsi      # 0xc0e3
movb $0x0, %al
callq 0x4210
movq $0x6f, -0x8(%rbp)
jmp 0x2f5f
cmpq $0x1b, -0x18(%rbp)
jne 0x2e93
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
leaq 0xe53a(%rip), %rdx      # 0x11330
movq %rdx, %rcx
addq $0xc0, %rcx
subq %rdx, %rcx
sarq $0x4, %rcx
cmpq %rcx, %rax
jae 0x2e65
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rdi
movq -0x28(%rbp), %rcx
leaq 0xe50e(%rip), %rax      # 0x11330
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rsi
callq 0x10f0
cmpl $0x0, %eax
jne 0x2e55
movq -0x28(%rbp), %rcx
leaq 0xe4ee(%rip), %rax      # 0x11330
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0x8(%rbp)
jmp 0x2f5f
jmp 0x2e57
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x2deb
movq -0x10(%rbp), %rax
movslq 0x28(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rdx
leaq 0x92ef(%rip), %rsi      # 0xc16e
movb $0x0, %al
callq 0x4210
movq $0x6f, -0x8(%rbp)
jmp 0x2f5f
cmpq $0x1c, -0x18(%rbp)
jne 0x2f48
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
leaq 0xe53f(%rip), %rdx      # 0x113f0
movq %rdx, %rcx
addq $0xc0, %rcx
subq %rdx, %rcx
sarq $0x4, %rcx
cmpq %rcx, %rax
jae 0x2f1d
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rdi
movq -0x30(%rbp), %rcx
leaq 0xe513(%rip), %rax      # 0x113f0
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rsi
callq 0x10f0
cmpl $0x0, %eax
jne 0x2f0d
movq -0x30(%rbp), %rcx
leaq 0xe4f3(%rip), %rax      # 0x113f0
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0x8(%rbp)
jmp 0x2f5f
jmp 0x2f0f
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x2ea6
movq -0x10(%rbp), %rax
movslq 0x28(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rdx
leaq 0x92df(%rip), %rsi      # 0xc216
movb $0x0, %al
callq 0x4210
movq $0x6f, -0x8(%rbp)
jmp 0x2f5f
jmp 0x2f4a
jmp 0x2f4c
movq -0x10(%rbp), %rax
movl $0xffffffff, 0x4(%rax)  # imm = 0xFFFFFFFF
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)