// File: /workspace/github_c_makefile_star2_O3/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 0x4311
movq 0x1af67(%rip), %r15     # 0x1f278
testq %r13, %r13
je 0x4476
testq %r14, %r14
je 0x4476
testq %r15, %r15
je 0x4476
cmpq $0x4, 0x38(%r15)
jne 0x4495
movl $0x23f, %edi            # imm = 0x23F
callq 0x22b0
testq %rax, %rax
je 0x44b4
movq %rax, %rbx
cmpl $-0x1, %ebp
je 0x43af
movq %r15, %rdi
movq %r13, %rsi
callq 0x44b9
cmpq $-0x1, %rax
je 0x43df
cmpl $0x1, %r12d
je 0x440f
testl %r12d, %r12d
jne 0x4452
leaq 0x1d703(%rip), %rcx     # 0x21a80
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 0x4468
addq $0xc0, %r14
leaq 0xd3ce(%rip), %rdx      # 0x1177b
jmp 0x43fb
leaq 0xd32c(%rip), %rsi      # 0x116e2
movq %r13, %rdi
callq 0x22d0
testl %eax, %eax
je 0x4352
addq $0xc0, %r14
leaq 0xd317(%rip), %rsi      # 0x116e7
movq %rbx, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2050
jmp 0x443f
addq $0xc0, %r14
testl %r12d, %r12d
leaq 0xd333(%rip), %rax      # 0x11723
leaq 0xd35e(%rip), %rdx      # 0x11755
cmoveq %rax, %rdx
movl $0x190, %esi            # imm = 0x190
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x2390
jmp 0x443f
addq $0xc0, %r14
movq 0x18(%r15), %rcx
movq 0x20(%r15), %rdx
movq (%rcx,%rax,8), %r8
movq (%rdx,%rax,8), %r9
leaq 0xd38a(%rip), %rdx      # 0x117b7
movl $0x190, %esi            # imm = 0x190
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x2390
movq %rbx, %rdi
callq 0x20c0
movq %rbx, %rdi
movq %rax, %rsi
callq 0xcefe
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2240
movq 0x30(%r15), %rcx
movl %ebp, %edi
movq %r14, %rsi
callq *(%rcx,%rax,8)
jmp 0x4452
leaq 0xd1af(%rip), %rdi      # 0x1162c
leaq 0xce94(%rip), %rsi      # 0x11318
leaq 0xd1b3(%rip), %rcx      # 0x1163e
movl $0x5e, %edx
callq 0x2100
leaq 0xd1de(%rip), %rdi      # 0x1167a
leaq 0xce75(%rip), %rsi      # 0x11318
leaq 0xd194(%rip), %rcx      # 0x1163e
movl $0x5f, %edx
callq 0x2100
callq 0x2669