// File: /workspace/github_c_makefile_star2_O0/chgzm[P]minic/tokenizer.c
// Function: tokenize
Vector* tokenize(char* addr) {
    Vector* vec = create_vector();

    int pos = 0;
    const char* p = addr;
    Token* token = NULL;
    while (p[pos]) {
        if (isspace(p[pos])) {
            ++pos;
        }
        else if (is_line_comment(p, pos)) {
            while (p[pos] != '\n') {
                ++pos;
            } 
        }
        else if (is_block_comment_begin(p, pos)) {
            while (!is_block_comment_end(p, pos)) {
                ++pos;
            }
            pos += 2;
        }
        else if (p[pos] == '#') {
            token = read_directive(p, &pos);
            if (token == NULL) {
                error("Failed to read directive.\n");
                return NULL;
            }
            vector_push_back(vec, token);
        }
        else if (p[pos] == '\'') {
            token = read_character(p, &pos);
            if (token == NULL) {
                error("Failed to read character.\n");
                return NULL;
            }
            vector_push_back(vec, token);
        }
        else if (p[pos] == '"') {
            token = read_string(p, &pos);
            if (token == NULL) {
                error("Failed to read string.\n");
                return NULL;
            }
            vector_push_back(vec, token);
        }
        else if (is_symbol(p[pos])) {
            token = read_symbol(p, &pos);
            if (token == NULL) {
                error("Failed to read symbol.\n");
                return NULL;
            }
            vector_push_back(vec, token);
        }
        else if (isalpha(p[pos]) || p[pos] == '_') {
            token = read_identifier(p, &pos);
            if (token == NULL) {
                error("Failed to read identifier.\n");
                return NULL;
            }
            vector_push_back(vec, token);
        }
        else if (isdigit(p[pos])) {
            token = read_number(p, &pos);
            if (token == NULL) {
                error("Failed to read number.\n");
                return NULL;
            }
            vector_push_back(vec, token);
        }
        else {
            error("Invalid character[%d]='%c'\n", pos, p[pos]);
            return NULL;
        }
    }

    return vec;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movb $0x0, %al
callq 0xe5c0
movq %rax, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x28(%rbp), %rax
movslq -0x1c(%rbp), %rcx
cmpb $0x0, (%rax,%rcx)
je 0xcdd2
callq 0x1180
movq (%rax), %rax
movq -0x28(%rbp), %rcx
movslq -0x1c(%rbp), %rdx
movsbl (%rcx,%rdx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x2000, %eax           # imm = 0x2000
cmpl $0x0, %eax
je 0xcae3
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xcdcd
movq -0x28(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0xcdf0
testb $0x1, %al
jne 0xcaf5
jmp 0xcb18
jmp 0xcaf7
movq -0x28(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0xa, %eax
je 0xcb13
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xcaf7
jmp 0xcdcb
movq -0x28(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0xce30
testb $0x1, %al
jne 0xcb2a
jmp 0xcb59
jmp 0xcb2c
movq -0x28(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0xce70
xorb $-0x1, %al
testb $0x1, %al
jne 0xcb40
jmp 0xcb4b
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xcb2c
movl -0x1c(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x1c(%rbp)
jmp 0xcdc9
movq -0x28(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x23, %eax
jne 0xcbaf
movq -0x28(%rbp), %rdi
leaq -0x1c(%rbp), %rsi
callq 0xceb0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0xcb9d
leaq 0x41af(%rip), %rdi      # 0x10d38
movb $0x0, %al
callq 0xe4e0
movq $0x0, -0x8(%rbp)
jmp 0xcdda
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0xe610
jmp 0xcdc7
movq -0x28(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x27, %eax
jne 0xcc05
movq -0x28(%rbp), %rdi
leaq -0x1c(%rbp), %rsi
callq 0xd0d0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0xcbf3
leaq 0x4174(%rip), %rdi      # 0x10d53
movb $0x0, %al
callq 0xe4e0
movq $0x0, -0x8(%rbp)
jmp 0xcdda
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0xe610
jmp 0xcdc5
movq -0x28(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x22, %eax
jne 0xcc5b
movq -0x28(%rbp), %rdi
leaq -0x1c(%rbp), %rsi
callq 0xd1e0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0xcc49
leaq 0x4139(%rip), %rdi      # 0x10d6e
movb $0x0, %al
callq 0xe4e0
movq $0x0, -0x8(%rbp)
jmp 0xcdda
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0xe610
jmp 0xcdc3
movq -0x28(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movsbl (%rax,%rcx), %edi
callq 0xd300
testb $0x1, %al
jne 0xcc72
jmp 0xccb7
movq -0x28(%rbp), %rdi
leaq -0x1c(%rbp), %rsi
callq 0xd350
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0xcca5
leaq 0x40f5(%rip), %rdi      # 0x10d86
movb $0x0, %al
callq 0xe4e0
movq $0x0, -0x8(%rbp)
jmp 0xcdda
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0xe610
jmp 0xcdc1
callq 0x1180
movq (%rax), %rax
movq -0x28(%rbp), %rcx
movslq -0x1c(%rbp), %rdx
movsbl (%rcx,%rdx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
jne 0xcced
movq -0x28(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x5f, %eax
jne 0xcd32
movq -0x28(%rbp), %rdi
leaq -0x1c(%rbp), %rsi
callq 0xd990
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0xcd20
leaq 0x4092(%rip), %rdi      # 0x10d9e
movb $0x0, %al
callq 0xe4e0
movq $0x0, -0x8(%rbp)
jmp 0xcdda
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0xe610
jmp 0xcdbf
callq 0x1180
movq (%rax), %rax
movq -0x28(%rbp), %rcx
movslq -0x1c(%rbp), %rdx
movsbl (%rcx,%rdx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
je 0xcd96
movq -0x28(%rbp), %rdi
leaq -0x1c(%rbp), %rsi
callq 0xdf90
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0xcd87
leaq 0x4044(%rip), %rdi      # 0x10dba
movb $0x0, %al
callq 0xe4e0
movq $0x0, -0x8(%rbp)
jmp 0xcdda
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0xe610
jmp 0xcdbd
movl -0x1c(%rbp), %esi
movq -0x28(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movsbl (%rax,%rcx), %edx
leaq 0x4026(%rip), %rdi      # 0x10dd2
movb $0x0, %al
callq 0xe4e0
movq $0x0, -0x8(%rbp)
jmp 0xcdda
jmp 0xcdbf
jmp 0xcdc1
jmp 0xcdc3
jmp 0xcdc5
jmp 0xcdc7
jmp 0xcdc9
jmp 0xcdcb
jmp 0xcdcd
jmp 0xca9e
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)