// File: /workspace/github_c_makefile_star2_O2/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 %r12
pushq %rbx
subq $0x150, %rsp            # imm = 0x150
movl %edi, %ebx
leaq 0x7f65(%rip), %rdi      # 0x1aa3b
callq 0x12469
leaq 0x1590fe(%rip), %r14    # 0x16bbe0
leaq 0x60(%rsp), %r15
pushq $0x50
popq %r12
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0xe97a
leaq 0x7f4a(%rip), %rdi      # 0x1aa4a
callq 0x12469
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0xe97a
leaq 0x85a9(%rip), %rsi      # 0x1b0c5
leaq 0xc(%rsp), %rdx
movq %r15, %rdi
xorl %eax, %eax
callq 0x82d0
pushq $0x1
popq %r14
cmpl $0x1, %eax
jne 0x12c93
leaq 0x8586(%rip), %rsi      # 0x1b0c5
xorl %ebp, %ebp
leaq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0x82d0
cmpl $0x1, %eax
jne 0x12c93
leaq 0xa30d(%rip), %rsi      # 0x1ce6f
leaq 0xa92f(%rip), %rdx      # 0x1d498
pushq $0x2
popq %r14
leaq 0x60(%rsp), %r8
leaq 0x10(%rsp), %r9
movl %r14d, %edi
movl %ebx, %ecx
xorl %eax, %eax
callq 0x1920b
decl %ebx
cmpl $0x3, %ebx
ja 0x12bc1
leaq 0xa29f(%rip), %rax      # 0x1ce30
movslq (%rax,%rbx,4), %rcx
addq %rax, %rcx
xorl %ebx, %ebx
jmpq *%rcx
pushq $0x1
popq %rbp
movl %r14d, %ebx
jmp 0x12bc9
movl 0xc(%rsp), %ebp
decl %ebp
movl 0x8(%rsp), %ebx
decl %ebx
jmp 0x12bc9
movl 0x8(%rsp), %eax
cltd
idivl %r14d
movl %eax, %ebx
pushq $0x1
popq %rbp
jmp 0x12bc9
movl 0xc(%rsp), %ebp
movl 0x8(%rsp), %ebx
leaq 0x84f5(%rip), %r14      # 0x1b0c5
leaq 0x100(%rsp), %r15
pushq $0x50
popq %r12
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x8190
leaq 0xb0(%rsp), %rdi
movq %r12, %rsi
movq %r14, %rdx
movl %ebx, %ecx
xorl %eax, %eax
callq 0x8190
leaq 0x7e2f(%rip), %rdi      # 0x1aa3b
movq %r15, %rsi
callq 0x12413
testl %eax, %eax
je 0x12c1d
movl %eax, %r14d
jmp 0x12c93
leaq 0x7e26(%rip), %rdi      # 0x1aa4a
leaq 0xb0(%rsp), %rbx
movq %rbx, %rsi
callq 0x12413
movl %eax, %r14d
leaq 0xa231(%rip), %rsi      # 0x1ce6f
leaq 0xa883(%rip), %rdx      # 0x1d4c8
pushq $0x2
popq %rdi
leaq 0x100(%rsp), %rcx
movq %rbx, %r8
xorl %eax, %eax
callq 0x1920b
testl %r14d, %r14d
jne 0x12c93
movl $0x3d090, %edi          # imm = 0x3D090
callq 0x8400
leaq 0x7dcb(%rip), %rdi      # 0x1aa3b
leaq 0x60(%rsp), %rsi
callq 0x12413
movl %eax, %ebx
leaq 0x7dc7(%rip), %rdi      # 0x1aa4a
leaq 0x10(%rsp), %rsi
callq 0x12413
movl %eax, %r14d
orl %ebx, %r14d
movl %r14d, %eax
addq $0x150, %rsp            # imm = 0x150
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq