// File: /workspace/github_c_makefile_star2_O0/Ziddykins[P]Dawn/src/cmdsys.c
// Function: sort_cmd_sys
void sort_cmd_sys(CmdSys cs) {
    size_t const SHIFT = 4;
    uint64_t const BITMASK = (1<<SHIFT)-1;
    unsigned short const HASH_BITLEN = 64;

    struct cmd_sys * ccs = cs ? cs : commands;
    assert(ccs);
    assert(ccs->capacity == ccs->len);
    if(ccs->len <= 1) {
        return;
    }

    size_t * positions;
    CALLEXIT(!(positions = malloc(ccs->len * sizeof *positions)))
    for(size_t i = 0; i < ccs->len; i++) {
        positions[i] = i;
    }

    size_t * buckets;
    CALLEXIT(!(buckets = malloc(ccs->len * (BITMASK+1) * sizeof *buckets))) //actually a 2d array

    size_t * idx;
    CALLEXIT(!(idx = calloc(BITMASK+1, sizeof *idx)))

    size_t bitmask = BITMASK;
    for(size_t i = 0; i < HASH_BITLEN / SHIFT; i++) {

        for(size_t j = 0; j < ccs->len; j++) {
            size_t pos = positions[j];
            size_t bucket = (ccs->hashes[pos] & bitmask) >> (i*SHIFT);

            buckets[ccs->len * bucket + idx[bucket]] = pos;
            idx[bucket]++;
        }

        size_t c = 0;
        for(size_t j = 0; j <= BITMASK; j++) {
            for(size_t k = 0; k < idx[j]; k++) {
                positions[c] = buckets[ccs->len * j + k];
                c++;
            }
            idx[j] = 0;
        }
        bitmask <<= SHIFT;
    }

    free(buckets);
    free(idx);

    uint64_t * hashes;
    CALLEXIT(!(hashes = calloc(ccs->len, sizeof *ccs->hashes)))
    char ** cmds;
    CALLEXIT(!(cmds = calloc(ccs->len, sizeof *ccs->cmds)))
    char ** helptexts;
    CALLEXIT(!(helptexts = calloc(ccs->len, sizeof *ccs->helptexts)))
    int * auth_levels;
    CALLEXIT(!(auth_levels = calloc(ccs->len, sizeof *ccs->auth_levels)))
    cmd_func *fn;
    CALLEXIT(!(fn = calloc(ccs->len, sizeof *ccs->fn)))

    for(size_t i = 0; i < ccs->len; i++) {
        hashes[i] = ccs->hashes[i];
        cmds[i] = ccs->cmds[i];
        helptexts[i] = ccs->helptexts[i];
        auth_levels[i] = ccs->auth_levels[i];
        fn[i] = ccs->fn[i];
    }

    for(size_t i = 0; i < ccs->len; i++) {
        ccs->hashes[i] = hashes[positions[i]];
        ccs->cmds[i] = cmds[positions[i]];
        ccs->helptexts[i] = helptexts[positions[i]];
        ccs->auth_levels[i] = auth_levels[positions[i]];
        ccs->fn[i] = fn[positions[i]];
    }

    free(hashes);
    free(cmds);
    free(helptexts);
    free(auth_levels);
    free(fn);
    free(positions);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x8(%rbp)
movq $0x4, -0x10(%rbp)
movq $0xf, -0x18(%rbp)
movw $0x40, -0x1a(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x3a99
movq -0x8(%rbp), %rax
movq %rax, -0xc8(%rbp)
jmp 0x3aa7
movq 0x227c8(%rip), %rax     # 0x26268
movq %rax, -0xc8(%rbp)
movq -0xc8(%rbp), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x3abb
jmp 0x3ada
leaq 0x1681e(%rip), %rdi     # 0x1a2e0
leaq 0x1681b(%rip), %rsi     # 0x1a2e4
movl $0x88, %edx
leaq 0x16cc5(%rip), %rcx     # 0x1a79a
callq 0x2100
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x28(%rbp), %rcx
cmpq (%rcx), %rax
jne 0x3aed
jmp 0x3b0c
leaq 0x16cc0(%rip), %rdi     # 0x1a7b4
leaq 0x167e9(%rip), %rsi     # 0x1a2e4
movl $0x89, %edx
leaq 0x16c93(%rip), %rcx     # 0x1a79a
callq 0x2100
movq -0x28(%rbp), %rax
cmpq $0x1, (%rax)
ja 0x3b1b
jmp 0x40aa
movq -0x28(%rbp), %rax
movq (%rax), %rdi
shlq $0x3, %rdi
callq 0x22b0
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
jne 0x3b4b
leaq 0x16c92(%rip), %rdi     # 0x1a7ce
callq 0x2190
movl $0x1, %edi
callq 0x2260
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x28(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x3b7e
movq -0x38(%rbp), %rdx
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x3b53
movq -0x28(%rbp), %rax
movq (%rax), %rdi
shlq $0x4, %rdi
shlq $0x3, %rdi
callq 0x22b0
movq %rax, -0x40(%rbp)
cmpq $0x0, %rax
jne 0x3bb2
leaq 0x16c84(%rip), %rdi     # 0x1a827
callq 0x2190
movl $0x1, %edi
callq 0x2260
movl $0x10, %edi
movl $0x8, %esi
callq 0x2110
movq %rax, -0x48(%rbp)
cmpq $0x0, %rax
jne 0x3be1
leaq 0x16cb8(%rip), %rdi     # 0x1a88a
callq 0x2190
movl $0x1, %edi
callq 0x2260
movq $0xf, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
cmpq $0x10, -0x58(%rbp)
jae 0x3d4d
movq $0x0, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq -0x28(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x3c8d
movq -0x30(%rbp), %rax
movq -0x60(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x68(%rbp)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x68(%rbp), %rcx
movq (%rax,%rcx,8), %rax
andq -0x50(%rbp), %rax
movq -0x58(%rbp), %rcx
shlq $0x2, %rcx
shrq %cl, %rax
movq %rax, -0x70(%rbp)
movq -0x68(%rbp), %rdx
movq -0x40(%rbp), %rax
movq -0x28(%rbp), %rcx
movq (%rcx), %rcx
imulq -0x70(%rbp), %rcx
movq -0x48(%rbp), %rsi
movq -0x70(%rbp), %rdi
addq (%rsi,%rdi,8), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x48(%rbp), %rax
movq -0x70(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
addq $0x1, %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x3c04
movq $0x0, -0x78(%rbp)
movq $0x0, -0x80(%rbp)
cmpq $0xf, -0x80(%rbp)
ja 0x3d30
movq $0x0, -0x88(%rbp)
movq -0x88(%rbp), %rax
movq -0x48(%rbp), %rcx
movq -0x80(%rbp), %rdx
cmpq (%rcx,%rdx,8), %rax
jae 0x3d0f
movq -0x40(%rbp), %rax
movq -0x28(%rbp), %rcx
movq (%rcx), %rcx
imulq -0x80(%rbp), %rcx
addq -0x88(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x30(%rbp), %rax
movq -0x78(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x78(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x78(%rbp)
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0x3cb3
movq -0x48(%rbp), %rax
movq -0x80(%rbp), %rcx
movq $0x0, (%rax,%rcx,8)
movq -0x80(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
jmp 0x3c9d
movq -0x50(%rbp), %rax
shlq $0x4, %rax
movq %rax, -0x50(%rbp)
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x3bf1
movq -0x40(%rbp), %rdi
callq 0x2240
movq -0x48(%rbp), %rdi
callq 0x2240
movq -0x28(%rbp), %rax
movq (%rax), %rdi
movl $0x8, %esi
callq 0x2110
movq %rax, -0x90(%rbp)
cmpq $0x0, %rax
jne 0x3d93
leaq 0x16b53(%rip), %rdi     # 0x1a8d7
callq 0x2190
movl $0x1, %edi
callq 0x2260
movq -0x28(%rbp), %rax
movq (%rax), %rdi
movl $0x8, %esi
callq 0x2110
movq %rax, -0x98(%rbp)
cmpq $0x0, %rax
jne 0x3dc7
leaq 0x16b76(%rip), %rdi     # 0x1a92e
callq 0x2190
movl $0x1, %edi
callq 0x2260
movq -0x28(%rbp), %rax
movq (%rax), %rdi
movl $0x8, %esi
callq 0x2110
movq %rax, -0xa0(%rbp)
cmpq $0x0, %rax
jne 0x3dfb
leaq 0x16b95(%rip), %rdi     # 0x1a981
callq 0x2190
movl $0x1, %edi
callq 0x2260
movq -0x28(%rbp), %rax
movq (%rax), %rdi
movl $0x4, %esi
callq 0x2110
movq %rax, -0xa8(%rbp)
cmpq $0x0, %rax
jne 0x3e2f
leaq 0x16bbe(%rip), %rdi     # 0x1a9de
callq 0x2190
movl $0x1, %edi
callq 0x2260
movq -0x28(%rbp), %rax
movq (%rax), %rdi
movl $0x8, %esi
callq 0x2110
movq %rax, -0xb0(%rbp)
cmpq $0x0, %rax
jne 0x3e63
leaq 0x16beb(%rip), %rdi     # 0x1aa3f
callq 0x2190
movl $0x1, %edi
callq 0x2260
movq $0x0, -0xb8(%rbp)
movq -0xb8(%rbp), %rax
movq -0x28(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x3f50
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq -0xb8(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x90(%rbp), %rax
movq -0xb8(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movq -0xb8(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x98(%rbp), %rax
movq -0xb8(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
movq -0xb8(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0xa0(%rbp), %rax
movq -0xb8(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rax
movq -0xb8(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq -0xa8(%rbp), %rax
movq -0xb8(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rax
movq -0xb8(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0xb0(%rbp), %rax
movq -0xb8(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0xb8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xb8(%rbp)
jmp 0x3e6e
movq $0x0, -0xc0(%rbp)
movq -0xc0(%rbp), %rax
movq -0x28(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x4065
movq -0x90(%rbp), %rax
movq -0x30(%rbp), %rcx
movq -0xc0(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq -0xc0(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x98(%rbp), %rax
movq -0x30(%rbp), %rcx
movq -0xc0(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movq -0xc0(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0xa0(%rbp), %rax
movq -0x30(%rbp), %rcx
movq -0xc0(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
movq -0xc0(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0xa8(%rbp), %rax
movq -0x30(%rbp), %rcx
movq -0xc0(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movl (%rax,%rcx,4), %edx
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rax
movq -0xc0(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0xb0(%rbp), %rax
movq -0x30(%rbp), %rcx
movq -0xc0(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rax
movq -0xc0(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0xc0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xc0(%rbp)
jmp 0x3f5b
movq -0x90(%rbp), %rdi
callq 0x2240
movq -0x98(%rbp), %rdi
callq 0x2240
movq -0xa0(%rbp), %rdi
callq 0x2240
movq -0xa8(%rbp), %rdi
callq 0x2240
movq -0xb0(%rbp), %rdi
callq 0x2240
movq -0x30(%rbp), %rdi
callq 0x2240
addq $0xd0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)