// File: /workspace/github_c_makefile_star2_O3/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 %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %rcx, %r14
movq %rdx, %rbx
movl %esi, %r15d
movq %rdi, %r12
movq %rdx, %rdi
callq 0xf829
movq %r14, %rdi
callq 0xf829
leaq 0x726d(%rip), %rsi      # 0x1c7ed
movq %r12, %rdi
callq 0x83b0
movl $0x1, %ebp
testq %rax, %rax
je 0x156a6
movq %rsp, %r13
movl $0x100, %edx            # imm = 0x100
movq %r13, %rdi
movq %r12, %rsi
callq 0xf384
movq %r13, %rdi
callq 0x8120
testl %eax, %eax
jle 0x155d9
xorl %r13d, %r13d
movq %rsp, %r12
cmpb $0xd, (%rsp,%r13)
jne 0x155c7
movb $0x0, (%rsp,%r13)
incq %r13
movq %r12, %rdi
callq 0x8120
cltq
cmpq %rax, %r13
jl 0x155bb
leaq 0x93d7(%rip), %rsi      # 0x1e9b7
movq %rsp, %rdi
callq 0x83b0
testq %rax, %rax
jne 0x15619
leaq 0x93d1(%rip), %rsi      # 0x1e9c5
movq %rsp, %rdi
callq 0x83b0
testq %rax, %rax
jne 0x15619
leaq 0x93cb(%rip), %rsi      # 0x1e9d3
movq %rsp, %rdi
callq 0x83b0
testq %rax, %rax
je 0x156a6
movq %rax, %r12
leaq 0xd(%rax), %rsi
movslq %r15d, %rdx
movq %r14, %rdi
callq 0xf384
xorl %ebp, %ebp
cmpq %r14, %r12
je 0x156a6
leaq -0x1(%r12), %r15
cmpb $0x28, -0x1(%r12)
movq %r15, %r12
jne 0x1562d
incq %r15
movl $0x42, %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0xf384
movq %rbx, %rdi
callq 0x14378
testl %eax, %eax
jne 0x156a6
movl $0x12, %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0xf384
movq %rbx, %rdi
callq 0x14378
testl %eax, %eax
jne 0x156a6
movl $0x11, %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0xf384
movq %rbx, %rdi
callq 0x14378
testl %eax, %eax
jne 0x156a6
movq %rbx, %rdi
callq 0xf829
movl $0x2, %ebp
movl %ebp, %eax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq