// File: /workspace/github_c_makefile_star2_O2/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 0x8de3(%rip), %rax      # 0xc5b8
cmpl $0x3, 0x40(%rax)
jne 0x3843
pushq %rbp
pushq %rbx
pushq %rax
movq (%rax), %rax
movq 0x10(%rax), %rdi
callq 0x5469
movq %rax, %rbx
pushq $0x3
popq %rdi
callq 0x371d
movq 0x8dbc(%rip), %rax      # 0xc5b8
cmpl $0x1, 0x40(%rax)
jne 0x384c
pushq $0x1
popq %rbp
movl %ebp, %edi
callq 0x371d
movq 0x8da5(%rip), %rax      # 0xc5b8
cmpl $0xc, 0x40(%rax)
jne 0x386d
cmpb $0x0, 0x46(%rax)
je 0x386d
movq (%rax), %rax
movq 0x20(%rax), %rax
movq 0x10(%rax), %rax
subq 0x7787(%rip), %rax      # 0xafb8
sarq $0x3, %rax
cmpq $0x41, %rax
je 0x3863
cmpq $0x40, %rax
je 0x3866
jmp 0x386d
xorl %edi, %edi
xorl %eax, %eax
jmp 0x328c
movq 0x98(%rax), %rdx
movq 0xa0(%rax), %rcx
leaq 0x3b9e(%rip), %rdi      # 0x73ff
jmp 0x38ab
pushq $0x2
popq %rbp
movl %ebp, %edi
callq 0x3488
movq 0x8d44(%rip), %rax      # 0xc5b8
movq 0x10(%rax), %rdi
movq %rbx, %rsi
callq 0x5c1a
testq %rax, %rax
je 0x38b7
cmpb $0x0, 0x8(%rax)
je 0x38ca
movb $0x2, 0x8(%rax)
movq 0x8d22(%rip), %rax      # 0xc5b8
movq 0x98(%rax), %rdx
movq 0xa0(%rax), %rcx
leaq 0x3b1c(%rip), %rdi      # 0x73c7
movq %rbx, %rsi
xorl %eax, %eax
callq 0x328c
jmp 0x38e3
movq 0x8cfa(%rip), %rax      # 0xc5b8
movq 0x10(%rax), %rdi
movq %rbx, %rsi
callq 0x5bac
movq 0x8ce7(%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
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x3030