// File: /workspace/github_cpp_makefile_star2_O2/billDrett[P]Bulletin-Boards/board.cpp
// Function: main
int main(int argc, char *argv[])
{
    pid_t serverPid = 1;
    string path, tmpPath, boardID;
    string line;
    int found;

    if(argc != 2)
    {
        cout<<"error arguments"<<endl;
        return - 2;
    }

    signal(SIGINT, SIG_IGN); //agnow to control c
    path = argv[1];
    found = path.find_last_of("/");
    if(found ==  string::npos)
    {
        boardID = path;
    }
    else
    {
        boardID = path.substr(found+1);
    }

    tmpPath = path + "/" + boardID + "_pid";

    if(open(tmpPath.c_str(), O_RDONLY, 0666) == -1)
    {
        //tmpPath = path + "/" +boardID;
        mkdir(path.c_str(), 0773);
        tmpPath = path + "/" +boardID + "_selfC2S";
        mkfifo(tmpPath.c_str(), 0666);
        tmpPath = path + "/" +boardID + "_selfS2C";
        mkfifo(tmpPath.c_str(), 0666);
        tmpPath = path + "/" +boardID + "_othersS2BP";
        mkfifo(tmpPath.c_str(), 0666);
        tmpPath = path + "/" +boardID + "_othersBP2S";
        mkfifo(tmpPath.c_str(), 0666);

        serverPid = fork();
        if(serverPid == -1)
        {
            perror("Failed to fork");
            exit(1);
        }
    }

    if(serverPid != 0) //boardClient process
    {
        cout<<"client proccess created"<<endl;
        string tmp1 = path + "/" + boardID + "_selfC2S", tmp2 = path + "/" + boardID + "_selfS2C";
        BoardClient* client = new BoardClient(tmp1, tmp2);
        while(!getline(cin, line).eof()) //eisodos apo pliktrologio
        {
            if(client->menu(line) == -1) break;
        }
        delete client;
        exit(0);
    }
    else //server process
    {
        char conver[32];
        chdir(path.c_str());
        tmpPath = boardID + "_pid";
        ofstream pidFile(tmpPath.c_str());

        pid_t currentPid = getpid();
        pidFile << currentPid;
        pidFile.close();
        cout<<"server process created"<<endl;

        string tmp1 = boardID + "_selfC2S", tmp2 = boardID + "_selfS2C", tmp3 = boardID + "_othersBP2S", tmp4 = boardID + "_othersS2BP";
        BoardServer* server = new BoardServer(tmp1, tmp2, tmp3, tmp4);
        server->parser();

        delete server;
        unlink(tmp1.c_str());
        unlink(tmp2.c_str());
        unlink(tmp3.c_str());
        unlink(tmp4.c_str());
        unlink(tmpPath.c_str());
        chdir("..");
        rmdir(path.c_str());
        exit(0);

    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x3c8, %rsp            # imm = 0x3C8
movq %rsi, %rbx
leaq -0x88(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
leaq -0xa8(%rbp), %rcx
movq %rcx, -0x10(%rcx)
andq $0x0, -0x8(%rcx)
xorl %edx, %edx
movb %dl, (%rax)
leaq -0x68(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
leaq -0x1c8(%rbp), %rsi
movq %rsi, -0x10(%rsi)
andq $0x0, -0x8(%rsi)
movb %dl, (%rcx)
movb %dl, (%rax)
movb %dl, (%rsi)
cmpl $0x2, %edi
je 0x2734
movq 0x88ee(%rip), %rdi      # 0xafd0
leaq 0x491b(%rip), %rsi      # 0x7004
callq 0x2230
movq %rax, %rdi
callq 0x2170
leaq -0x1d8(%rbp), %rdi
callq 0x2130
leaq -0x78(%rbp), %rdi
callq 0x2130
leaq -0xb8(%rbp), %rdi
callq 0x2130
leaq -0x98(%rbp), %rdi
callq 0x2130
pushq $-0x2
popq %rax
addq $0x3c8, %rsp            # imm = 0x3C8
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
pushq $0x2
popq %rdi
pushq $0x1
popq %rsi
callq 0x2280
movq 0x8(%rbx), %rsi
leaq -0x98(%rbp), %rdi
callq 0x23d0
leaq 0x48be(%rip), %rsi      # 0x7014
leaq -0x98(%rbp), %rdi
pushq $-0x1
popq %rdx
callq 0x2210
cmpl $-0x1, %eax
jne 0x277c
leaq -0x78(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x2190
jmp 0x27b2
incl %eax
movslq %eax, %rdx
leaq -0x3d8(%rbp), %rdi
leaq -0x98(%rbp), %rsi
pushq $-0x1
popq %rcx
callq 0x2260
leaq -0x78(%rbp), %rdi
leaq -0x3d8(%rbp), %rbx
movq %rbx, %rsi
callq 0x22a0
movq %rbx, %rdi
callq 0x2130
leaq 0x485b(%rip), %rdx      # 0x7014
leaq -0x38(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x2f7f
leaq -0x58(%rbp), %rdi
leaq -0x38(%rbp), %rsi
leaq -0x78(%rbp), %rdx
callq 0x2f56
leaq 0x4835(%rip), %rdx      # 0x7016
leaq -0x3d8(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x2f2d
leaq -0xb8(%rbp), %rbx
leaq -0x3d8(%rbp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x22a0
movq %r14, %rdi
callq 0x2130
leaq -0x58(%rbp), %rdi
callq 0x2130
leaq -0x38(%rbp), %rdi
callq 0x2130
movq (%rbx), %rdi
xorl %esi, %esi
movl $0x1b6, %edx            # imm = 0x1B6
xorl %eax, %eax
callq 0x21c0
cmpl $-0x1, %eax
jne 0x2a3f
leaq -0x98(%rbp), %rbx
movq (%rbx), %rdi
movl $0x1fb, %esi            # imm = 0x1FB
callq 0x2140
leaq 0x47bb(%rip), %rdx      # 0x7014
leaq -0x38(%rbp), %rdi
movq %rbx, %rsi
callq 0x2f7f
leaq -0x58(%rbp), %rdi
leaq -0x38(%rbp), %rsi
leaq -0x78(%rbp), %rdx
callq 0x2f56
leaq 0x479e(%rip), %rdx      # 0x701b
leaq -0x3d8(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x2f2d
leaq -0xb8(%rbp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x22a0
movq %r14, %rdi
callq 0x2130
leaq -0x58(%rbp), %rdi
callq 0x2130
leaq -0x38(%rbp), %rdi
callq 0x2130
movq (%rbx), %rdi
movl $0x1b6, %esi            # imm = 0x1B6
callq 0x2060
leaq 0x4747(%rip), %rdx      # 0x7014
leaq -0x38(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x2f7f
leaq -0x58(%rbp), %rdi
leaq -0x38(%rbp), %rsi
leaq -0x78(%rbp), %rdx
callq 0x2f56
leaq 0x472f(%rip), %rdx      # 0x7024
leaq -0x3d8(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x2f2d
movq %rbx, %rdi
movq %r14, %rsi
callq 0x22a0
movq %r14, %rdi
callq 0x2130
leaq -0x58(%rbp), %rdi
callq 0x2130
leaq -0x38(%rbp), %rdi
callq 0x2130
movq (%rbx), %rdi
movl $0x1b6, %esi            # imm = 0x1B6
callq 0x2060
leaq 0x46d6(%rip), %rdx      # 0x7014
leaq -0x38(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x2f7f
leaq -0x58(%rbp), %rdi
leaq -0x38(%rbp), %rsi
leaq -0x78(%rbp), %rdx
callq 0x2f56
leaq 0x46c7(%rip), %rdx      # 0x702d
leaq -0x3d8(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x2f2d
movq %rbx, %rdi
movq %r14, %rsi
callq 0x22a0
movq %r14, %rdi
callq 0x2130
leaq -0x58(%rbp), %rdi
callq 0x2130
leaq -0x38(%rbp), %rdi
callq 0x2130
movq (%rbx), %rdi
movl $0x1b6, %esi            # imm = 0x1B6
callq 0x2060
leaq 0x4665(%rip), %rdx      # 0x7014
leaq -0x38(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x2f7f
leaq -0x58(%rbp), %rdi
leaq -0x38(%rbp), %rsi
leaq -0x78(%rbp), %rdx
callq 0x2f56
leaq 0x4662(%rip), %rdx      # 0x7039
leaq -0x3d8(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x2f2d
movq %rbx, %rdi
movq %r14, %rsi
callq 0x22a0
movq %r14, %rdi
callq 0x2130
leaq -0x58(%rbp), %rdi
callq 0x2130
leaq -0x38(%rbp), %rdi
callq 0x2130
movq (%rbx), %rdi
movl $0x1b6, %esi            # imm = 0x1B6
callq 0x2060
callq 0x20b0
testl %eax, %eax
je 0x2baf
cmpl $-0x1, %eax
jne 0x2a3f
leaq 0x4613(%rip), %rdi      # 0x7045
callq 0x21e0
pushq $0x1
popq %rdi
callq 0x2290
movq 0x858a(%rip), %rdi      # 0xafd0
leaq 0x4607(%rip), %rsi      # 0x7054
callq 0x2230
movq %rax, %rdi
callq 0x2170
leaq 0x45b3(%rip), %rdx      # 0x7014
leaq -0x38(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x2f7f
leaq -0x58(%rbp), %rdi
leaq -0x38(%rbp), %rsi
leaq -0x78(%rbp), %rdx
callq 0x2f56
leaq 0x4592(%rip), %rdx      # 0x701b
leaq -0x3d8(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x2f2d
leaq -0x58(%rbp), %rdi
callq 0x2130
leaq -0x38(%rbp), %rdi
callq 0x2130
leaq 0x4562(%rip), %rdx      # 0x7014
leaq -0xd8(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x2f7f
leaq -0x38(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
leaq -0x78(%rbp), %rdx
callq 0x2f56
leaq 0x4544(%rip), %rdx      # 0x7024
leaq -0x58(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x2f2d
leaq -0x38(%rbp), %rdi
callq 0x2130
leaq -0xd8(%rbp), %rdi
callq 0x2130
pushq $0x8
popq %rdi
callq 0x2240
movq %rax, %r14
leaq -0x1b8(%rbp), %rdi
leaq -0x3d8(%rbp), %rsi
callq 0x22e0
leaq -0x198(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x22e0
leaq -0x1b8(%rbp), %rsi
leaq -0x198(%rbp), %rdx
movq %r14, %rdi
callq 0x2fb8
leaq -0x198(%rbp), %rdi
callq 0x2130
leaq -0x1b8(%rbp), %rdi
callq 0x2130
movq 0x847b(%rip), %rbx      # 0xafe0
leaq -0x1d8(%rbp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2080
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x2, 0x20(%rax,%rcx)
jne 0x2b95
movq %r14, %rdi
movq %r15, %rsi
callq 0x38e2
cmpl $-0x1, %eax
jne 0x2b6c
movq %r14, %rdi
callq 0x3010
pushq $0x8
popq %rsi
movq %r14, %rdi
callq 0x2250
xorl %edi, %edi
callq 0x2290
movq -0x98(%rbp), %rdi
callq 0x2320
leaq 0x4454(%rip), %rdx      # 0x7016
leaq -0x3d8(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x2f7f
movq %rbx, %rdi
movq %r14, %rsi
callq 0x22a0
movq %r14, %rdi
callq 0x2130
movq (%rbx), %rsi
leaq -0x3d8(%rbp), %rdi
pushq $0x10
popq %rdx
callq 0x2270
callq 0x2310
leaq -0x3d8(%rbp), %rdi
movl %eax, %esi
callq 0x2380
leaq -0x3d8(%rbp), %rdi
callq 0x22f0
movq 0x83b3(%rip), %rdi      # 0xafd0
leaq 0x4448(%rip), %rsi      # 0x706c
callq 0x2230
movq %rax, %rdi
callq 0x2170
leaq 0x43e3(%rip), %rdx      # 0x701b
leaq -0x58(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x2f7f
leaq 0x43d8(%rip), %rdx      # 0x7024
leaq -0x38(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x2f7f
leaq 0x43d9(%rip), %rdx      # 0x7039
leaq -0xd8(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x2f7f
leaq 0x43b6(%rip), %rdx      # 0x702d
leaq -0x178(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x2f7f
pushq $0x38
popq %rdi
callq 0x2240
movq %rax, %r14
leaq -0x158(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x22e0
leaq -0x138(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x22e0
leaq -0x118(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x22e0
leaq -0xf8(%rbp), %rdi
leaq -0x178(%rbp), %rsi
callq 0x22e0
leaq -0x158(%rbp), %rsi
leaq -0x138(%rbp), %rdx
leaq -0x118(%rbp), %rcx
leaq -0xf8(%rbp), %r8
movq %r14, %rdi
callq 0x3b50
leaq -0xf8(%rbp), %rdi
callq 0x2130
leaq -0x118(%rbp), %rdi
callq 0x2130
leaq -0x138(%rbp), %rdi
callq 0x2130
leaq -0x158(%rbp), %rdi
callq 0x2130
movq %r14, %rdi
callq 0x4386
movq %r14, %rdi
callq 0x3c3e
pushq $0x38
popq %rsi
movq %r14, %rdi
callq 0x2250
movq -0x58(%rbp), %rdi
callq 0x2160
movq -0x38(%rbp), %rdi
callq 0x2160
movq -0xd8(%rbp), %rdi
callq 0x2160
movq -0x178(%rbp), %rdi
callq 0x2160
movq -0xb8(%rbp), %rdi
callq 0x2160
leaq 0x42ff(%rip), %rdi      # 0x7083
callq 0x2320
movq -0x98(%rbp), %rdi
callq 0x2100
jmp 0x2ba8
movq %rax, %rbx
leaq -0xf8(%rbp), %rdi
callq 0x2130
jmp 0x2dae
movq %rax, %rbx
leaq -0x118(%rbp), %rdi
callq 0x2130
jmp 0x2dbf
movq %rax, %rbx
leaq -0x138(%rbp), %rdi
callq 0x2130
jmp 0x2dd0
movq %rax, %rbx
leaq -0x158(%rbp), %rdi
callq 0x2130
jmp 0x2de1
movq %rax, %rbx
pushq $0x38
popq %rsi
movq %r14, %rdi
callq 0x2250
jmp 0x2df1
movq %rax, %rbx
leaq -0x178(%rbp), %rdi
callq 0x2130
jmp 0x2e02
movq %rax, %rbx
leaq -0xd8(%rbp), %rdi
callq 0x2130
jmp 0x2e13
movq %rax, %rbx
leaq -0x38(%rbp), %rdi
callq 0x2130
jmp 0x2e21
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x2130
jmp 0x2e31
jmp 0x2e2e
movq %rax, %rbx
leaq -0x3d8(%rbp), %rdi
callq 0x2330
jmp 0x2ef8
jmp 0x2ef5
jmp 0x2ef5
jmp 0x2e8b
jmp 0x2ed5
movq %rax, %rbx
leaq -0x198(%rbp), %rdi
callq 0x2130
jmp 0x2e69
jmp 0x2ee3
movq %rax, %rbx
leaq -0x1b8(%rbp), %rdi
callq 0x2130
jmp 0x2e7c
jmp 0x2ef5
movq %rax, %rbx
pushq $0x8
popq %rsi
movq %r14, %rdi
callq 0x2250
jmp 0x2e8e
jmp 0x2ed5
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
jmp 0x2eb0
jmp 0x2ee3
movq %rax, %rbx
leaq -0x38(%rbp), %rdi
callq 0x2130
jmp 0x2ea9
jmp 0x2ef5
movq %rax, %rbx
leaq -0xd8(%rbp), %rdi
callq 0x2130
jmp 0x2ebc
jmp 0x2ed5
movq %rax, %rbx
leaq -0x3d8(%rbp), %rdi
jmp 0x2eea
jmp 0x2ee3
jmp 0x2ed5
jmp 0x2ef5
jmp 0x2ee3
jmp 0x2ed5
jmp 0x2ef5
jmp 0x2ee3
jmp 0x2ef5
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x2130
jmp 0x2ee6
movq %rax, %rbx
leaq -0x38(%rbp), %rdi
callq 0x2130
jmp 0x2ef8
jmp 0x2ef5
jmp 0x2ef5
movq %rax, %rbx
leaq -0x1d8(%rbp), %rdi
callq 0x2130
leaq -0x78(%rbp), %rdi
callq 0x2130
leaq -0xb8(%rbp), %rdi
callq 0x2130
leaq -0x98(%rbp), %rdi
callq 0x2130
movq %rbx, %rdi
callq 0x2390