// File: /workspace/github_c_makefile_star2_O1/schroeder-lvb[P]sissm/src/picladmin.c
// Function: cmdMap
int _cmdMap( char *arg, char *arg2, char *passThru )
{
    int errCode = 0;
    int isNight = 0, isIns = 0, clearMutators = 0;
    char *w, gameMode[80], wordBuf[80], mutName[80];
    char mutatorsList[256];
    int i, j, c;

    strclr( mutatorsList );
    strclr( gameMode );

    if ( 0 == strlen( arg ) ) {
        apiSaySys( "You must specify a map.  Type !maplist");
        errCode = 1;
    }
    else {
        //
        // Walk through each word to determine if it is "ins", "sec", 
        // "day", "night" or any of the approved mutators or game modes.
        // The check order may be important in the future.
        //
        j = 2;
        while ( errCode == 0 ) {

            w = getWord( passThru, j++, " " );
            if ( w == NULL )       break;
            if ( 0 == strlen( w )) break;
         
            strlcpy( wordBuf, w, 80 );

            // alias 
            //
            if ( 0 == strcasecmp( wordBuf, "hardcore" )) strlcpy( wordBuf, "checkpointhardcore", 80 );

            // process each word
            //
            if ( 0 == strcmp( wordBuf, "@" ) ) 
                clearMutators = 1;
            else if (NULL != strcasestr( wordBuf, "night" )) 
                isNight = 1;
            else if (NULL != strcasestr( wordBuf, "ins"   )) 
                isIns   = 1;
            else if ( apiIsSupportedGameMode( wordBuf ) ) {
                strlcpy( gameMode, wordBuf, 80 );
            }
            else {
                c = apiMutLookup( wordBuf, mutName, 80 );
                switch (c) {
                    case 0:
                        apiSaySys("Unknown game mode or mutator '%s'", wordBuf );
                        logPrintf(  LOG_LEVEL_INFO, "picladmin", "Unknown game mode or mutator '%s'", wordBuf );
                        errCode = 1;
                        break;
                    case 1:
                        strlcat( mutatorsList, mutName, 256 );
                        strlcat( mutatorsList, ",",     256 );
                        break;
                    default:
                        apiSaySys("Ambiguious mutator name '%s'", wordBuf );
                        logPrintf(  LOG_LEVEL_INFO, "picladmin", "Ambiguious mutator name '%s'", wordBuf );
                        errCode = 1;
                        break;
                }
            }
        }

        // clean up the mutatorsList (remove trailing comma)
        //
        if ( 0 != ( i = (int) strlen( mutatorsList ) )) {
            mutatorsList[ i-1 ] = 0;
        }

        if ( 0 == errCode ) {
            // change map
            logPrintf(  LOG_LEVEL_INFO, "picladmin", "----------------------------------------------------" );
            logPrintf(  LOG_LEVEL_INFO, "picladmin", "Map change to '%s' Mode '%s'  Sec/Ins '%d' Day/Night '%d'", arg, gameMode, isIns, isNight );
            logPrintf(  LOG_LEVEL_INFO, "picladmin", "Mutators: '%s'  clear: %d", mutatorsList, clearMutators );
            errCode = apiMapChange( arg, gameMode, isIns, isNight, mutatorsList, clearMutators );
        }

        if ( errCode ) {
            apiSaySys( "Map/mode/side/mutator not found" );
        }
    }
    return errCode;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x218, %rsp            # imm = 0x218
movq %rdx, %r12
movq %rdi, %rbx
leaq 0x110(%rsp), %rdi
callq 0xf4dd
leaq 0x70(%rsp), %rdi
callq 0xf4dd
cmpb $0x0, (%rbx)
je 0xb912
movq %rbx, 0x18(%rsp)
leaq 0x109e7(%rip), %rdx     # 0x1c156
movq %r12, %rdi
movl $0x2, %esi
callq 0xf4e1
movb $0x1, %r14b
testq %rax, %rax
je 0xb923
movl $0x0, 0x14(%rsp)
movl $0x3, %r15d
leaq 0x20(%rsp), %r13
movl $0x0, 0x10(%rsp)
xorl %ebp, %ebp
cmpb $0x0, (%rax)
je 0xb935
movl $0x50, %edx
movq %r13, %rdi
movq %rax, %rsi
callq 0xf038
movq %r13, %rdi
leaq 0x10837(%rip), %rsi     # 0x1bfff
callq 0x8060
testl %eax, %eax
jne 0xb7e5
movups 0x1081d(%rip), %xmm0    # 0x1bff5
movaps %xmm0, 0x20(%rsp)
movl $0x65726f, 0x2f(%rsp)   # imm = 0x65726F
movb $0x1, %r14b
cmpw $0x40, 0x20(%rsp)
jne 0xb7fd
movl $0x1, 0x14(%rsp)
jmp 0xb8e9
movq %r13, %rdi
leaq 0x107cb(%rip), %rsi     # 0x1bfd2
callq 0x8350
testq %rax, %rax
je 0xb81b
movl $0x1, %ebp
jmp 0xb8e9
movq %r13, %rdi
leaq 0x107b4(%rip), %rsi     # 0x1bfd9
callq 0x8350
testq %rax, %rax
je 0xb83c
movl $0x1, 0x10(%rsp)
jmp 0xb8e9
movq %r13, %rdi
callq 0x13b3f
testl %eax, %eax
je 0xb85f
movl $0x50, %edx
leaq 0x70(%rsp), %rdi
movq %r13, %rsi
callq 0xf038
jmp 0xb8e9
movq %r13, %rdi
leaq 0xc0(%rsp), %rsi
movl $0x50, %edx
callq 0x13d98
cmpl $0x1, %eax
je 0xb889
xorl %r14d, %r14d
testl %eax, %eax
jne 0xb8bc
leaq 0x10781(%rip), %rbx     # 0x1c008
jmp 0xb8c3
movl $0x100, %edx            # imm = 0x100
leaq 0x110(%rsp), %rbx
movq %rbx, %rdi
leaq 0xc0(%rsp), %rsi
callq 0xefc4
movl $0x100, %edx            # imm = 0x100
movq %rbx, %rdi
leaq 0x13110(%rip), %rsi     # 0x1e9c5
callq 0xefc4
jmp 0xb8e9
leaq 0x10767(%rip), %rbx     # 0x1c02a
movq %rbx, %rdi
movq %r13, %rsi
xorl %eax, %eax
callq 0x1316b
movl $0x2, %edi
leaq 0x103ab(%rip), %rsi     # 0x1bc87
movq %rbx, %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0x1a227
testb %r14b, %r14b
je 0xb935
leal 0x1(%r15), %ebx
movq %r12, %rdi
movl %r15d, %esi
leaq 0x10857(%rip), %rdx     # 0x1c156
callq 0xf4e1
movl %ebx, %r15d
testq %rax, %rax
jne 0xb7a5
jmp 0xb935
movl $0x1, %ebx
leaq 0x1068c(%rip), %rdi     # 0x1bfaa
jmp 0xb9fa
movl $0x0, 0x14(%rsp)
movl $0x0, 0x10(%rsp)
xorl %ebp, %ebp
leaq 0x110(%rsp), %rdi
callq 0x8120
testl %eax, %eax
je 0xb952
decl %eax
cltq
movb $0x0, 0x110(%rsp,%rax)
movl $0x1, %ebx
testb $0x1, %r14b
je 0xb9ef
leaq 0x1031f(%rip), %rbx     # 0x1bc87
leaq 0x106d8(%rip), %rdx     # 0x1c047
movl $0x2, %edi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x1a227
movl %ebp, (%rsp)
leaq 0x106f4(%rip), %rdx     # 0x1c07c
leaq 0x70(%rsp), %r14
movl $0x2, %edi
movq %rbx, %rsi
movq 0x18(%rsp), %r12
movq %r12, %rcx
movq %r14, %r8
movl 0x10(%rsp), %r13d
movl %r13d, %r9d
xorl %eax, %eax
callq 0x1a227
leaq 0x10700(%rip), %rdx     # 0x1c0b6
leaq 0x110(%rsp), %r15
movl $0x2, %edi
movq %rbx, %rsi
movq %r15, %rcx
movl 0x14(%rsp), %ebx
movl %ebx, %r8d
xorl %eax, %eax
callq 0x1a227
movq %r12, %rdi
movq %r14, %rsi
movl %r13d, %edx
movl %ebp, %ecx
movq %r15, %r8
movl %ebx, %r9d
callq 0x13b83
movl %eax, %ebx
testl %ebx, %ebx
je 0xba03
leaq 0x106d6(%rip), %rdi     # 0x1c0d0
xorl %eax, %eax
callq 0x1316b
jmp 0xba05
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq