// File: /workspace/github_cpp_makefile_star2_O1/Fohlen[P]cubescript-standalone/command.cpp
// Function: sortlist(char*, ident*, ident*, unsigned int*)
void sortlist(char *list, ident *x, ident *y, uint *body)
{
    if(x == y || x->type != ID_ALIAS || y->type != ID_ALIAS) return;

    vector<sortitem> items;
    int macrolen = strlen(list), total = 0;
    char *macros = newstring(list, macrolen);
    const char *curlist = list, *start, *end, *quotestart, *quoteend;
    while(parselist(curlist, start, end, quotestart, quoteend))
    {
        macros[end - list] = '\0';
        sortitem item = { &macros[start - list], quotestart, quoteend };
        items.add(item);
        total += int(quoteend - quotestart);
    } 

    identstack xstack, ystack;
    pusharg(*x, nullval, xstack); x->flags &= ~IDF_UNKNOWN;
    pusharg(*y, nullval, ystack); y->flags &= ~IDF_UNKNOWN;

    sortfun f = { x, y, body };
    items.sort(f);

    poparg(*x);
    poparg(*y);
    
    char *sorted = macros;
    int sortedlen = total + max(items.length() - 1, 0);
    if(macrolen < sortedlen)
    {
        delete[] macros;
        sorted = newstring(sortedlen);
    }

    int offset = 0;
    loopv(items)
    {
        sortitem &item = items[i];
        int len = int(item.quoteend - item.quotestart);
        if(i) sorted[offset++] = ' ';
        memcpy(&sorted[offset], item.quotestart, len);
        offset += len;
    }
    sorted[offset] = '\0';
 
    commandret->setstr(sorted);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
cmpq %rdx, %rsi
je 0xc43e
cmpl $0x4, (%rsi)
jne 0xc43e
movq %rdx, %r12
cmpl $0x4, (%rdx)
jne 0xc43e
movq %rdi, %r15
movq %rcx, -0x98(%rbp)
movq %rsi, -0x48(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x40(%rbp)
callq 0x2080
movq %rax, %r13
movslq %r13d, %r14
incq %r14
movq %r14, %rdi
callq 0x152b1
movq %r13, -0x90(%rbp)
incq %r13
cmpq %r14, %r13
cmovaeq %r14, %r13
movq %rax, %r14
movq %rax, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x2130
movq %r14, %rbx
movb $0x0, -0x1(%r14,%r13)
leaq -0xa0(%rbp), %rdi
movq %r15, (%rdi)
leaq -0x68(%rbp), %rsi
leaq -0x60(%rbp), %rdx
leaq -0x58(%rbp), %rcx
leaq -0x50(%rbp), %r8
callq 0xa23b
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
testb %al, %al
je 0xc1a8
movq %r12, -0x88(%rbp)
xorl %r14d, %r14d
movq -0x60(%rbp), %rax
subq %r15, %rax
movb $0x0, (%rbx,%rax)
movq -0x68(%rbp), %rax
subq %r15, %rax
addq %rbx, %rax
movq %rax, -0x80(%rbp)
movq -0x58(%rbp), %r13
movq %r13, -0x78(%rbp)
movq -0x50(%rbp), %r12
movq %r12, -0x70(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x1287a
subl %r13d, %r12d
addl %r12d, %r14d
leaq -0xa0(%rbp), %rdi
leaq -0x68(%rbp), %rsi
leaq -0x60(%rbp), %rdx
leaq -0x58(%rbp), %rcx
leaq -0x50(%rbp), %r8
callq 0xa23b
testb %al, %al
jne 0xc142
decl %r14d
movq -0x88(%rbp), %r12
movq -0x48(%rbp), %r13
movq 0x20(%r13), %rax
leaq -0xd0(%rbp), %rcx
movq %rax, (%rcx)
movl 0x10(%r13), %eax
movl %eax, 0x8(%rcx)
movq 0x28(%r13), %rax
movq %rax, 0x10(%rcx)
movq %rcx, 0x28(%r13)
movl 0x124d5(%rip), %eax     # 0x1e6a8
movl %eax, 0x10(%r13)
movq 0x124c2(%rip), %rax     # 0x1e6a0
movq %rax, 0x20(%r13)
movq 0x18(%r13), %rax
testq %rax, %rax
je 0xc20a
addl $0xffffff00, (%rax)     # imm = 0xFFFFFF00
movq 0x18(%r13), %rdi
cmpl $0xff, (%rdi)
jg 0xc202
callq 0x152d7
movq $0x0, 0x18(%r13)
andb $-0x21, 0x38(%r13)
movq 0x20(%r12), %rax
leaq -0xb8(%rbp), %rcx
movq %rax, (%rcx)
movl 0x10(%r12), %eax
movl %eax, 0x8(%rcx)
movq 0x28(%r12), %rax
movq %rax, 0x10(%rcx)
movq %rcx, 0x28(%r12)
movl 0x1246e(%rip), %eax     # 0x1e6a8
movl %eax, 0x10(%r12)
movq 0x1245a(%rip), %rax     # 0x1e6a0
movq %rax, 0x20(%r12)
movq 0x18(%r12), %rax
testq %rax, %rax
je 0xc276
addl $0xffffff00, (%rax)     # imm = 0xFFFFFF00
movq 0x18(%r12), %rdi
cmpl $0xff, (%rdi)
jg 0xc26d
callq 0x152d7
movq $0x0, 0x18(%r12)
andb $-0x21, 0x38(%r12)
movq %r13, -0x80(%rbp)
movq %r12, -0x78(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x40(%rbp), %rdi
movslq -0x34(%rbp), %rax
leaq (%rax,%rax,2), %rax
leaq (%rdi,%rax,8), %rsi
movq -0x70(%rbp), %rax
movq %rax, 0x10(%rsp)
movups -0x80(%rbp), %xmm0
movups %xmm0, (%rsp)
callq 0x12193
movq 0x28(%r13), %r15
testq %r15, %r15
je 0xc312
cmpl $0x3, 0x10(%r13)
jne 0xc2d3
movq 0x20(%r13), %rdi
testq %rdi, %rdi
je 0xc2d3
callq 0x152d7
movl 0x8(%r15), %eax
movl %eax, 0x10(%r13)
movq (%r15), %rax
movq %rax, 0x20(%r13)
movq 0x18(%r13), %rax
testq %rax, %rax
je 0xc30a
addl $0xffffff00, (%rax)     # imm = 0xFFFFFF00
movq 0x18(%r13), %rdi
cmpl $0xff, (%rdi)
jg 0xc302
callq 0x152d7
movq $0x0, 0x18(%r13)
movq 0x10(%r15), %rax
movq %rax, 0x28(%r13)
movq 0x28(%r12), %r15
testq %r15, %r15
je 0xc378
cmpl $0x3, 0x10(%r12)
jne 0xc333
movq 0x20(%r12), %rdi
testq %rdi, %rdi
je 0xc333
callq 0x152d7
movl 0x8(%r15), %eax
movl %eax, 0x10(%r12)
movq (%r15), %rax
movq %rax, 0x20(%r12)
movq 0x18(%r12), %rax
testq %rax, %rax
je 0xc36f
addl $0xffffff00, (%rax)     # imm = 0xFFFFFF00
movq 0x18(%r12), %rdi
cmpl $0xff, (%rdi)
jg 0xc366
callq 0x152d7
movq $0x0, 0x18(%r12)
movq 0x10(%r15), %rax
movq %rax, 0x28(%r12)
movl -0x34(%rbp), %eax
cmpl $0x2, %eax
movl $0x1, %ecx
cmovgel %eax, %ecx
addl %ecx, %r14d
cmpl -0x90(%rbp), %r14d
jle 0xc3aa
movq %rbx, %rdi
callq 0x152d7
movslq %r14d, %rdi
incq %rdi
callq 0x152b1
movq %rax, %r12
jmp 0xc3ad
movq %rbx, %r12
movslq -0x34(%rbp), %rcx
xorl %r14d, %r14d
testq %rcx, %rcx
jle 0xc40d
movq -0x40(%rbp), %r15
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rcx
movq %rcx, -0x48(%rbp)
xorl %r13d, %r13d
movq 0x10(%r15,%r13), %rdx
subq 0x8(%r15,%r13), %rdx
testq %r13, %r13
je 0xc3e6
movslq %r14d, %rcx
incl %r14d
movb $0x20, (%r12,%rcx)
movslq %r14d, %rbx
leaq (%r12,%rbx), %rdi
movq 0x8(%r15,%r13), %rsi
movslq %edx, %r14
movq %r14, %rdx
callq 0x2130
addl %ebx, %r14d
addq $0x18, %r13
cmpq %r13, -0x48(%rbp)
jne 0xc3cc
movslq %r14d, %r14
movb $0x0, (%r12,%r14)
movq 0x11def(%rip), %rcx     # 0x1e208
movl $0x3, 0x8(%rcx)
movq %r12, (%rcx)
cmpl $0x0, -0x34(%rbp)
jle 0xc430
movl $0x0, -0x34(%rbp)
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0xc43e
callq 0x152d7
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xc456
jmp 0xc456
jmp 0xc456
movq %rax, %rbx
cmpl $0x0, -0x34(%rbp)
jle 0xc466
movl $0x0, -0x34(%rbp)
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0xc474
callq 0x152d7
movq %rbx, %rdi
callq 0x23a0