// File: /workspace/github_cpp_makefile_star2_O1/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 0x1387(%rip), %rsi      # 0x408d
movl $0x9, %edx
callq 0x20a0
cmpl $-0x1, %eax
je 0x2f44
xorl %ebx, %ebx
movb $0x1, %r15b
leaq -0x460(%rbp), %r13
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 0x2f19
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %r12
movq %r13, %rdi
movq %r12, %rdx
callq 0x20d0
addl %r12d, %r14d
movl %r14d, -0x2c(%rbp)
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
movq %r12, %rdx
leaq 0x13bf(%rip), %rcx      # 0x4141
xorl %r8d, %r8d
callq 0x2220
movq %r13, %r14
testb $0x1, %r15b
je 0x2db7
movq %r13, %rdi
leaq 0x1312(%rip), %rsi      # 0x40af
leaq -0x2c(%rbp), %rdx
callq 0x395a
movq %rax, %r14
testq %rax, %rax
je 0x2e87
movl $0x1, %ebx
cmpl $0x1, %ebx
jne 0x2de0
movq %r14, %rdi
leaq 0x1303(%rip), %rsi      # 0x40c9
leaq -0x2c(%rbp), %rdx
callq 0x395a
testq %rax, %rax
je 0x2ed1
movl $0x2, %ebx
movq %rax, %r14
cmpl $0x2, %ebx
jne 0x2e23
movl -0x2c(%rbp), %eax
movl %eax, -0x30(%rbp)
movq %r14, %rdi
leaq 0x12c5(%rip), %rsi      # 0x40ba
leaq -0x30(%rbp), %rdx
callq 0x39b8
movq %rax, %r12
movslq -0x30(%rbp), %rdx
movl $0x1, %edi
movq %r14, %rsi
callq 0x20a0
xorl %r15d, %r15d
movl $0x2, %ebx
testq %r12, %r12
je 0x2d25
movq %r14, %rdi
leaq 0x1282(%rip), %rsi      # 0x40af
leaq -0x2c(%rbp), %rdx
callq 0x39b8
testq %rax, %rax
jne 0x2f19
movq %r14, %rdi
leaq 0x126f(%rip), %rsi      # 0x40b8
leaq -0x2c(%rbp), %rdx
callq 0x395a
movl $0x3, %ebx
xorl %r15d, %r15d
testq %rax, %rax
je 0x2d25
decq %rax
movslq -0x2c(%rbp), %r8
incq %r8
xorl %r15d, %r15d
movq -0x48(%rbp), %rdx
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
movq %rax, %rcx
callq 0x2220
jmp 0x2d25
movq %r13, %rdi
leaq 0x1227(%rip), %rsi      # 0x40b8
leaq -0x2c(%rbp), %rdx
callq 0x395a
movb $0x1, %r15b
movl $0x0, %ebx
testq %rax, %rax
je 0x2d25
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, %r15b
jmp 0x2d25
movq %r14, %rdi
leaq 0x11dd(%rip), %rsi      # 0x40b8
leaq -0x2c(%rbp), %rdx
callq 0x395a
movl $0x1, %ebx
xorl %r15d, %r15d
testq %rax, %rax
je 0x2d25
decq %rax
movslq -0x2c(%rbp), %r8
incq %r8
xorl %r15d, %r15d
movq -0x48(%rbp), %rdx
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
movq %rax, %rcx
callq 0x2220
jmp 0x2d25
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x2f32
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 0x114c(%rip), %rdi      # 0x4097
callq 0x2140
jmp 0x2d19
jmp 0x2f59
jmp 0x2f59
movq %rax, %rbx
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x2f75
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2180
movq %rbx, %rdi
callq 0x2250
nop