// File: /workspace/github_cpp_makefile_star2_O3/billDrett[P]Bulletin-Boards/boardPost.cpp
// Function: BoardPost::getChanels()
void BoardPost::getChanels()
{
    int nwrite, nread;
    char buffer[BUFFERSIZE];
    char* tmp;
    char* tmp1;
    string tmpTag;
    statesChanels state = waitingChanel;

    if((nwrite = write(pipeBoardPost2Server, "<Chanels>", 9))== -1) //stelnoume mnm sto server na epistrepsei ta chanels tou
    {
        perror("Cant write to pipe S2BP");
    }

    while((nread = read(pipeServer2BoardPost, buffer + tmpTag.size(), BUFFERSIZE - tmpTag.size())) > 0) //diavazoume thn apanthsh tou server mexri na vroume to <end><Chanel>
    {                                                                                                   //se periptwsh pou diavastike meros tou proigoumenou tag diavazw ligotera bytes kai prostheto to proigoumeno tag sthn arxh
        strncpy(buffer, tmpTag.c_str(), tmpTag.size()); //antigrafw to meros tou proigoumenou tag efoson yparxei
        nread += tmpTag.size();
        tmpTag = ""; //midenizw to proigoumeno tag
        tmp = buffer;

        if(state == waitingChanel)//perimenw na vrw to <Chanel>
        {
            tmp1 = getAfterTag(tmp, "<Chanel>", nread);
            if(tmp1 == NULL) //dn vrethike to chanel tag
            {
                if((tmp1 = getAfterTag(tmp, "<", nread)) != NULL) // mporei na pira meros tou tag, to apothikeuw kai to prosthetw sthn arxh tou neou read
                {
                    tmpTag.assign(tmp1-1, nread+1); // -1 giati thelw na krathsw kai to "< kai +1 sto read gia na to symperilavw
                }
                continue;
            }
            tmp = tmp1;
            state = waitingStart;
        }

        if(state == waitingStart) //perimenw na vrw to <start>
        {
            tmp1 = getAfterTag(tmp, "<start>", nread);
            if(tmp1 == NULL)
            {
                if((tmp1 = getAfterTag(tmp, "<", nread)) != NULL) // mporei na pira meros tou tag, to apothikeuw kai to prosthetw sthn arxh tou neou read
                {
                    tmpTag.assign(tmp1-1, nread+1); // -1 giati thelw na krathsw kai to "< kai +1 sto read gia na to symperilavw
                }
                continue;
            }
            tmp = tmp1;
            state = waitingEnd;
        }
        if(state == waitingEnd) //perimenw na vrw to <end>
        {
            int copyNread = nread;
            if(getBeforeTag(tmp, "<end>", copyNread) != NULL) //emfanizw ta chanels mexri na vrw to tag <end>, an to vrw emfanizw ta bytes mexri to <end>
            {
                state = waitingEndChanel;
            }

            write(1, tmp, copyNread); //grafw ta bytes mexri to copyNread
        }

        if(state == waitingEndChanel) //perimenw na vrw to <Chanel> meta to <end>
        {
            tmp1 = getBeforeTag(tmp, "<Chanel>", nread);
            if(tmp1 == NULL)
            {
                if((tmp1 = getAfterTag(tmp, "<", nread)) != NULL) // mporei na pira meros tou tag, to apothikeuw kai to prosthetw sthn arxh tou neou read
                {
                    tmpTag.assign(tmp1-1, nread+1); // -1 giati thelw na krathsw kai to "< kai +1 sto read gia na to symperilavw
                }
                continue;
            }
            break; //oloklirwthike to mnm
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x438, %rsp            # imm = 0x438
leaq -0x40(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq %rdi, -0x58(%rbp)
movl (%rdi), %edi
leaq 0x1383(%rip), %rsi      # 0x408d
movl $0x9, %edx
callq 0x20a0
cmpl $-0x1, %eax
je 0x2f40
xorl %ebx, %ebx
movb $0x1, %r13b
leaq -0x460(%rbp), %r12
movq -0x58(%rbp), %rax
movl 0x4(%rax), %edi
movq -0x48(%rbp), %rax
leaq (%rax,%rbp), %rsi
addq $-0x460, %rsi           # imm = 0xFBA0
movl $0x400, %edx            # imm = 0x400
subq %rax, %rdx
callq 0x2200
movq %rax, %r14
movl %r14d, -0x2c(%rbp)
testl %r14d, %r14d
jle 0x2f15
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %r15
movq %r12, %rdi
movq %r15, %rdx
callq 0x20d0
addl %r15d, %r14d
movl %r14d, -0x2c(%rbp)
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
movq %r15, %rdx
leaq 0x13bb(%rip), %rcx      # 0x4141
xorl %r8d, %r8d
callq 0x2220
testb $0x1, %r13b
je 0x2df9
movq %r12, %rdi
leaq 0x1311(%rip), %rsi      # 0x40af
leaq -0x2c(%rbp), %rdx
callq 0x395e
movq %rax, %r15
testq %rax, %rax
jne 0x2e0c
movq %r12, %rdi
leaq 0x12ff(%rip), %rsi      # 0x40b8
leaq -0x2c(%rbp), %rdx
callq 0x395e
movb $0x1, %r13b
movl $0x0, %ebx
testq %rax, %rax
je 0x2d29
decq %rax
movslq -0x2c(%rbp), %r8
incq %r8
xorl %ebx, %ebx
movq -0x48(%rbp), %rdx
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
movq %rax, %rcx
callq 0x2220
movb $0x1, %r13b
jmp 0x2d29
movq %r12, %r14
cmpl $0x2, %ebx
je 0x2e2b
movq %r12, %r15
movq %r12, %r14
cmpl $0x1, %ebx
jne 0x2e69
movq %r15, %rdi
leaq 0x12b3(%rip), %rsi      # 0x40c9
leaq -0x2c(%rbp), %rdx
callq 0x395e
movq %rax, %r14
testq %rax, %rax
je 0x2ecd
movl -0x2c(%rbp), %eax
movl %eax, -0x30(%rbp)
movq %r14, %rdi
leaq 0x127f(%rip), %rsi      # 0x40ba
leaq -0x30(%rbp), %rdx
callq 0x39bc
movq %rax, %r15
movslq -0x30(%rbp), %rdx
movl $0x1, %edi
movq %r14, %rsi
callq 0x20a0
xorl %r13d, %r13d
movl $0x2, %ebx
testq %r15, %r15
je 0x2d29
movq %r14, %rdi
leaq 0x123c(%rip), %rsi      # 0x40af
leaq -0x2c(%rbp), %rdx
callq 0x39bc
testq %rax, %rax
jne 0x2f15
movq %r14, %rdi
leaq 0x1229(%rip), %rsi      # 0x40b8
leaq -0x2c(%rbp), %rdx
callq 0x395e
movl $0x3, %ebx
xorl %r13d, %r13d
testq %rax, %rax
je 0x2d29
decq %rax
movslq -0x2c(%rbp), %r8
incq %r8
xorl %r13d, %r13d
movq -0x48(%rbp), %rdx
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
movq %rax, %rcx
callq 0x2220
jmp 0x2d29
movq %r15, %rdi
leaq 0x11e1(%rip), %rsi      # 0x40b8
leaq -0x2c(%rbp), %rdx
callq 0x395e
movl $0x1, %ebx
xorl %r13d, %r13d
testq %rax, %rax
je 0x2d29
decq %rax
movslq -0x2c(%rbp), %r8
incq %r8
xorl %r13d, %r13d
movq -0x48(%rbp), %rdx
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
movq %rax, %rcx
callq 0x2220
jmp 0x2d29
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x2f2e
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2180
addq $0x438, %rsp            # imm = 0x438
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1150(%rip), %rdi      # 0x4097
callq 0x2140
jmp 0x2d1d
jmp 0x2f55
jmp 0x2f55
movq %rax, %rbx
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x2f71
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2180
movq %rbx, %rdi
callq 0x2250
nop