// File: /workspace/github_c_makefile_star2_O1/schroeder-lvb[P]sissm/src/roster.c
// Function: rosterParsePlayerChat
int rosterParsePlayerChat( char *strIn, int maxChars, char *clientID, char *chatLine )
{
    int   errCode = 1, i;
    char  strIn2[256], *p;
    char *chatText = NULL;


    // Clear the return variables in case of parsing error
    //
    strclr( clientID );
    strclr( chatLine );

    // check if this is a valid chat line
    //
    if ( NULL != strstr( strIn, "LogChat: Display:" )) {

        // make a copy and get rid of last carriage return
        //
        strlcpy( strIn2, strIn, 256 );
        for (i = 0; i< (int) strlen( strIn2 ); i++ )
            if ( strIn2[i] == '\015') strIn2[i] = 0;

        // Go find the first character of typed text.  Check 3 cases for a match.
        // if none found, chatText is NULL
        //
        if ( chatText == NULL )  chatText = strstr( strIn2, "Global Chat: " );
        if ( chatText == NULL )  chatText = strstr( strIn2, "Team 0 Chat: " );
        if ( chatText == NULL )  chatText = strstr( strIn2, "Team 1 Chat: " );
        if ( chatText != NULL )  {
            // chatText += 13;
            strlcpy( chatLine, chatText+13, maxChars );
            errCode = 0;
        }

        // Find the steam or EPIC ID of the originator
        // EPIC
        //
        if ( chatText != NULL ) {   // from start of chat text, work backwards to find the "(" symbol

            p = chatText;
            while ( (p--) != chatLine ) {         
                if ( *p == '(' ) {
                    p++;
                    strlcpy( clientID, p, 66 );       // check if this is EPIC ID
                    if ( 0 == rosterIsValidGUID( clientID ) ) {
                        strlcpy( clientID, p, 18 );  // check if this is Steam ID
                        if ( 0 == rosterIsValidGUID( clientID ) ) {
                            strlcpy( clientID, p, 17 );  // check if this is WinGDK ID
                            if ( 0 == rosterIsValidGUID( clientID ) ) {
                                strclr( clientID );      // parse error, no ID
                                errCode = 2;
                           }
                        }
                    }
                    break;
                }
            }
        }        
    }
    return errCode;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x100, %rsp            # imm = 0x100
movq %rcx, %r14
movq %rdx, %rbx
movl %esi, %ebp
movq %rdi, %r15
movq %rdx, %rdi
callq 0xf4dd
movq %r14, %rdi
callq 0xf4dd
leaq 0x753b(%rip), %rsi      # 0x1c813
movq %r15, %rdi
callq 0x83b0
testq %rax, %rax
je 0x15384
movq %rsp, %r12
movl $0x100, %edx            # imm = 0x100
movq %r12, %rdi
movq %r15, %rsi
callq 0xf038
movq %r12, %rdi
callq 0x8120
testl %eax, %eax
jle 0x1532c
xorl %r12d, %r12d
movq %rsp, %r15
cmpb $0xd, (%rsp,%r12)
jne 0x1531a
movb $0x0, (%rsp,%r12)
incq %r12
movq %r15, %rdi
callq 0x8120
cltq
cmpq %rax, %r12
jl 0x1530e
leaq 0x9694(%rip), %rsi      # 0x1e9c7
movq %rsp, %rdi
callq 0x83b0
movq %rax, %r15
testq %rax, %rax
jne 0x15355
leaq 0x968b(%rip), %rsi      # 0x1e9d5
movq %rsp, %rdi
callq 0x83b0
movq %rax, %r15
testq %r15, %r15
jne 0x1536c
leaq 0x9682(%rip), %rsi      # 0x1e9e3
movq %rsp, %rdi
callq 0x83b0
movq %rax, %r15
testq %r15, %r15
je 0x1538e
leaq 0xd(%r15), %rsi
movslq %ebp, %rdx
movq %r14, %rdi
callq 0xf038
xorl %ebp, %ebp
jmp 0x15393
movl $0x1, %ebp
jmp 0x1540f
movl $0x1, %ebp
testq %r15, %r15
je 0x1540f
cmpq %r14, %r15
je 0x1540f
leaq -0x1(%r15), %r12
cmpb $0x28, -0x1(%r15)
movq %r12, %r15
jne 0x15398
incq %r12
movl $0x42, %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0xf038
movq %rbx, %rdi
callq 0x1403c
testl %eax, %eax
jne 0x1540f
movl $0x12, %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0xf038
movq %rbx, %rdi
callq 0x1403c
testl %eax, %eax
jne 0x1540f
movl $0x11, %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0xf038
movq %rbx, %rdi
callq 0x1403c
testl %eax, %eax
jne 0x1540f
movq %rbx, %rdi
callq 0xf4dd
movl $0x2, %ebp
movl %ebp, %eax
addq $0x100, %rsp            # imm = 0x100
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq