// File: /workspace/github_c_makefile_star2_O3/schroeder-lvb[P]sissm/src/api.c
// Function: apiBotRespawn
int apiBotRespawn( int resetAlgo )
{
    char botMinStr[80], botMinResetStr[80],  botMaxStr[80], botMaxResetStr[80];
    int  botMin, botMinReset, botMax, botMaxReset;
    int errCode = 1;

    // Get minimumenemies/maximumenemies strings
    // Store and convert them to integers
    //
    strlcpy( botMinStr, apiGameModePropertyGet( "minimumenemies" ), 80 );
    strlcpy( botMaxStr, apiGameModePropertyGet( "maximumenemies" ), 80 );
    if ( 1 == sscanf( botMinStr, "%d", &botMin ) ) {
        if ( 1 == sscanf( botMaxStr, "%d", &botMax ) ) {
            errCode = 0;
        }
    }

    // drop the count by algo type
    //
    if ( errCode == 0) {

        logPrintf( LOG_LEVEL_INFO, "api", "apiBotReset algo ::%d:: min/max read ::%s::%s::", resetAlgo, botMinStr, botMaxStr );

        switch( resetAlgo ) {
        case 1: 
            botMinReset = 0;  botMaxReset = 0;
            break;
        case 2:                                            // minimum value 
            botMinReset = 1;  botMaxReset = 2;
            break;
        case 3:                                            // minus-one value
            botMinReset = botMin-1;  botMaxReset = botMax-1;
            break;
        case 4:                                            // half value 
            botMinReset = 1;  botMaxReset = botMax / 2;
            break;
        default:                                           // re-write same value
            botMinReset = botMin;  botMaxReset = botMax;   
            break;
        }
   
        snprintf( botMinResetStr, 80, "%d", botMinReset );
        snprintf( botMaxResetStr, 80, "%d", botMaxReset );
        errCode = _apiGameModePropertySet( "minimumenemies", botMinResetStr );
        if ( 0 == errCode )  {
            errCode = _apiGameModePropertySet( "maximumenemies", botMaxResetStr );
            logPrintf( LOG_LEVEL_INFO, "api", "apiBotReset min/max to ::%s::%s::", botMinResetStr, botMaxResetStr );
        }
        
    }

    // slight delay
    //
    if ( errCode == 0 ) 
        usleep( 250000 );   // 250,000us = 100ms = 0.25s
 
    // Restore minimumenemies/maximumenemies
    //
    if ( errCode == 0 ) {
        errCode |= _apiGameModePropertySet( "minimumenemies", botMinStr );
        errCode |= _apiGameModePropertySet( "maximumenemies", botMaxStr );
    }

    return( errCode );
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x158, %rsp            # imm = 0x158
movl %edi, %ebx
leaq 0x81c8(%rip), %rdi      # 0x1ba3b
callq 0x131f2
leaq 0x158361(%rip), %r14    # 0x16bbe0
leaq 0x60(%rsp), %r15
movl $0x50, %edx
movq %r15, %rdi
movq %r14, %rsi
callq 0xf384
leaq 0x81af(%rip), %rdi      # 0x1ba4a
callq 0x131f2
leaq 0x10(%rsp), %rdi
movl $0x50, %edx
movq %r14, %rsi
callq 0xf384
leaq 0x880c(%rip), %rsi      # 0x1c0c5
leaq 0xc(%rsp), %rdx
movq %r15, %rdi
xorl %eax, %eax
callq 0x82d0
movl $0x1, %r14d
cmpl $0x1, %eax
jne 0x13a36
leaq 0x87e7(%rip), %rsi      # 0x1c0c5
xorl %ebp, %ebp
leaq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0x82d0
cmpl $0x1, %eax
jne 0x13a36
leaq 0xa57e(%rip), %rsi      # 0x1de7f
leaq 0xaba0(%rip), %rdx      # 0x1e4a8
leaq 0x60(%rsp), %r8
leaq 0x10(%rsp), %r9
movl $0x2, %edi
movl %ebx, %ecx
xorl %eax, %eax
callq 0x1a3e3
decl %ebx
cmpl $0x3, %ebx
ja 0x13962
leaq 0xa512(%rip), %rax      # 0x1de40
movslq (%rax,%rbx,4), %rcx
addq %rax, %rcx
xorl %ebx, %ebx
jmpq *%rcx
movl $0x2, %ebx
jmp 0x1395b
movl 0xc(%rsp), %ebp
decl %ebp
movl 0x8(%rsp), %ebx
decl %ebx
jmp 0x1396a
movl 0x8(%rsp), %eax
movl %eax, %ebx
shrl $0x1f, %ebx
addl %eax, %ebx
sarl %ebx
movl $0x1, %ebp
jmp 0x1396a
movl 0xc(%rsp), %ebp
movl 0x8(%rsp), %ebx
leaq 0x8754(%rip), %r14      # 0x1c0c5
leaq 0x100(%rsp), %r15
movl $0x50, %esi
movq %r15, %rdi
movq %r14, %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x8190
leaq 0xb0(%rsp), %rdi
movl $0x50, %esi
movq %r14, %rdx
movl %ebx, %ecx
xorl %eax, %eax
callq 0x8190
leaq 0x808e(%rip), %rdi      # 0x1ba3b
movq %r15, %rsi
callq 0x1319a
testl %eax, %eax
je 0x139be
movl %eax, %r14d
jmp 0x13a36
leaq 0x8085(%rip), %rdi      # 0x1ba4a
leaq 0xb0(%rsp), %rbx
movq %rbx, %rsi
callq 0x1319a
movl %eax, %r14d
leaq 0xa4a0(%rip), %rsi      # 0x1de7f
leaq 0xaaf2(%rip), %rdx      # 0x1e4d8
leaq 0x100(%rsp), %rcx
movl $0x2, %edi
movq %rbx, %r8
xorl %eax, %eax
callq 0x1a3e3
testl %r14d, %r14d
jne 0x13a36
movl $0x3d090, %edi          # imm = 0x3D090
callq 0x83f0
leaq 0x8028(%rip), %rdi      # 0x1ba3b
leaq 0x60(%rsp), %rsi
callq 0x1319a
movl %eax, %ebx
leaq 0x8024(%rip), %rdi      # 0x1ba4a
leaq 0x10(%rsp), %rsi
callq 0x1319a
movl %eax, %r14d
orl %ebx, %r14d
movl %r14d, %eax
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r14
popq %r15
popq %rbp
retq