// File: /workspace/github_c_makefile_star2_O1/schroeder-lvb[P]sissm/src/api.c
// Function: apiMapcycleRead
int apiMapcycleRead( char *mapcycleFile )
{
    FILE *fpr;
    int   i, j;
    char  tmpLine[256], lastMapName[256], lastReqName[256];
    char  *w, *w2, *v, *u, scenarioName[256];

    strclr( lastMapName );
    for (i = 0; i<API_MAXMAPS; i++) {
        strclr( mapCycleList[i].mapName );
        strclr( mapCycleList[i].reqName );
        strclr( mapCycleList[i].scenario );
        strclr( mapCycleList[i].traveler );
        strclr( mapCycleList[i].gameMode );
        mapCycleList[i].dayNight =  0;
        mapCycleList[i].secIns   = -1;

        strclr( mapNameMerged[i] );
    }

#if DELME
    // mutator meta:  #SISSM.allowmutator, and #SISSM.defaultmutator
    //
    strclr( mutAllowed );
    strclr( mutDefault );
#endif

    i = 0;
    if ( NULL != (fpr = fopen( mapcycleFile, "rt" ))) {
        while ( !feof( fpr ) ) {
            if (NULL != fgets( tmpLine, 255, fpr )) {

                // part 1:  parse the "#SISSM.mapname" line
                //
                // printf("\nDEBUG - reading %s", tmpLine );
                if ( tmpLine == strcasestr( tmpLine, "#SISSM.mapname" )) {
                    if ( NULL != (w = getWord( tmpLine, 1, "= ,;:\015\012" ))) {
                        strlcpy( lastMapName, w, 256 );
                        strlcpy( lastReqName, w, 256 );
                        if ( NULL != (w2 = getWord( tmpLine, 2, "= ,;:\015\012" ))) {
                            if (0 != strlen( w2 )) strlcpy( lastReqName, w2, 256 );
                        }
                        // printf("\nDEBUG - reading map name ::%s::", lastMapName );

                        // create a merged list for "maplist" command
                        //
                        for ( j = 0; j<API_MAXMAPS; j++ ) {
                            if ( 0 == strcasecmp( mapNameMerged[j], lastReqName ) ) 
                                break;
                            if ( 0 == strlen( mapNameMerged[j] ) ) {
                                strlcpy( mapNameMerged[j], lastReqName, 40 ); 
                                break;
                            }
                        }
                    }
                }

                // part 2:  parse the scenario name and the game mode (checkpoint, hardcorecheckpoint, etc.)
                //
                else if ( tmpLine == strcasestr( tmpLine, "(Scenario=\"" )) {

                    strlcpy( scenarioName,  getWord( tmpLine, 1, "=\"" ), 255 );

                    if ( (0 != strlen( scenarioName )) && (0 != strlen( lastMapName )) )  {
                        strlcpy( mapCycleList[i].scenario, scenarioName, 256 );
                        strlcpy( mapCycleList[i].mapName,  lastMapName,  256 );
                        strlcpy( mapCycleList[i].reqName,  lastReqName,  256 );
                        strlcpy( mapCycleList[i].traveler, lastMapName,  256 );
                        strncat( mapCycleList[i].traveler, "?Scenario=", 256 );
                        strncat( mapCycleList[i].traveler, scenarioName, 128 );

                        // parse the gamemode
                        //
                        if ( NULL != ( v = strcasestr( tmpLine, "mode=\"" )  )) {
                            if ( NULL != (u = getWord( v, 1, "\"" )) ) {
                                strncat( mapCycleList[i].traveler, "?Game=", 256 );
                                strncat( mapCycleList[i].traveler, u,        172 );
                                strlcpy( mapCycleList[i].gameMode, u,         40 );
                            }
                        }

                        // parse the day/night
                        //
                        if ( NULL != strcasestr( tmpLine, "lighting=\"night\"" )) { 
                            mapCycleList[i].dayNight = 1;
                            strncat( mapCycleList[i].traveler, "?Lighting=Night", 256 );
                        }
                        else {
                            strncat( mapCycleList[i].traveler, "?Lighting=Day", 256 );
                        }

                        mapCycleList[i].secIns = -1;
                        if ( NULL != strcasestr( scenarioName, "insurgent"  )) 
                            mapCycleList[i].secIns = 1;
                        if ( NULL != strcasestr( scenarioName, "security"   )) 
                            mapCycleList[i].secIns = 0;
 
                        logPrintf( LOG_LEVEL_INFO, "api", "Mapcycle %03d tag %s traveler ::Sec/Ins:%1d Day/Night:%1d ::%s:: GameMode ::%s::", 
                            i,
                            mapCycleList[i].reqName,  mapCycleList[i].secIns,  mapCycleList[i].dayNight, 
                            mapCycleList[i].traveler, mapCycleList[i].gameMode );

                        if ( ++i >= API_MAXMAPS ) break; 

                    }
                }

#if DELME
                else if ( tmpLine == strcasestr( tmpLine, "#SISSM.allowmutator" )) {
                    j = 1;
                    while ( 1 == 1 ) {
                        u = getWord( tmpLine, j++, " ,=:\012\015" );
                        if ( u == NULL )        break;
                        if ( 0 == strlen( u ) ) break;
                        strlcat( mutAllowed, u,   16000 );
                        strlcat( mutAllowed, " ", 16000 );
                    } 
                }
                else if ( tmpLine == strcasestr( tmpLine, "#SISSM.defaultmutator" )) {
                    j = 1;
                    while ( 1 == 1 ) {
                        u = getWord( tmpLine, j++, " ,=:\012\015" );
                        if ( u == NULL )        break;
                        if ( 0 == strlen( u ) ) break;
                        strlcat( mutDefault, u,   256 );
                        strlcat( mutDefault, " ", 256 );
                    } 
                }
#endif
            }
        }
    }
 
#if DELME
    // todo-mut

    // Expand the space-separated single string mutAllowed to list mutAllowedList
    //
    strclr( mutAllowedList[0] );
    for (j = 0; j<API_MUT_MAXLIST; i++ ) { 
        w = getWord( mutAllowed, j, " ," );
        if ( w != NULL ) 
            strlcpy( mutAllowedList[j], w, API_MUT_MAXCHAR );
        else {
            strclr( mutAllowedList[j] );
            break;
        }              
    }
#endif 

#if 0
    if ( i != 0 ) {
        printf("\nMaps ------------------------\n");
        for ( j = 0; j<API_MAXMAPS; j++ ) {
            if ( 0 == strlen( mapNameMerged[j] ) ) break;
            printf("::%s:: ",  mapNameMerged[j] );
        }
        printf("\nMutators ------------------------");
        printf("\nMutAllowed ::%s::",    mutAllowed );
        printf("\nMutDefault ::%s::\n",  mutDefault );
    }
#endif

    return( i );
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x428, %rsp            # imm = 0x428
movq %rdi, %rbx
leaq 0x220(%rsp), %rdi
callq 0xf4dd
leaq 0x1eb6cf(%rip), %r14    # 0x1fdef0
xorl %r12d, %r12d
leaq 0x1656c5(%rip), %rbp    # 0x177ef0
movabsq $-0x100000000, %r13     # imm = 0xFFFFFFFF00000000
leaq (%r12,%rbp), %rdi
callq 0xf4dd
leaq (%r12,%rbp), %rdi
addq $0x100, %rdi            # imm = 0x100
callq 0xf4dd
leaq (%r12,%rbp), %rdi
addq $0x200, %rdi            # imm = 0x200
callq 0xf4dd
leaq (%r12,%rbp), %rdi
addq $0x300, %rdi            # imm = 0x300
callq 0xf4dd
leaq (%r12,%rbp), %r15
addq $0x408, %r15            # imm = 0x408
movq %r15, %rdi
callq 0xf4dd
movq %r13, -0x8(%r15)
movq %r14, %rdi
callq 0xf4dd
addq $0x28, %r14
addq $0x430, %r12            # imm = 0x430
cmpq $0x86000, %r12          # imm = 0x86000
jne 0x12835
leaq 0x95eb(%rip), %rsi      # 0x1be93
movq %rbx, %rdi
callq 0x8320
movq $0x0, 0x8(%rsp)
testq %rax, %rax
je 0x12ca2
movq %rax, %rbx
movq %rax, %rdi
callq 0x8270
testl %eax, %eax
jne 0x12ca2
leaq 0x320(%rsp), %r14
leaq 0xbc91(%rip), %r13      # 0x1e575
leaq 0xbc99(%rip), %r12      # 0x1e584
movq $0x0, 0x8(%rsp)
movq %r14, %rdi
movl $0xff, %esi
movq %rbx, %rdx
callq 0x8200
testq %rax, %rax
je 0x12c92
movq %r14, %rdi
movq %r13, %rsi
callq 0x8350
movq %r14, %rdi
cmpq %rax, %r14
je 0x12ade
leaq 0xbc61(%rip), %rsi      # 0x1e58c
callq 0x8350
cmpq %rax, %r14
jne 0x12c92
movq %r14, %rdi
movl $0x1, %esi
leaq 0xbc5f(%rip), %rdx      # 0x1e5a7
callq 0xf4e1
movl $0xff, %edx
leaq 0x20(%rsp), %rdi
movq %rax, %rsi
callq 0xf038
cmpb $0x0, 0x20(%rsp)
je 0x12c92
cmpb $0x0, 0x220(%rsp)
je 0x12c92
movslq 0x8(%rsp), %rax
imulq $0x430, %rax, %r15      # imm = 0x430
leaq (%r15,%rbp), %r12
leaq (%r15,%rbp), %rdi
addq $0x200, %rdi            # imm = 0x200
movl $0x100, %edx            # imm = 0x100
leaq 0x20(%rsp), %rsi
callq 0xf038
movl $0x100, %edx            # imm = 0x100
movq %r12, %rdi
leaq 0x220(%rsp), %r13
movq %r13, %rsi
callq 0xf038
leaq (%r15,%rbp), %rdi
addq $0x100, %rdi            # imm = 0x100
movl $0x100, %edx            # imm = 0x100
movq %rdi, 0x18(%rsp)
leaq 0x120(%rsp), %rsi
callq 0xf038
addq %rbp, %r15
addq $0x300, %r15            # imm = 0x300
movl $0x100, %edx            # imm = 0x100
movq %r15, %rdi
movq %r13, %rsi
callq 0xf038
movq %r15, %rdi
callq 0x8120
movabsq $0x6972616e6563533f, %rcx # imm = 0x6972616E6563533F
movq %rcx, 0x300(%rax,%r12)
movl $0x3d6f69, 0x307(%rax,%r12) # imm = 0x3D6F69
movl $0x80, %edx
movq %r15, %rdi
leaq 0x20(%rsp), %rsi
callq 0x81c0
movq %r14, %rdi
leaq 0xbb6b(%rip), %rsi      # 0x1e5a3
callq 0x8350
testq %rax, %rax
je 0x12a9c
movq %rax, %rdi
movl $0x1, %esi
leaq 0xbb57(%rip), %rdx      # 0x1e5a8
callq 0xf4e1
testq %rax, %rax
je 0x12a9c
movq %rax, %r13
movq %r15, %rdi
callq 0x8120
movl $0x6d61473f, (%r15,%rax) # imm = 0x6D61473F
movl $0x3d656d, 0x3(%r15,%rax) # imm = 0x3D656D
movl $0xac, %edx
movq %r15, %rdi
movq %r13, %rsi
callq 0x81c0
leaq 0x408(%r12), %rdi
movl $0x28, %edx
movq %r13, %rsi
callq 0xf038
movq %r14, %rdi
leaq 0xbb0b(%rip), %rsi      # 0x1e5b1
callq 0x8350
testq %rax, %rax
movq %r15, 0x10(%rsp)
je 0x12ba8
movl $0x1, 0x400(%r12)
movq %r15, %rdi
callq 0x8120
movups 0xbaee(%rip), %xmm0     # 0x1e5c2
movups %xmm0, (%r15,%rax)
jmp 0x12bcd
movl $0x1, %esi
movq %r12, %rdx
callq 0xf4e1
testq %rax, %rax
je 0x12c92
movq %rax, %r15
movl $0x100, %edx            # imm = 0x100
leaq 0x220(%rsp), %rdi
movq %rax, %rsi
callq 0xf038
movl $0x100, %edx            # imm = 0x100
leaq 0x120(%rsp), %rdi
movq %r15, %rsi
callq 0xf038
movq %r14, %rdi
movl $0x2, %esi
movq %r12, %rdx
callq 0xf4e1
testq %rax, %rax
je 0x12b50
cmpb $0x0, (%rax)
je 0x12b50
movl $0x100, %edx            # imm = 0x100
leaq 0x120(%rsp), %rdi
movq %rax, %rsi
callq 0xf038
xorl %r12d, %r12d
leaq 0x1eb396(%rip), %rax    # 0x1fdef0
leaq (%rax,%r12), %r15
movq %r15, %rdi
leaq 0x120(%rsp), %rsi
callq 0x8060
testl %eax, %eax
je 0x12b9c
cmpb $0x0, (%r15)
je 0x12b87
addq $0x28, %r12
cmpq $0x5000, %r12           # imm = 0x5000
jne 0x12b53
jmp 0x12b9c
movl $0x28, %edx
movq %r15, %rdi
leaq 0x120(%rsp), %rsi
callq 0xf038
leaq 0xb9e1(%rip), %r12      # 0x1e584
jmp 0x12c92
movq %r15, %rdi
callq 0x8120
movabsq $0x6e69746867694c3f, %rcx # imm = 0x6E69746867694C3F
movq %rcx, (%r15,%rax)
movabsq $0x7961443d676e69, %rcx # imm = 0x7961443D676E69
movq %rcx, 0x6(%r15,%rax)
movl $0xffffffff, 0x404(%r12) # imm = 0xFFFFFFFF
leaq 0x20(%rsp), %r15
movq %r15, %rdi
leaq 0xb9f8(%rip), %rsi      # 0x1e5e0
callq 0x8350
cmpq $0x1, %rax
movl $0x0, %r13d
sbbl %r13d, %r13d
orl $0x1, %r13d
movl %r13d, 0x404(%r12)
movq %r15, %rdi
leaq 0xb9da(%rip), %rsi      # 0x1e5ea
callq 0x8350
testq %rax, %rax
movl $0x0, %eax
cmovnel %eax, %r13d
movl %r13d, 0x404(%r12)
movl 0x400(%r12), %r10d
addq $0x408, %r12            # imm = 0x408
subq $0x8, %rsp
movl $0x2, %edi
leaq 0xb247(%rip), %rsi      # 0x1de8f
leaq 0xb9a4(%rip), %rdx      # 0x1e5f3
movq 0x10(%rsp), %r15
movl %r15d, %ecx
movq 0x20(%rsp), %r8
movl %r13d, %r9d
xorl %eax, %eax
pushq %r12
pushq 0x20(%rsp)
pushq %r10
callq 0x1a227
addq $0x20, %rsp
leal 0x1(%r15), %eax
cmpl $0x1fe, %r15d           # imm = 0x1FE
movq %rax, 0x8(%rsp)
leaq 0xb8ec(%rip), %r13      # 0x1e575
leaq 0xb8f4(%rip), %r12      # 0x1e584
jg 0x12ca2
movq %rbx, %rdi
callq 0x8270
testl %eax, %eax
je 0x128f4
movq 0x8(%rsp), %rax
addq $0x428, %rsp            # imm = 0x428
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq