// File: /workspace/github_c_makefile_star2_O3/schroeder-lvb[P]sissm/src/picladmin.c
// Function: commandExecute
int _commandExecute( char *cmdString, char *originID ) 
{   
    char *p, cmdOut[256], arg1Out[256], arg2Out[256];
    int i, errCode = 1;
    int isCommand = 0;

    // zero the physical stores
    //
    strclr( cmdOut );  strclr( arg1Out );  strclr( arg2Out );

    // The input string cmdString will be in the format, e.g., "botfixed 30"
    // parse command vs arguments and invoke the string-matched function 
    //
    if ( NULL != (p = getWord( cmdString, 0, " " ) )) strlcpy( cmdOut,  p, 256);
    if ( NULL != (p = getWord( cmdString, 1, " " ) )) strlcpy( arg1Out, p, 256);
    if ( NULL != (p = getWord( cmdString, 2, " " ) )) strlcpy( arg2Out, p, 256);

    // Handle special 'help' case for when no argument is specified
    // 
    if ( (0 == strcmp("help", cmdOut)) && (0 == strlen( arg1Out )) ) {
        strlcpy( arg1Out, cmdOut, 256 );
        strlcpy( cmdOut, "help",  256 );
    } 

    // remember the origin ID for some command that may need it (e.g., !help)
    //
    _setOriginID( originID );

    // loop through the command table
    //
    i = 0;
    while ( 1==1 ) {

        if ( (0 == strcmp( cmdTable[i].cmdShort, cmdOut )) || (0 == strcmp( cmdTable[i].cmdLong, cmdOut )) ) {

            isCommand = 1;

            // check if this admin has enough privilege to execute this command
            //
            if ( ! apiAuthIsAllowedCommand( originID, cmdTable[i].cmdLong ) ) {
                logPrintf( LOG_LEVEL_INFO, "picladmin", "Insufficient priv for [%s] to execute %s", originID, cmdString );
                _respSay( picladminConfig.msgInvalid );                       // unauthorized message
                break;
            }

            // execute the command
            //
            errCode = (*cmdTable[i].cmdFunction)( arg1Out, arg2Out, cmdString );
            if ( errCode == 0 ) {
                logPrintf( LOG_LEVEL_INFO, "picladmin", "Admin [%s] executed command: %s", originID, cmdString );
            }
            break;
        }
        i++;
        if ( 0==strcmp( cmdTable[i].cmdShort, "*") )
            break;
    }

    // check if the command was not in standard commands table -- if not
    // it may be a operator added macro.
    // 
    if ( !isCommand ) {

        // check if this admin has enough privilege to execute this command
        //
        if ( apiAuthIsAllowedMacro( originID, cmdOut ) ) {
        
            // execute the macro
            //
            _cmdMacros( cmdOut, "", "" );
            if ( errCode == 0 ) {
                logPrintf( LOG_LEVEL_INFO, "picladmin", "Admin [%s] executed macro: %s", originID, cmdOut );
            }
        }
    }

    // Command level security - set ident to invalid
    //
    _setOriginID( "INVALID" );

    return errCode; 
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x300, %rsp            # imm = 0x300
movq %rsi, %rbx
movq %rdi, %r14
movq %rsp, %rdi
callq 0xf829
leaq 0x100(%rsp), %rdi
callq 0xf829
leaq 0x200(%rsp), %rdi
callq 0xf829
leaq 0xf720(%rip), %rdx      # 0x1c14e
movq %r14, %rdi
xorl %esi, %esi
callq 0xf82d
testq %rax, %rax
je 0xca4d
movq %rsp, %rdi
movl $0x100, %edx            # imm = 0x100
movq %rax, %rsi
callq 0xf384
leaq 0xf6fa(%rip), %rdx      # 0x1c14e
movq %r14, %rdi
movl $0x1, %esi
callq 0xf82d
testq %rax, %rax
je 0xca7b
leaq 0x100(%rsp), %rdi
movl $0x100, %edx            # imm = 0x100
movq %rax, %rsi
callq 0xf384
leaq 0xf6cc(%rip), %rdx      # 0x1c14e
movq %r14, %rdi
movl $0x2, %esi
callq 0xf82d
testq %rax, %rax
je 0xcaa9
leaq 0x200(%rsp), %rdi
movl $0x100, %edx            # imm = 0x100
movq %rax, %rsi
callq 0xf384
movl $0x706c6568, %eax       # imm = 0x706C6568
xorl (%rsp), %eax
movzbl 0x4(%rsp), %ecx
orl %eax, %ecx
jne 0xcae8
cmpb $0x0, 0x100(%rsp)
jne 0xcae8
leaq 0x100(%rsp), %rdi
movq %rsp, %r15
movl $0x100, %edx            # imm = 0x100
movq %r15, %rsi
callq 0xf384
movl $0x706c6568, (%r15)     # imm = 0x706C6568
movb $0x0, 0x4(%r15)
leaq 0x51281(%rip), %rdi     # 0x5dd70
movl $0x100, %edx            # imm = 0x100
movq %rbx, %rsi
callq 0xf384
leaq 0x1b71d(%rip), %r15     # 0x28220
movq %rsp, %rsi
movq %r15, %rdi
callq 0x8220
testl %eax, %eax
je 0xcb54
leaq 0x1b777(%rip), %r15     # 0x28290
movq %rsp, %r12
leaq -0x5c(%r15), %rdi
movq %r12, %rsi
callq 0x8220
testl %eax, %eax
je 0xcb50
cmpb $0x2a, (%r15)
jne 0xcb3d
cmpb $0x0, 0x1(%r15)
je 0xcc32
movq %r15, %rdi
movq %r12, %rsi
callq 0x8220
addq $0x70, %r15
testl %eax, %eax
jne 0xcb1c
addq $-0x70, %r15
leaq 0x14(%r15), %rsi
movq %rbx, %rdi
callq 0x13a5b
testl %eax, %eax
je 0xcbab
leaq 0x100(%rsp), %rdi
leaq 0x200(%rsp), %rsi
movq %r14, %rdx
xorl %eax, %eax
callq *0x68(%r15)
movl %eax, %ebp
testl %eax, %eax
jne 0xcc0f
leaq 0xf0f1(%rip), %rsi      # 0x1bc7f
leaq 0xfb0b(%rip), %rdx      # 0x1c6a0
movl $0x2, %edi
movq %rbx, %rcx
movq %r14, %r8
xorl %eax, %eax
callq 0x1a3e3
xorl %ebp, %ebp
jmp 0xcc0f
leaq 0xf0cd(%rip), %rsi      # 0x1bc7f
leaq 0xfabe(%rip), %rdx      # 0x1c677
movl $0x2, %edi
movq %rbx, %rcx
movq %r14, %r8
xorl %eax, %eax
callq 0x1a3e3
callq 0x83c0
cltq
imulq $0x66666667, %rax, %rcx # imm = 0x66666667
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x21, %rcx
addl %edx, %ecx
leal (%rcx,%rcx,4), %ecx
subl %ecx, %eax
cltq
shlq $0xa, %rax
leaq 0x27d48(%rip), %rcx     # 0x34940
leaq (%rax,%rcx), %rdi
addq $0x2804, %rdi           # imm = 0x2804
xorl %eax, %eax
callq 0x134e5
movl $0x1, %ebp
movabsq $0x44494c41564e49, %rax # imm = 0x44494C41564E49
movq %rax, 0x51150(%rip)     # 0x5dd70
movl %ebp, %eax
addq $0x300, %rsp            # imm = 0x300
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x13b4c
movl $0x1, %ebp
testl %eax, %eax
je 0xcc0f
movq %rsp, %rdi
callq 0x9a88
jmp 0xcc0f