// File: /workspace/github_c_makefile_star2_O2/Ziddykins[P]Dawn/src/cmdsys.c
// Function: invoke_cmd
void invoke_cmd(CmdSys cs, int pindex, char * cmd, struct Message * msg, int mode) {
    struct cmd_sys * ccs = cs ? cs : commands;
    assert(ccs && msg && cmd);
    assert(ccs->flags == CMD_FINALIZED);

    char * out;
    CALLEXIT(!(out = malloc(MAX_MESSAGE_BUFFER+175)))
    if (pindex == -1 && strcmp(cmd, ";new") != 0) {
        sprintf(out, "PRIVMSG %s :Please create a new account by issuing ';new'\r\n", msg->receiver);
        add_msg(out, strlen(out));
    } else {
        size_t cmdID = get_cmd_id(ccs, cmd);
        if(cmdID == (size_t)(-1)) {
            if(mode == CMD_EXEC) {
                snprintf(out, MAX_MESSAGE_BUFFER, "PRIVMSG %s :Unknown command. Please use ';help'\r\n", msg->receiver);
            } else {
                snprintf(out, MAX_MESSAGE_BUFFER, "PRIVMSG %s :Command does not exist.\r\n", msg->receiver);
            }
            add_msg(out, strlen(out));
            //printf("%s", out);
        } else {
            if(mode == CMD_EXEC) {
                if(dawn->players[pindex].auth_level >= ccs->auth_levels[cmdID]) {
                    ccs->fn[cmdID](pindex, msg);
                } else {
                    snprintf(out, MAX_MESSAGE_BUFFER, "PRIVMSG %s :You are not authorized to issue this command!\r\n", msg->receiver);
                    add_msg(out, strlen(out));
                }
            } else if(mode == CMD_HELP) {
                snprintf(out, MAX_MESSAGE_BUFFER, "PRIVMSG %s :'%s': %s\r\n", msg->receiver, ccs->cmds[cmdID], ccs->helptexts[cmdID]);
                add_msg(out, strlen(out));
            }
        }
    }
    free(out);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %r8d, %r12d
movq %rcx, %r14
movq %rdx, %r13
movl %esi, %ebp
movq %rdi, %r15
testq %rdi, %rdi
jne 0x3581
movq 0x19cf7(%rip), %r15     # 0x1d278
testq %r13, %r13
je 0x36e6
testq %r14, %r14
je 0x36e6
testq %r15, %r15
je 0x36e6
cmpq $0x4, 0x38(%r15)
jne 0x36ff
movl $0x23f, %edi            # imm = 0x23F
callq 0x22c0
testq %rax, %rax
je 0x371c
movq %rax, %rbx
cmpl $-0x1, %ebp
je 0x361f
movq %r15, %rdi
movq %r13, %rsi
callq 0x3730
cmpq $-0x1, %rax
je 0x364f
cmpl $0x1, %r12d
je 0x367f
testl %r12d, %r12d
jne 0x36c2
leaq 0x1c493(%rip), %rcx     # 0x1fa80
movq (%rcx), %rcx
movslq %ebp, %rdx
imulq $0x26a8, %rdx, %rdx     # imm = 0x26A8
movzbl 0x2840(%rcx,%rdx), %ecx
movq 0x28(%r15), %rdx
cmpl %ecx, (%rdx,%rax,4)
jle 0x36d8
addq $0xc0, %r14
leaq 0xd12a(%rip), %rdx      # 0x10747
jmp 0x366b
leaq 0xd088(%rip), %rsi      # 0x106ae
movq %r13, %rdi
callq 0x22e0
testl %eax, %eax
je 0x35c2
addq $0xc0, %r14
leaq 0xd073(%rip), %rsi      # 0x106b3
movq %rbx, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2050
jmp 0x36af
addq $0xc0, %r14
testl %r12d, %r12d
leaq 0xd08f(%rip), %rax      # 0x106ef
leaq 0xd0ba(%rip), %rdx      # 0x10721
cmoveq %rax, %rdx
movl $0x190, %esi            # imm = 0x190
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x23a0
jmp 0x36af
addq $0xc0, %r14
movq 0x18(%r15), %rcx
movq 0x20(%r15), %rdx
movq (%rcx,%rax,8), %r8
movq (%rdx,%rax,8), %r9
leaq 0xd0e6(%rip), %rdx      # 0x10783
movl $0x190, %esi            # imm = 0x190
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x23a0
movq %rbx, %rdi
callq 0x20c0
movq %rbx, %rdi
movq %rax, %rsi
callq 0xbd04
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2250
movq 0x30(%r15), %rcx
movl %ebp, %edi
movq %r14, %rsi
callq *(%rcx,%rax,8)
jmp 0x36c2
leaq 0xcf0b(%rip), %rdi      # 0x105f8
leaq 0xcbf0(%rip), %rsi      # 0x102e4
leaq 0xcf0f(%rip), %rcx      # 0x1060a
pushq $0x5e
jmp 0x3716
leaq 0xcf40(%rip), %rdi      # 0x10646
leaq 0xcbd7(%rip), %rsi      # 0x102e4
leaq 0xcef6(%rip), %rcx      # 0x1060a
pushq $0x5f
popq %rdx
callq 0x2100
leaq 0xcf3f(%rip), %rdi      # 0x10662
callq 0x2190
pushq $0x1
popq %rdi
callq 0x2270