// File: /workspace/github_c_makefile_star2_O0/tstword[P]MIPSAssemblerC/src/assembler.c
// Function: verify_operand_list
int verify_operand_list(struct reserved_entry *res_entry, struct operand_node *operand_list) {
    /* Check if reserved_entry is valid */
    if(res_entry->token != TOK_MNEMONIC && res_entry->token != TOK_DIRECTIVE) return 0;

    /* Verify operand list */
    struct operand_node *current_operand = operand_list;
    struct opcode_entry *entry = (struct opcode_entry *)res_entry->attrptr;

    const char *op_string = res_entry->token == TOK_DIRECTIVE ? "directive" : "mnemonic";

    for(int i = 0; i < MAX_OPERAND_COUNT; ++i) {
        if(entry->operand[i] & OPERAND_REPEAT) {
            if(current_operand == NULL || !(entry->operand[i] & current_operand->operand)) {
                report_cfg("Invalid operand combination for %s '%s' on line %ld", op_string, res_entry->id, cfg_assembler->lineno);
                return 0;
            } 
            if(current_operand->operand & OPERAND_LABEL) {
                if(get_symbol_table(cfg_assembler->symbol_table, current_operand->identifier) == NULL)
                    insert_front(cfg_assembler->decl_symlist, insert_symbol_table(cfg_assembler->symbol_table, current_operand->identifier));
            }
            
            /* Check for more operands in repeat... */
            current_operand = current_operand->next;
            while(current_operand != NULL && entry->operand[i] & current_operand->operand) {
                if(current_operand->operand & OPERAND_LABEL) {
                    if(get_symbol_table(cfg_assembler->symbol_table, current_operand->identifier) == NULL)
                        insert_front(cfg_assembler->decl_symlist, insert_symbol_table(cfg_assembler->symbol_table, current_operand->identifier));
                }
                current_operand = current_operand->next;
            }
        } else {
            if(entry->operand[i] == OPERAND_NONE) {
                if(current_operand != NULL) {
                    report_cfg("Invalid operand combiniation for %s '%s' on line %ld", op_string, res_entry->id, cfg_assembler->lineno);
                    return 0;
                }
                break;
            } else {
                if(current_operand == NULL || !(entry->operand[i] & current_operand->operand)) {
                    if(entry->operand[i] & OPERAND_OPTIONAL) continue;
                    report_cfg("Invalid operand combiniation for %s '%s' on line %ld", op_string, res_entry->id, cfg_assembler->lineno);
                    return 0;
                }
                if(current_operand->operand & OPERAND_LABEL) {
                    if(get_symbol_table(cfg_assembler->symbol_table, current_operand->identifier) == NULL)
                        insert_front(cfg_assembler->decl_symlist, insert_symbol_table(cfg_assembler->symbol_table, current_operand->identifier));
                }
            }
            current_operand = current_operand->next;
        }
    }

    if(current_operand != NULL) {
        report_cfg("Invalid operand combiniation for %s '%s' on line %ld", op_string, res_entry->id, cfg_assembler->lineno);
        return 0;
    }

    return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x8, 0x8(%rax)
je 0x4170
movq -0x10(%rbp), %rax
cmpl $0xc, 0x8(%rax)
je 0x4170
movl $0x0, -0x4(%rbp)
jmp 0x44bb
movq -0x18(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %edx
leaq 0x6517(%rip), %rax      # 0xa6a9
leaq 0x6506(%rip), %rcx      # 0xa69f
cmpl $0xc, %edx
cmoveq %rcx, %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
cmpl $0x3, -0x34(%rbp)
jge 0x447d
movq -0x28(%rbp), %rax
movslq -0x34(%rbp), %rcx
movzbl 0x3(%rax,%rcx), %eax
andl $0x20, %eax
cmpl $0x0, %eax
je 0x433d
cmpq $0x0, -0x20(%rbp)
je 0x41f0
movq -0x28(%rbp), %rax
movslq -0x34(%rbp), %rcx
movzbl 0x3(%rax,%rcx), %eax
movq -0x20(%rbp), %rcx
movzbl (%rcx), %ecx
andl %ecx, %eax
cmpl $0x0, %eax
jne 0x4223
movq -0x30(%rbp), %rsi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
movq 0xb3a6(%rip), %rax      # 0xf5a8
movq 0x98(%rax), %rcx
leaq 0x64a2(%rip), %rdi      # 0xa6b2
movb $0x0, %al
callq 0x3280
movl $0x0, -0x4(%rbp)
jmp 0x44bb
movq -0x20(%rbp), %rax
movzbl (%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x4285
movq 0xb36f(%rip), %rax      # 0xf5a8
movq 0x10(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x7ef0
cmpq $0x0, %rax
jne 0x4283
movq 0xb351(%rip), %rax      # 0xf5a8
movq 0x18(%rax), %rax
movq %rax, -0x40(%rbp)
movq 0xb342(%rip), %rax      # 0xf5a8
movq 0x10(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x7e40
movq -0x40(%rbp), %rdi
movq %rax, %rsi
callq 0x7210
jmp 0x4285
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x20(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x20(%rbp)
movb %al, -0x41(%rbp)
je 0x42bc
movq -0x28(%rbp), %rax
movslq -0x34(%rbp), %rcx
movzbl 0x3(%rax,%rcx), %eax
movq -0x20(%rbp), %rcx
movzbl (%rcx), %ecx
andl %ecx, %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x41(%rbp)
movb -0x41(%rbp), %al
testb $0x1, %al
jne 0x42c5
jmp 0x4338
movq -0x20(%rbp), %rax
movzbl (%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x4327
movq 0xb2cd(%rip), %rax      # 0xf5a8
movq 0x10(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x7ef0
cmpq $0x0, %rax
jne 0x4325
movq 0xb2af(%rip), %rax      # 0xf5a8
movq 0x18(%rax), %rax
movq %rax, -0x50(%rbp)
movq 0xb2a0(%rip), %rax      # 0xf5a8
movq 0x10(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x7e40
movq -0x50(%rbp), %rdi
movq %rax, %rsi
callq 0x7210
jmp 0x4327
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0x4291
jmp 0x446d
movq -0x28(%rbp), %rax
movslq -0x34(%rbp), %rcx
movzbl 0x3(%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x438e
cmpq $0x0, -0x20(%rbp)
je 0x4389
movq -0x30(%rbp), %rsi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
movq 0xb240(%rip), %rax      # 0xf5a8
movq 0x98(%rax), %rcx
leaq 0x6370(%rip), %rdi      # 0xa6e6
movb $0x0, %al
callq 0x3280
movl $0x0, -0x4(%rbp)
jmp 0x44bb
jmp 0x447d
cmpq $0x0, -0x20(%rbp)
je 0x43b0
movq -0x28(%rbp), %rax
movslq -0x34(%rbp), %rcx
movzbl 0x3(%rax,%rcx), %eax
movq -0x20(%rbp), %rcx
movzbl (%rcx), %ecx
andl %ecx, %eax
cmpl $0x0, %eax
jne 0x43fd
movq -0x28(%rbp), %rax
movslq -0x34(%rbp), %rcx
movzbl 0x3(%rax,%rcx), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x43ca
jmp 0x446f
movq -0x30(%rbp), %rsi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
movq 0xb1cc(%rip), %rax      # 0xf5a8
movq 0x98(%rax), %rcx
leaq 0x62fc(%rip), %rdi      # 0xa6e6
movb $0x0, %al
callq 0x3280
movl $0x0, -0x4(%rbp)
jmp 0x44bb
movq -0x20(%rbp), %rax
movzbl (%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x445f
movq 0xb195(%rip), %rax      # 0xf5a8
movq 0x10(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x7ef0
cmpq $0x0, %rax
jne 0x445d
movq 0xb177(%rip), %rax      # 0xf5a8
movq 0x18(%rax), %rax
movq %rax, -0x58(%rbp)
movq 0xb168(%rip), %rax      # 0xf5a8
movq 0x10(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x7e40
movq -0x58(%rbp), %rdi
movq %rax, %rsi
callq 0x7210
jmp 0x445f
jmp 0x4461
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0x446f
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x41ab
cmpq $0x0, -0x20(%rbp)
je 0x44b4
movq -0x30(%rbp), %rsi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
movq 0xb112(%rip), %rax      # 0xf5a8
movq 0x98(%rax), %rcx
leaq 0x6242(%rip), %rdi      # 0xa6e6
movb $0x0, %al
callq 0x3280
movl $0x0, -0x4(%rbp)
jmp 0x44bb
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)