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

    if(ccs->capacity == 0) {
        CALLEXIT(!(ccs->hashes = calloc(1, sizeof *ccs->hashes)))
        CALLEXIT(!(ccs->cmds = calloc(1, sizeof *ccs->cmds)))
        CALLEXIT(!(ccs->helptexts = calloc(1, sizeof *ccs->helptexts)))
        CALLEXIT(!(ccs->auth_levels = calloc(1, sizeof *ccs->auth_levels)))
        CALLEXIT(!(ccs->fn = calloc(1, sizeof *ccs->fn)))
        ccs->capacity = 1;
    }

    if(ccs->len >= ccs->capacity) {
        ccs->capacity *= 2;
        trim_arrays(ccs);
    }

    ccs->hashes[ccs->len] = hash_code(cmd);

    size_t len = strlen(cmd) + 1;
    assert(len < MAX_MESSAGE_BUFFER);
    CALLEXIT(!(ccs->cmds[ccs->len] = calloc(len+1, 1)))
    strncpy(ccs->cmds[ccs->len], cmd, len);

    len = strlen(helptext);
    assert(len < MAX_MESSAGE_BUFFER);
    CALLEXIT(!(ccs->helptexts[ccs->len] = calloc(len+1, 1)))
    strncpy(ccs->helptexts[ccs->len], helptext, len);

    ccs->auth_levels[ccs->len] = auth_level;
    ccs->fn[ccs->len] = fn;

    ccs->len++;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %r8, %rbx
movl %ecx, %ebp
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r14
testq %rdi, %rdi
jne 0x2e6b
movq 0x1a40d(%rip), %r14     # 0x1d278
movq %r14, %xmm0
movq %r12, %xmm1
punpcklqdq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0]
movq %rbx, %xmm0
movq %r15, %xmm2
punpcklqdq %xmm0, %xmm2    # xmm2 = xmm2[0],xmm0[0]
pxor %xmm0, %xmm0
pcmpeqd %xmm0, %xmm2
pcmpeqd %xmm0, %xmm1
movdqa %xmm1, %xmm0
shufps $0xdd, %xmm2, %xmm0     # xmm0 = xmm0[1,3],xmm2[1,3]
shufps $0x88, %xmm2, %xmm1     # xmm1 = xmm1[0,2],xmm2[0,2]
andps %xmm0, %xmm1
movmskps %xmm1, %eax
testl %eax, %eax
jne 0x302d
movq $0x2, 0x38(%r14)
movq 0x8(%r14), %r13
testq %r13, %r13
jne 0x2f46
pushq $0x1
popq %rdi
pushq $0x8
popq %rsi
callq 0x2110
movq %rax, 0x10(%r14)
testq %rax, %rax
je 0x308e
pushq $0x1
popq %rdi
pushq $0x8
popq %rsi
callq 0x2110
movq %rax, 0x18(%r14)
testq %rax, %rax
je 0x3097
pushq $0x1
popq %rdi
pushq $0x8
popq %rsi
callq 0x2110
movq %rax, 0x20(%r14)
testq %rax, %rax
je 0x30a0
pushq $0x1
popq %rdi
pushq $0x4
popq %rsi
callq 0x2110
movq %rax, 0x28(%r14)
testq %rax, %rax
je 0x30a9
pushq $0x1
popq %r13
pushq $0x8
popq %rsi
movq %r13, %rdi
callq 0x2110
movq %rax, 0x30(%r14)
testq %rax, %rax
je 0x30b2
movq $0x1, 0x8(%r14)
cmpq %r13, (%r14)
jb 0x2f5a
addq %r13, %r13
movq %r13, 0x8(%r14)
movq %r14, %rdi
callq 0x30c6
movq %r12, %rdi
callq 0x3182
movq (%r14), %rcx
movq 0x10(%r14), %rdx
movq %rax, (%rdx,%rcx,8)
movq %r12, %rdi
callq 0x20c0
leaq 0x1(%rax), %r13
cmpq $0x190, %r13            # imm = 0x190
jae 0x3046
addq $0x2, %rax
pushq $0x1
popq %rsi
movq %rax, %rdi
callq 0x2110
movq (%r14), %rcx
movq 0x18(%r14), %rdx
movq %rax, (%rdx,%rcx,8)
testq %rax, %rax
je 0x305f
movq 0x18(%r14), %rax
movq (%rax,%rcx,8), %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x20e0
movq %r15, %rdi
callq 0x20c0
cmpq $0x190, %rax            # imm = 0x190
jae 0x3068
movq %rax, %r12
leaq 0x1(%rax), %rdi
pushq $0x1
popq %rsi
callq 0x2110
movq (%r14), %rcx
movq 0x20(%r14), %rdx
movq %rax, (%rdx,%rcx,8)
testq %rax, %rax
je 0x3085
movq 0x20(%r14), %rax
movq (%rax,%rcx,8), %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x20e0
movq (%r14), %rax
movq 0x28(%r14), %rcx
movl %ebp, (%rcx,%rax,4)
movq 0x30(%r14), %rcx
movq %rbx, (%rcx,%rax,8)
incq %rax
movq %rax, (%r14)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xd2d7(%rip), %rdi      # 0x1030b
leaq 0xd2a9(%rip), %rsi      # 0x102e4
leaq 0xd2e6(%rip), %rcx      # 0x10328
pushq $0x2e
jmp 0x307f
leaq 0xd4d3(%rip), %rdi      # 0x10520
leaq 0xd290(%rip), %rsi      # 0x102e4
leaq 0xd2cd(%rip), %rcx      # 0x10328
pushq $0x42
jmp 0x307f
leaq 0xd4d3(%rip), %rdi      # 0x10539
jmp 0x30b9
leaq 0xd4b1(%rip), %rdi      # 0x10520
leaq 0xd26e(%rip), %rsi      # 0x102e4
leaq 0xd2ab(%rip), %rcx      # 0x10328
pushq $0x47
popq %rdx
callq 0x2100
leaq 0xd4fb(%rip), %rdi      # 0x10587
jmp 0x30b9
leaq 0xd2e3(%rip), %rdi      # 0x10378
jmp 0x30b9
leaq 0xd32e(%rip), %rdi      # 0x103cc
jmp 0x30b9
leaq 0xd375(%rip), %rdi      # 0x1041c
jmp 0x30b9
leaq 0xd3c6(%rip), %rdi      # 0x10476
jmp 0x30b9
leaq 0xd41b(%rip), %rdi      # 0x104d4
callq 0x2190
pushq $0x1
popq %rdi
callq 0x2270