// File: /workspace/github_c_makefile_star2_O3/tstword[P]MIPSAssemblerC/src/assembler.c
// Function: label_cfg
void label_cfg() {
    if(cfg_assembler->lookahead == TOK_IDENTIFIER) {
        char *id = strdup_wrap(cfg_assembler->tokenizer->lexbuf);

        match_cfg(TOK_IDENTIFIER);
        
        if(cfg_assembler->lookahead == TOK_COLON) {
            match_cfg(TOK_COLON);

            if(cfg_assembler->lookahead == TOK_DIRECTIVE) {
                struct opcode_entry *entry = (struct opcode_entry *)((struct reserved_entry *)cfg_assembler->tokenizer->attrptr)->attrptr;
                
                if(cfg_assembler->auto_align) {
                    switch(entry - opcode_table) {
                        case DIRECTIVE_WORD:
                            align_segment_offset(2);
                            break;
                        case DIRECTIVE_HALF:
                            align_segment_offset(1);
                            break;
                    }
                }
            }

            struct symbol_table_entry *entry;
            if((entry = get_symbol_table(cfg_assembler->symbol_table, id)) != NULL) {
                if(entry->status != SYMBOL_UNDEFINED) {
                    entry->status = SYMBOL_DOUBLY;
                    report_cfg("Multiple definitions of label '%s' on line %ld, col %ld", id, cfg_assembler->lineno, cfg_assembler->colno);
                } 
                else {
                    entry->offset = cfg_assembler->segment_offset[cfg_assembler->segment];
                    entry->segment = cfg_assembler->segment;
                    entry->status = SYMBOL_DEFINED;
                }
            } 
            else { 
                entry = insert_symbol_table(cfg_assembler->symbol_table, id);
                entry->offset = cfg_assembler->segment_offset[cfg_assembler->segment];
                entry->segment = cfg_assembler->segment;
                entry->status = SYMBOL_DEFINED;
            }
        } 
        else {
            report_cfg("Unrecognized mnemonic '%s' on line %ld, col %ld", id, cfg_assembler->lineno, cfg_assembler->colno);
        }
        free(id);
    } else {
        report_cfg(NULL);
    }
}

// Assembly:
movq 0x89db(%rip), %rax      # 0xc5b8
cmpl $0x3, 0x40(%rax)
jne 0x3c5e
pushq %rbx
movq (%rax), %rax
movq 0x10(%rax), %rdi
callq 0x594d
movq %rax, %rbx
movl $0x3, %edi
callq 0x3b21
movq 0x89b4(%rip), %rax      # 0xc5b8
cmpl $0x1, 0x40(%rax)
jne 0x3c67
movl $0x1, %edi
callq 0x3b21
movq 0x899d(%rip), %rax      # 0xc5b8
cmpl $0xc, 0x40(%rax)
jne 0x3c95
cmpb $0x0, 0x46(%rax)
je 0x3c95
movq (%rax), %rcx
movq 0x20(%rcx), %rcx
movq 0x10(%rcx), %rcx
subq 0x737f(%rip), %rcx      # 0xafb8
sarq $0x3, %rcx
cmpq $0x40, %rcx
je 0x3c7e
cmpq $0x41, %rcx
jne 0x3c95
movzbl 0x45(%rax), %ecx
movl 0x48(%rax,%rcx,4), %edx
testb $0x3, %dl
je 0x3c95
andl $-0x4, %edx
addl $0x4, %edx
jmp 0x3c91
xorl %edi, %edi
xorl %eax, %eax
jmp 0x365c
movq 0x98(%rax), %rdx
movq 0xa0(%rax), %rcx
leaq 0x3783(%rip), %rdi      # 0x73ff
jmp 0x3ccc
movzbl 0x45(%rax), %ecx
movl 0x48(%rax,%rcx,4), %edx
testb $0x1, %dl
je 0x3c95
andl $-0x2, %edx
addl $0x2, %edx
movl %edx, 0x48(%rax,%rcx,4)
movq 0x10(%rax), %rdi
movq %rbx, %rsi
callq 0x616b
testq %rax, %rax
je 0x3cd8
cmpb $0x0, 0x8(%rax)
je 0x3ceb
movb $0x2, 0x8(%rax)
movq 0x8901(%rip), %rax      # 0xc5b8
movq 0x98(%rax), %rdx
movq 0xa0(%rax), %rcx
leaq 0x36fb(%rip), %rdi      # 0x73c7
movq %rbx, %rsi
xorl %eax, %eax
callq 0x365c
jmp 0x3d04
movq 0x88d9(%rip), %rax      # 0xc5b8
movq 0x10(%rax), %rdi
movq %rbx, %rsi
callq 0x60b1
movq 0x88c6(%rip), %rcx      # 0xc5b8
movzbl 0x45(%rcx), %edx
movl 0x48(%rcx,%rdx,4), %ecx
movl %ecx, 0xc(%rax)
movb %dl, 0x10(%rax)
movb $0x1, 0x8(%rax)
movq %rbx, %rdi
popq %rbx
jmp 0x3030