// File: /workspace/github_cpp_makefile_star2_O1/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), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
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 0x32fa
movl (%rbx), %edi
leaq 0xfc8(%rip), %rsi       # 0x40fd
movl $0x6, %edx
callq 0x20a0
cmpl $-0x1, %eax
je 0x325f
movl (%rbx), %edi
leaq 0xf78(%rip), %rsi       # 0x40c9
movl $0x7, %edx
callq 0x20a0
cmpl $-0x1, %eax
je 0x3270
leaq 0xf7e(%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
callq 0x2280
leaq 0xfae(%rip), %rsi       # 0x4140
leaq -0x48(%rbp), %rdi
callq 0x2280
leaq 0xe72(%rip), %rsi       # 0x4014
movl $0x1, %ecx
movq %r15, %rdi
movq $-0x1, %rdx
callq 0x22a0
cmpl $-0x1, %eax
jne 0x31c9
leaq -0x68(%rbp), %rdi
movq %r15, %rsi
callq 0x20e0
jmp 0x320f
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 0x320f
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x2180
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
leaq -0x48(%rbp), %rdi
callq 0x2080
movl -0x40(%rbp), %r13d
cmpl $0x1d, %r13d
jg 0x3249
addl $-0x1e, %r13d
leaq 0xf0b(%rip), %r15       # 0x4140
leaq -0x48(%rbp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x2280
incl %r13d
jne 0x3239
movl (%rbx), %edi
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq 0x20a0
cmpl $-0x1, %eax
je 0x328b
jmp 0x3297
leaq 0xe6b(%rip), %rdi       # 0x40d1
callq 0x2140
jmp 0x3148
leaq 0xe8d(%rip), %rdi       # 0x4104
callq 0x2140
jmp 0x3164
jmp 0x335c
jmp 0x335c
leaq 0xe3f(%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 0x32cc
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %r15, %rsi
movq %rax, %rdx
callq 0x20a0
cmpq $-0x1, %rax
jne 0x329e
jmp 0x328b
leaq 0xde7(%rip), %rsi       # 0x40ba
movl $0x5, %edx
callq 0x20a0
cmpl $-0x1, %eax
je 0x333e
movl (%rbx), %edi
leaq 0xe12(%rip), %rsi       # 0x40fd
movl $0x6, %edx
callq 0x20a0
cmpl $-0x1, %eax
je 0x334c
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x3313
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2180
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x332c
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 0xdbf(%rip), %rdi       # 0x4104
callq 0x2140
jmp 0x32e2
leaq 0xd7e(%rip), %rdi       # 0x40d1
callq 0x2140
jmp 0x32fa
jmp 0x335c
movq %rax, %rbx
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x3378
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2180
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x3391
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2180
movq %rbx, %rdi
callq 0x2250
nop