// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x330, %rsp            # imm = 0x330
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x1, -0x328(%rbp)
movl $0x0, -0x32c(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x122b0
leaq -0x220(%rbp), %rdi
callq 0x122b0
leaq -0x320(%rbp), %rdi
callq 0x122b0
movq -0x8(%rbp), %rdi
xorl %esi, %esi
leaq 0x161a0(%rip), %rdx     # 0x24158
callq 0x122d0
movq %rax, %rcx
movq %rcx, -0x18(%rbp)
xorl %eax, %eax
cmpq %rcx, %rax
je 0xdfe0
leaq -0x120(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x11bc0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
leaq 0x16168(%rip), %rdx     # 0x24158
callq 0x122d0
movq %rax, %rcx
movq %rcx, -0x18(%rbp)
xorl %eax, %eax
cmpq %rcx, %rax
je 0xe018
leaq -0x220(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x11bc0
movq -0x8(%rbp), %rdi
movl $0x2, %esi
leaq 0x16130(%rip), %rdx     # 0x24158
callq 0x122d0
movq %rax, %rcx
movq %rcx, -0x18(%rbp)
xorl %eax, %eax
cmpq %rcx, %rax
je 0xe050
leaq -0x320(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x11bc0
leaq -0x120(%rbp), %rsi
leaq 0x15d0c(%rip), %rdi     # 0x23d6a
callq 0x8200
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0xe0b1
leaq -0x220(%rbp), %rdi
callq 0x8110
movq %rax, %rcx
xorl %eax, %eax
cmpq %rcx, %rax
jne 0xe0b1
leaq -0x220(%rbp), %rdi
leaq -0x120(%rbp), %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x11bc0
leaq -0x120(%rbp), %rdi
leaq 0x15cc3(%rip), %rsi     # 0x23d6a
movl $0x100, %edx            # imm = 0x100
callq 0x11bc0
movq -0x10(%rbp), %rdi
callq 0xe2b0
movl $0x0, -0x324(%rbp)
movslq -0x324(%rbp), %rax
leaq 0x2213e(%rip), %rdi     # 0x30210
imulq $0x70, %rax, %rax
addq %rax, %rdi
leaq -0x120(%rbp), %rsi
callq 0x8200
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0xe11e
movslq -0x324(%rbp), %rax
leaq 0x22115(%rip), %rdi     # 0x30210
imulq $0x70, %rax, %rax
addq %rax, %rdi
addq $0x14, %rdi
leaq -0x120(%rbp), %rsi
callq 0x8200
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0xe1eb
movl $0x1, -0x32c(%rbp)
movq -0x10(%rbp), %rdi
movslq -0x324(%rbp), %rax
leaq 0x220d6(%rip), %rsi     # 0x30210
imulq $0x70, %rax, %rax
addq %rax, %rsi
addq $0x14, %rsi
callq 0x18320
cmpl $0x0, %eax
jne 0xe189
movq -0x10(%rbp), %rcx
movq -0x8(%rbp), %r8
movl $0x2, %edi
leaq 0x15b24(%rip), %rsi     # 0x23c87
leaq 0x16517(%rip), %rdx     # 0x24681
movb $0x0, %al
callq 0x21bf0
leaq 0x2e7c8(%rip), %rdi     # 0x3c940
addq $0x2804, %rdi           # imm = 0x2804
callq 0xe2e0
jmp 0xe22a
movslq -0x324(%rbp), %rcx
leaq 0x22079(%rip), %rax     # 0x30210
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movq 0x68(%rax), %rcx
leaq -0x220(%rbp), %rdi
leaq -0x320(%rbp), %rsi
movq -0x8(%rbp), %rdx
movb $0x0, %al
callq *%rcx
movl %eax, -0x328(%rbp)
cmpl $0x0, -0x328(%rbp)
jne 0xe1e9
movq -0x10(%rbp), %rcx
movq -0x8(%rbp), %r8
movl $0x2, %edi
leaq 0x15aac(%rip), %rsi     # 0x23c87
leaq 0x164c8(%rip), %rdx     # 0x246aa
movb $0x0, %al
callq 0x21bf0
jmp 0xe22a
movl -0x324(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x324(%rbp)
movslq -0x324(%rbp), %rax
leaq 0x22008(%rip), %rdi     # 0x30210
imulq $0x70, %rax, %rax
addq %rax, %rdi
leaq 0x159e6(%rip), %rsi     # 0x23bfc
callq 0x8200
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0xe225
jmp 0xe22a
jmp 0xe0c4
cmpl $0x0, -0x32c(%rbp)
jne 0xe290
movq -0x10(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x18470
cmpl $0x0, %eax
je 0xe28e
leaq -0x120(%rbp), %rdi
leaq 0x154bb(%rip), %rdx     # 0x23711
movq %rdx, %rsi
callq 0xa3b0
cmpl $0x0, -0x328(%rbp)
jne 0xe28c
movq -0x10(%rbp), %rcx
leaq -0x120(%rbp), %r8
movl $0x2, %edi
leaq 0x15a09(%rip), %rsi     # 0x23c87
leaq 0x16445(%rip), %rdx     # 0x246ca
movb $0x0, %al
callq 0x21bf0
jmp 0xe28e
jmp 0xe290
leaq 0x16451(%rip), %rdi     # 0x246e8
callq 0xe2b0
movl -0x328(%rbp), %eax
addq $0x330, %rsp            # imm = 0x330
popq %rbp
retq
nopl (%rax,%rax)