// File: /workspace/github_c_makefile_star2_O0/chgzm[P]minic/preprocessor.c
// Function: enabled_read
static int enabled_read(const Vector* in_vec, int* index, Vector* out_vec) {
    Token* token = in_vec->elements[*index];
    if (token->type != TK_HASH) {
        if (token->type == TK_IDENT && strptrmap_contains(define_map, token->str)) {
            Token* value1 = strptrmap_get(define_map, token->str);
            if (value1 != NULL) {
                vector_push_back(out_vec, value1);
            }

            ++(*index);
            return STATE_ENABLED;
        }
        else {
            vector_push_back(out_vec, token);
            ++(*index);
            return STATE_ENABLED;
        }
    }
    else {
        //
        // #define
        //
        if (strncmp("define", token->str, 6) == 0) {
            ++(*index);
            const Token* name = in_vec->elements[*index];
            ++(*index);

            if (token->has_value) {
                Token* value2 = in_vec->elements[*index];
                strptrmap_put(define_map, name->str, value2);
                ++(*index);

                return STATE_ENABLED;
            }
            else  {
                strptrmap_put(define_map, name->str, NULL);
                return STATE_ENABLED;
            }
        }
        //
        // #include
        //
        else if (strncmp("include", token->str, 7) == 0) { 
            ++(*index);

            token = in_vec->elements[*index];
            // FIXME: skip include <...> 
            if (token->type == TK_LANGLE) {
                while (token->type != TK_RANGLE) {
                    ++(*index);
                    token = in_vec->elements[*index];
                }

                ++(*index);
                return STATE_ENABLED; 
            } 
            else if (token->type == TK_STR) {
                char* addr = read_file(token->str);
                if (addr == NULL) {
                    error("Failed to load file:\"%s\".\n", token->str); 
                    return STATE_INVALID;
                }

                const Vector* include_vec = tokenize(addr);
                if (include_vec == NULL) {
                    error("Failed to tokenize.\n");
                    return STATE_INVALID;
                }

                const Vector* include_processed_vec = preprocess(include_vec);
                if (include_processed_vec == NULL) {
                    error("Failed to preprocess.\n");
                    return STATE_INVALID;
                }

                for (int i = 0; i < include_processed_vec->size; ++i) {
                    vector_push_back(out_vec, include_processed_vec->elements[i]);
                }

                ++(*index);
            }
            else {
                error("Invalid token[%d]=\"%s\".\n", index, decode_token_type(token->type));
                return STATE_INVALID;
            }

            return STATE_ENABLED;
        } 
        //
        // #ifdef
        //
        else if (strncmp("ifdef", token->str, 5) == 0) {
            ++(*index);

            token = in_vec->elements[*index];
            if (token->type != TK_IDENT) {
                error("Invalid token[%d]=\"%s\".\n", index, decode_token_type(token->type));
                return STATE_INVALID;
            }
            ++(*index);

            if (strptrmap_contains(define_map, token->str)) {
                return STATE_ENABLED;
            } else {
                return STATE_DISABLED;
            }
        }
        //
        // #ifndef
        //
        else if (strncmp("ifndef", token->str, 6) == 0) {
            ++(*index);

            token = in_vec->elements[*index];
            if (token->type != TK_IDENT) {
                error("Invalid token[%d]=\"%s\".\n", index, decode_token_type(token->type));
                return STATE_INVALID;
            }
            ++(*index);

            if (strptrmap_contains(define_map, token->str)) {
                return STATE_DISABLED;
            } else {
                return STATE_ENABLED;
            }
        }
        //
        // #else
        //
        else if (strncmp("else", token->str, 4) == 0) {
            ++(*index);
            return STATE_DISABLED; 
        }
        //
        // #endif
        //
        else if (strncmp("endif", token->str, 5) == 0) {
            ++(*index);
            return STATE_ENABLED;
        }
        else {
            // @todo
            ++(*index);
            return STATE_ENABLED;
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x2f, (%rax)
je 0xc544
movq -0x28(%rbp), %rax
cmpl $0x3, (%rax)
jne 0xc520
movq 0x8cc6(%rip), %rdi      # 0x15190
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0xeae0
testb $0x1, %al
jne 0xc4dd
jmp 0xc520
movq 0x8cac(%rip), %rdi      # 0x15190
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0xeb80
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0xc509
movq -0x20(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0xe610
movq -0x18(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0xc9a8
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0xe610
movq -0x18(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0xc9a8
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0x4348(%rip), %rdi      # 0x1089b
movl $0x6, %edx
callq 0x1060
cmpl $0x0, %eax
jne 0xc605
movq -0x18(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x28(%rbp), %rax
testb $0x1, 0x14(%rax)
je 0xc5e1
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x40(%rbp)
movq 0x8bd7(%rip), %rdi      # 0x15190
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x40(%rbp), %rdx
callq 0xe950
movq -0x18(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0xc9a8
movq 0x8ba8(%rip), %rdi      # 0x15190
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0xe950
movl $0x0, -0x4(%rbp)
jmp 0xc9a8
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0x428e(%rip), %rdi      # 0x108a2
movl $0x7, %edx
callq 0x1060
cmpl $0x0, %eax
jne 0xc7be
movq -0x18(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x27, (%rax)
jne 0xc696
jmp 0xc653
movq -0x28(%rbp), %rax
cmpl $0x28, (%rax)
je 0xc67f
movq -0x18(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x28(%rbp)
jmp 0xc653
movq -0x18(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0xc9a8
movq -0x28(%rbp), %rax
cmpl $0x2, (%rax)
jne 0xc77c
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0xe510
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0xc6dd
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0x41e0(%rip), %rdi      # 0x108aa
movb $0x0, %al
callq 0xe4e0
movl $0x2, -0x4(%rbp)
jmp 0xc9a8
movq -0x48(%rbp), %rdi
callq 0xca70
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0xc70b
leaq 0x330c(%rip), %rdi      # 0xfa04
movb $0x0, %al
callq 0xe4e0
movl $0x2, -0x4(%rbp)
jmp 0xc9a8
movq -0x50(%rbp), %rdi
callq 0xc330
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0xc739
leaq 0x32f3(%rip), %rdi      # 0xfa19
movb $0x0, %al
callq 0xe4e0
movl $0x2, -0x4(%rbp)
jmp 0xc9a8
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
movq -0x58(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0xc76f
movq -0x20(%rbp), %rdi
movq -0x58(%rbp), %rax
movq (%rax), %rax
movslq -0x5c(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0xe610
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0xc740
movq -0x18(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0xc7b0
movq -0x18(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x28(%rbp), %rax
movl (%rax), %edi
callq 0xe050
movq -0x68(%rbp), %rsi
movq %rax, %rdx
leaq 0x3793(%rip), %rdi      # 0xff30
movb $0x0, %al
callq 0xe4e0
movl $0x2, -0x4(%rbp)
jmp 0xc9a8
jmp 0xc7b2
movl $0x0, -0x4(%rbp)
jmp 0xc9a8
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0x40f8(%rip), %rdi      # 0x108c5
movl $0x5, %edx
callq 0x1060
cmpl $0x0, %eax
jne 0xc87b
movq -0x18(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x3, (%rax)
je 0xc83e
movq -0x18(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x28(%rbp), %rax
movl (%rax), %edi
callq 0xe050
movq -0x70(%rbp), %rsi
movq %rax, %rdx
leaq 0x3705(%rip), %rdi      # 0xff30
movb $0x0, %al
callq 0xe4e0
movl $0x2, -0x4(%rbp)
jmp 0xc9a8
movq -0x18(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq 0x8940(%rip), %rdi      # 0x15190
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0xeae0
testb $0x1, %al
jne 0xc863
jmp 0xc86f
movl $0x0, -0x4(%rbp)
jmp 0xc9a8
movl $0x1, -0x4(%rbp)
jmp 0xc9a8
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0x4041(%rip), %rdi      # 0x108cb
movl $0x6, %edx
callq 0x1060
cmpl $0x0, %eax
jne 0xc932
movq -0x18(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x3, (%rax)
je 0xc8fb
movq -0x18(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x28(%rbp), %rax
movl (%rax), %edi
callq 0xe050
movq -0x78(%rbp), %rsi
movq %rax, %rdx
leaq 0x3648(%rip), %rdi      # 0xff30
movb $0x0, %al
callq 0xe4e0
movl $0x2, -0x4(%rbp)
jmp 0xc9a8
movq -0x18(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq 0x8883(%rip), %rdi      # 0x15190
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0xeae0
testb $0x1, %al
jne 0xc920
jmp 0xc929
movl $0x1, -0x4(%rbp)
jmp 0xc9a8
movl $0x0, -0x4(%rbp)
jmp 0xc9a8
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0x3f91(%rip), %rdi      # 0x108d2
movl $0x4, %edx
callq 0x1060
cmpl $0x0, %eax
jne 0xc964
movq -0x18(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0xc9a8
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0x3f64(%rip), %rdi      # 0x108d7
movl $0x5, %edx
callq 0x1060
cmpl $0x0, %eax
jne 0xc996
movq -0x18(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0xc9a8
movq -0x18(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)