// File: /workspace/github_cpp_makefile_star2_O3/billDrett[P]Bulletin-Boards/boardPost.cpp
// Function: BoardPost::sendFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int)
void BoardPost::sendFile(string file, int Id)
{
    int fp, found;
    int nread, nwrite;
    char buff[BUFFERSIZE];
    string name, tmpName;
    char convert[24];

    fp =open(file.c_str(), O_RDONLY, 0644);
    if(fp == -1) return;

    if((nwrite = write(pipeBoardPost2Server, "<File>", 6))== -1) //stelnoume ta tags gia arxh File
    {
        perror("Cant write to pipe BP2S");
    }
    if((nwrite = write(pipeBoardPost2Server, "<start>", 7))== -1)
    {
        perror("Cant write to pipe C2S");
    }
    sprintf(convert, "%d", Id);
    name.append(convert); //stelnw to chanel
    name.append(" ");
    found = file.find_last_of("/"); //prepei na parw to onoma, epeidh mporei na einai path pairnw to string meta to teleutaio "/"
    if(found ==  string::npos)
    {
        tmpName = file;
    }
    else
    {
        tmpName = file.substr(found+1);
    }
    name.append(tmpName);

    for(int i = name.size(); i <30; i++) //SYMVASH ta prwta 30 tha einai gia to chanelId kai to onoma tou arxeiou ara gemizw to ypoloipo me space
    {
        name.append(" ");
    }

    if((nwrite = write(pipeBoardPost2Server, name.c_str(), name.size()))== -1)
    {
        perror("Cant write to pipe BP2S");
    }

    while((nread = read(fp, buff, BUFFERSIZE)) > 0) //stelnw to arxeio
    {
        if(write(pipeBoardPost2Server, buff, nread) == -1)
        {
            perror("Cant write to pipe BP2S");
        }
    }

    if((nwrite = write(pipeBoardPost2Server, "<end>", 5))== -1)
    {
        perror("Cant write to pipe C2S");
    }

    if((nwrite = write(pipeBoardPost2Server, "<File>", 6))== -1)
    {
        perror("Cant write to pipe BP2S");
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x478, %rsp            # imm = 0x478
movl %edx, %r12d
movq %rsi, %r15
movq %rdi, %rbx
leaq -0x38(%rbp), %r13
movq %r13, -0x10(%r13)
xorl %eax, %eax
movq %rax, -0x8(%r13)
movb %al, (%r13)
leaq -0x58(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
movq (%rsi), %rdi
xorl %esi, %esi
movl $0x1a4, %edx            # imm = 0x1A4
xorl %eax, %eax
callq 0x2120
movl %eax, %r14d
cmpl $-0x1, %eax
je 0x32ff
movl (%rbx), %edi
leaq 0xfca(%rip), %rsi       # 0x40fd
movl $0x6, %edx
callq 0x20a0
cmpl $-0x1, %eax
je 0x3264
movl (%rbx), %edi
leaq 0xf7a(%rip), %rsi       # 0x40c9
movl $0x7, %edx
callq 0x20a0
cmpl $-0x1, %eax
je 0x3275
leaq 0xf80(%rip), %rsi       # 0x40e9
leaq -0xa0(%rbp), %r13
movq %r13, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0x2040
leaq -0x48(%rbp), %rdi
movq %r13, %rsi
leaq -0x38(%rbp), %r13
callq 0x2280
leaq 0xfac(%rip), %rsi       # 0x4140
leaq -0x48(%rbp), %rdi
callq 0x2280
leaq 0xe70(%rip), %rsi       # 0x4014
movl $0x1, %ecx
movq %r15, %rdi
movq $-0x1, %rdx
callq 0x22a0
cmpl $-0x1, %eax
jne 0x31cb
leaq -0x68(%rbp), %rdi
movq %r15, %rsi
callq 0x20e0
jmp 0x3211
incl %eax
movslq %eax, %rdx
leaq -0x88(%rbp), %rdi
movq %r15, %rsi
movq $-0x1, %rcx
callq 0x2190
leaq -0x68(%rbp), %rdi
leaq -0x88(%rbp), %r15
movq %r15, %rsi
callq 0x21d0
movq (%r15), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x3211
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x2180
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
leaq -0x48(%rbp), %rdi
callq 0x2080
movq -0x40(%rbp), %rdx
cmpl $0x1d, %edx
jg 0x3252
leal -0x1e(%rdx), %r13d
leaq 0xf0a(%rip), %r15       # 0x4140
leaq -0x48(%rbp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x2280
incl %r13d
jne 0x323a
movq -0x40(%rbp), %rdx
leaq -0x38(%rbp), %r13
movl (%rbx), %edi
movq -0x48(%rbp), %rsi
callq 0x20a0
cmpl $-0x1, %eax
je 0x3290
jmp 0x329c
leaq 0xe66(%rip), %rdi       # 0x40d1
callq 0x2140
jmp 0x3146
leaq 0xe88(%rip), %rdi       # 0x4104
callq 0x2140
jmp 0x3162
jmp 0x335d
jmp 0x335d
leaq 0xe3a(%rip), %rdi       # 0x40d1
callq 0x2140
leaq -0x4a0(%rbp), %r15
movl $0x400, %edx            # imm = 0x400
movl %r14d, %edi
movq %r15, %rsi
callq 0x2200
movl (%rbx), %edi
testl %eax, %eax
jle 0x32d1
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %r15, %rsi
movq %rax, %rdx
callq 0x20a0
cmpq $-0x1, %rax
jne 0x32a3
jmp 0x3290
leaq 0xde2(%rip), %rsi       # 0x40ba
movl $0x5, %edx
callq 0x20a0
cmpl $-0x1, %eax
je 0x333f
movl (%rbx), %edi
leaq 0xe0d(%rip), %rsi       # 0x40fd
movl $0x6, %edx
callq 0x20a0
cmpl $-0x1, %eax
je 0x334d
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x3318
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2180
movq -0x48(%rbp), %rdi
cmpq %r13, %rdi
je 0x332d
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2180
addq $0x478, %rsp            # imm = 0x478
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xdbe(%rip), %rdi       # 0x4104
callq 0x2140
jmp 0x32e7
leaq 0xd7d(%rip), %rdi       # 0x40d1
callq 0x2140
jmp 0x32ff
jmp 0x335d
movq %rax, %rbx
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x3379
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2180
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x3392
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2180
movq %rbx, %rdi
callq 0x2250