// File: /workspace/github_c_makefile_star2_O3/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 0x3b1a
movq 0x1b75e(%rip), %r14     # 0x1f278
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 0x3cf6
movq $0x2, 0x38(%r14)
movq 0x8(%r14), %r13
testq %r13, %r13
jne 0x3c0b
movl $0x1, %edi
movl $0x8, %esi
callq 0x2110
movq %rax, 0x10(%r14)
testq %rax, %rax
je 0x3d5d
movl $0x1, %edi
movl $0x8, %esi
callq 0x2110
movq %rax, 0x18(%r14)
testq %rax, %rax
je 0x3d62
movl $0x1, %edi
movl $0x8, %esi
callq 0x2110
movq %rax, 0x20(%r14)
testq %rax, %rax
je 0x3d67
movl $0x1, %edi
movl $0x4, %esi
callq 0x2110
movq %rax, 0x28(%r14)
testq %rax, %rax
je 0x3d6c
movl $0x1, %r13d
movl $0x1, %edi
movl $0x8, %esi
callq 0x2110
movq %rax, 0x30(%r14)
testq %rax, %rax
je 0x3d71
movq $0x1, 0x8(%r14)
cmpq %r13, (%r14)
jb 0x3c1f
addq %r13, %r13
movq %r13, 0x8(%r14)
movq %r14, %rdi
callq 0x3d76
movq %r12, %rdi
callq 0x3e32
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 0x3d15
addq $0x2, %rax
movl $0x1, %esi
movq %rax, %rdi
callq 0x2110
movq (%r14), %rcx
movq 0x18(%r14), %rdx
movq %rax, (%rdx,%rcx,8)
testq %rax, %rax
je 0x3d34
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 0x3d39
movq %rax, %r12
leaq 0x1(%rax), %rdi
movl $0x1, %esi
callq 0x2110
movq (%r14), %rcx
movq 0x20(%r14), %rdx
movq %rax, (%rdx,%rcx,8)
testq %rax, %rax
je 0x3d58
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 0xd642(%rip), %rdi      # 0x1133f
leaq 0xd614(%rip), %rsi      # 0x11318
leaq 0xd651(%rip), %rcx      # 0x1135c
movl $0x2e, %edx
callq 0x2100
leaq 0xd838(%rip), %rdi      # 0x11554
leaq 0xd5f5(%rip), %rsi      # 0x11318
leaq 0xd632(%rip), %rcx      # 0x1135c
movl $0x42, %edx
callq 0x2100
callq 0x2543
leaq 0xd814(%rip), %rdi      # 0x11554
leaq 0xd5d1(%rip), %rsi      # 0x11318
leaq 0xd60e(%rip), %rcx      # 0x1135c
movl $0x47, %edx
callq 0x2100
callq 0x252e
callq 0x25ac
callq 0x2597
callq 0x2582
callq 0x256d
callq 0x2558