// File: /workspace/github_c_makefile_star2_O1/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 0x427e
movq 0x1affa(%rip), %r15     # 0x1f278
testq %r13, %r13
je 0x43e3
testq %r14, %r14
je 0x43e3
testq %r15, %r15
je 0x43e3
cmpq $0x4, 0x38(%r15)
jne 0x4402
movl $0x23f, %edi            # imm = 0x23F
callq 0x22b0
testq %rax, %rax
je 0x4421
movq %rax, %rbx
cmpl $-0x1, %ebp
je 0x431c
movq %r15, %rdi
movq %r13, %rsi
callq 0x4426
cmpq $-0x1, %rax
je 0x434c
cmpl $0x1, %r12d
je 0x437c
testl %r12d, %r12d
jne 0x43bf
leaq 0x1d796(%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 0x43d5
addq $0xc0, %r14
leaq 0xd42d(%rip), %rdx      # 0x11747
jmp 0x4368
leaq 0xd38b(%rip), %rsi      # 0x116ae
movq %r13, %rdi
callq 0x22d0
testl %eax, %eax
je 0x42bf
addq $0xc0, %r14
leaq 0xd376(%rip), %rsi      # 0x116b3
movq %rbx, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2050
jmp 0x43ac
addq $0xc0, %r14
testl %r12d, %r12d
leaq 0xd392(%rip), %rax      # 0x116ef
leaq 0xd3bd(%rip), %rdx      # 0x11721
cmoveq %rax, %rdx
movl $0x190, %esi            # imm = 0x190
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x2390
jmp 0x43ac
addq $0xc0, %r14
movq 0x18(%r15), %rcx
movq 0x20(%r15), %rdx
movq (%rcx,%rax,8), %r8
movq (%rdx,%rax,8), %r9
leaq 0xd3e9(%rip), %rdx      # 0x11783
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 0xcd1c
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 0x43bf
leaq 0xd20e(%rip), %rdi      # 0x115f8
leaq 0xcef3(%rip), %rsi      # 0x112e4
leaq 0xd212(%rip), %rcx      # 0x1160a
movl $0x5e, %edx
callq 0x2100
leaq 0xd23d(%rip), %rdi      # 0x11646
leaq 0xced4(%rip), %rsi      # 0x112e4
leaq 0xd1f3(%rip), %rcx      # 0x1160a
movl $0x5f, %edx
callq 0x2100
callq 0x2669