// File: /workspace/github_c_makefile_star2_O0/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:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq 0xbb49(%rip), %rax      # 0xf5a8
cmpl $0x3, 0x40(%rax)
jne 0x3c3d
movq 0xbb38(%rip), %rax      # 0xf5a8
movq (%rax), %rax
movq 0x10(%rax), %rdi
callq 0x71a0
movq %rax, -0x8(%rbp)
movl $0x3, %edi
callq 0x3900
movq 0xbb17(%rip), %rax      # 0xf5a8
cmpl $0x1, 0x40(%rax)
jne 0x3c04
movl $0x1, %edi
callq 0x3900
movq 0xbafc(%rip), %rax      # 0xf5a8
cmpl $0xc, 0x40(%rax)
jne 0x3b19
movq 0xbaef(%rip), %rax      # 0xf5a8
movq (%rax), %rax
movq 0x20(%rax), %rax
movq 0x10(%rax), %rax
movq %rax, -0x10(%rbp)
movq 0xbad9(%rip), %rax      # 0xf5a8
cmpb $0x0, 0x46(%rax)
je 0x3b17
movq -0x10(%rbp), %rax
leaq 0xa5f0(%rip), %rcx      # 0xe0d0
subq %rcx, %rax
sarq $0x3, %rax
movq %rax, -0x20(%rbp)
subq $0x40, %rax
je 0x3b0b
jmp 0x3af3
movq -0x20(%rbp), %rax
subq $0x41, %rax
jne 0x3b15
jmp 0x3aff
movl $0x2, %edi
callq 0x3570
jmp 0x3b15
movl $0x1, %edi
callq 0x3570
jmp 0x3b17
jmp 0x3b19
movq 0xba88(%rip), %rax      # 0xf5a8
movq 0x10(%rax), %rdi
movq -0x8(%rbp), %rsi
callq 0x7ef0
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
je 0x3bb4
movq -0x18(%rbp), %rax
movzbl 0x8(%rax), %eax
cmpl $0x0, %eax
je 0x3b7c
movq -0x18(%rbp), %rax
movb $0x2, 0x8(%rax)
movq -0x8(%rbp), %rsi
movq 0xba51(%rip), %rax      # 0xf5a8
movq 0x98(%rax), %rdx
movq 0xba43(%rip), %rax      # 0xf5a8
movq 0xa0(%rax), %rcx
leaq 0x6a34(%rip), %rdi      # 0xa5a7
movb $0x0, %al
callq 0x3280
jmp 0x3bb2
movq 0xba25(%rip), %rax      # 0xf5a8
movq 0xba1e(%rip), %rcx      # 0xf5a8
movzbl 0x45(%rcx), %ecx
movl 0x48(%rax,%rcx,4), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0xc(%rax)
movq 0xba08(%rip), %rax      # 0xf5a8
movb 0x45(%rax), %cl
movq -0x18(%rbp), %rax
movb %cl, 0x10(%rax)
movq -0x18(%rbp), %rax
movb $0x1, 0x8(%rax)
jmp 0x3c02
movq 0xb9ed(%rip), %rax      # 0xf5a8
movq 0x10(%rax), %rdi
movq -0x8(%rbp), %rsi
callq 0x7e40
movq %rax, -0x18(%rbp)
movq 0xb9d5(%rip), %rax      # 0xf5a8
movq 0xb9ce(%rip), %rcx      # 0xf5a8
movzbl 0x45(%rcx), %ecx
movl 0x48(%rax,%rcx,4), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0xc(%rax)
movq 0xb9b8(%rip), %rax      # 0xf5a8
movb 0x45(%rax), %cl
movq -0x18(%rbp), %rax
movb %cl, 0x10(%rax)
movq -0x18(%rbp), %rax
movb $0x1, 0x8(%rax)
jmp 0x3c32
movq -0x8(%rbp), %rsi
movq 0xb999(%rip), %rax      # 0xf5a8
movq 0x98(%rax), %rdx
movq 0xb98b(%rip), %rax      # 0xf5a8
movq 0xa0(%rax), %rcx
leaq 0x69b4(%rip), %rdi      # 0xa5df
movb $0x0, %al
callq 0x3280
movq -0x8(%rbp), %rdi
callq 0x3030
jmp 0x3c48
xorl %eax, %eax
movl %eax, %edi
movb $0x0, %al
callq 0x3280
addq $0x20, %rsp
popq %rbp
retq
nop