// File: /workspace/github_cpp_makefile_star2_O3/billDrett[P]Bulletin-Boards/boardServer.cpp
// Function: BoardServer::parseCommandPrototype(char*, int&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, void (BoardServer::*)(char*, int, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&), int)
void BoardServer::parseCommandPrototype(char* buffer, int &nread, std::string CommandType, void (BoardServer::*foo)(char* buffer, int nread, int state, std::string& previousRead), int pipeToRead)
{//o buffer krataei ta perienxomena autou pou diavasame, to commandType einai to string pou perimenoume na diavasoume arxika kai sto telos, kai o pointer se function einai thn tha ekteleitai mexri na synanththei <end>
    string tmpTag , previousRead;
    char* tmp;
    char* tmp1;

    int stateCommand = waitingCommand;

    do
    {
        strncpy(buffer, tmpTag.c_str(), tmpTag.size());
        nread += tmpTag.size();
        tmpTag = "";
        tmp = buffer; //dn ta kanw if else if giati mporei na allaksoun state mesa se ena loop analoga me ta perienxomena tou buffer

        if(stateCommand == waitingCommand)
        {
            tmp1 = getAfterTag(tmp, CommandType.c_str(), nread);
            if(tmp1 == NULL)
            {
                if((tmp1 = getAfterTag(tmp, "<", nread)) != NULL)
                {
                    tmpTag.assign(tmp1-1, nread+1); // -1 giati thelw na krathsw kai to "< kai +1 sto read gia na to symperilavw
                }
                continue;
            }
            tmp = tmp1;
            stateCommand = waitingStart;
        }

        if(stateCommand == waitingStart)
        {
            tmp1 = getAfterTag(tmp, "<start>", nread);
            if(tmp1 == NULL)
            {
                if((tmp1 = getAfterTag(tmp, "<", nread)) != NULL)
                {
                    tmpTag.assign(tmp1-1, nread+1); // -1 giati thelw na krathsw kai to "< kai +1 sto read gia na to symperilavw
                }
                continue;
            }
            tmp = tmp1;
            stateCommand = waitingEnd;
        }

        if(stateCommand == waitingEnd)
        {

            int copyNread = nread;
            if(getBeforeTag(tmp, "<end>", copyNread) != NULL)
            {
                stateCommand = waitingEndCommand;
            }

            (this->*foo)(tmp, copyNread, stateCommand, previousRead); //kalw thn synarthsh pou mou dothike ws parametros
        }

        if(stateCommand == waitingEndCommand)
        {
            tmp1 = getAfterTag(tmp, CommandType.c_str(), nread);
            if(tmp1 == NULL)
            {
                if((tmp1 = getAfterTag(tmp, "<", nread)) != NULL)
                {
                    tmpTag.assign(tmp1-1, nread+1); // -1 giati thelw na krathsw kai to "< kai +1 sto read gia na to symperilavw
                }
                continue;
            }
            tmp = tmp1;
            shiftArray(buffer, tmp, nread);//strncpy(buffer, tmp, nread); //apothikeuw ta ypoloipa tou buffer sthn arxh tou gia na ta diaxeiristei to menu
            return;
        }
    }while(((nread = read(pipeToRead, buffer + tmpTag.size(), BUFFERSIZE - tmpTag.size())) > 0)); //an dn exoun diavastei ola osa thelw kanw ksana read apo to pipe pou mou dwthike
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %r8, -0x60(%rbp)
movq %rcx, -0x68(%rbp)
movq %rdx, %r14
movq %rsi, %r13
leaq -0x40(%rbp), %rax
movq %rax, -0x10(%rax)
xorl %r15d, %r15d
movq %r15, -0x8(%rax)
movb %r15b, (%rax)
leaq -0x78(%rbp), %rax
movq %rax, -0x10(%rax)
movq %r15, -0x8(%rax)
movb %r15b, (%rax)
addq %r9, %rdi
movq %rdi, -0x58(%rbp)
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rbx
movq %r13, %rdi
movq %rbx, %rdx
callq 0x2160
addl %ebx, (%r14)
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
movq %rbx, %rdx
leaq 0x2502(%rip), %rcx      # 0x8233
xorl %r8d, %r8d
callq 0x2360
movq %r13, %rbx
cmpl $0x2, %r15d
je 0x5d93
movq %r13, %r12
cmpl $0x1, %r15d
je 0x5d75
movq %r13, %rbx
testl %r15d, %r15d
jne 0x5def
movq -0x68(%rbp), %rax
movq (%rax), %rsi
movq %r13, %rdi
movq %r14, %rdx
callq 0x6616
movq %rax, %r12
testq %rax, %rax
je 0x5e8a
movq %r12, %rdi
leaq 0x2398(%rip), %rsi      # 0x8117
movq %r14, %rdx
callq 0x6616
movq %rax, %rbx
testq %rax, %rax
je 0x5e50
movl (%r14), %eax
movl %eax, -0x2c(%rbp)
movq %rbx, %rdi
leaq 0x24b3(%rip), %rsi      # 0x8256
leaq -0x2c(%rbp), %rdx
callq 0x6674
movq %rax, %r12
cmpq $0x1, %rax
movl $0x3, %ecx
sbbl $0x0, %ecx
movq -0x60(%rbp), %rdx
movq %rdx, %rax
testb $0x1, %dl
je 0x5dd7
movq -0x58(%rbp), %rax
movq (%rax), %rax
movq -0x60(%rbp), %rdx
movq -0x1(%rax,%rdx), %rax
movl -0x2c(%rbp), %edx
movq -0x58(%rbp), %rdi
movq %rbx, %rsi
leaq -0x88(%rbp), %r8
callq *%rax
testq %r12, %r12
je 0x5e48
movq -0x68(%rbp), %rax
movq (%rax), %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x6616
testq %rax, %rax
jne 0x5ee9
movq %rbx, %rdi
leaq 0x233d(%rip), %rsi      # 0x8151
movq %r14, %rdx
callq 0x6616
movl $0x3, %r15d
testq %rax, %rax
je 0x5ec4
decq %rax
movslq (%r14), %r8
incq %r8
movq -0x48(%rbp), %rdx
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
movq %rax, %rcx
callq 0x2360
jmp 0x5ec4
movl $0x2, %r15d
jmp 0x5ec4
movq %r12, %rdi
leaq 0x22f7(%rip), %rsi      # 0x8151
movq %r14, %rdx
callq 0x6616
movl $0x1, %r15d
testq %rax, %rax
je 0x5ec4
decq %rax
movslq (%r14), %r8
incq %r8
movq -0x48(%rbp), %rdx
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
movq %rax, %rcx
callq 0x2360
jmp 0x5ec4
movq %r13, %rdi
leaq 0x22bd(%rip), %rsi      # 0x8151
movq %r14, %rdx
callq 0x6616
testq %rax, %rax
je 0x5ec1
decq %rax
movslq (%r14), %r8
incq %r8
xorl %r15d, %r15d
movq -0x48(%rbp), %rdx
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
movq %rax, %rcx
callq 0x2360
jmp 0x5ec4
xorl %r15d, %r15d
movq -0x48(%rbp), %rax
leaq (%rax,%r13), %rsi
movl $0x400, %edx            # imm = 0x400
subq %rax, %rdx
movl 0x10(%rbp), %edi
callq 0x2300
movl %eax, (%r14)
testl %eax, %eax
jg 0x5d0b
jmp 0x5ef7
movl (%r14), %edx
movq %r13, %rdi
movq %rax, %rsi
callq 0x672e
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x5f13
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x2230
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x5f2c
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2230
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5f3f
jmp 0x5f3f
movq %rax, %rbx
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x5f5e
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x2230
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x5f77
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2230
movq %rbx, %rdi
callq 0x23c0
nop