// File: 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
subq $0x530, %rsp            # imm = 0x530
movq %rsi, -0x4d0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x4d8(%rbp)
leaq -0x450(%rbp), %rdi
callq 0x2260
leaq -0x470(%rbp), %rdi
callq 0x2260
movq -0x4d0(%rbp), %rdi
callq 0x20d0
movq %rax, %rdi
xorl %esi, %esi
movb %sil, %al
movl $0x1a4, %edx            # imm = 0x1A4
callq 0x2170
movl %eax, -0x4c8(%rbp)
jmp 0x32f6
movl -0x4c8(%rbp), %eax
movl %eax, -0x18(%rbp)
cmpl $-0x1, -0x18(%rbp)
jne 0x3343
movl $0x1, -0x4a0(%rbp)
jmp 0x3658
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x498(%rbp)
movl %eax, -0x49c(%rbp)
leaq -0x470(%rbp), %rdi
callq 0x2150
leaq -0x450(%rbp), %rdi
callq 0x2150
jmp 0x3679
movq -0x4d8(%rbp), %rax
movl (%rax), %edi
leaq 0xd80(%rip), %rsi       # 0x40d3
movl $0x6, %edx
callq 0x20b0
movq %rax, -0x4e0(%rbp)
jmp 0x3366
movq -0x4e0(%rbp), %rax
movl %eax, -0x24(%rbp)
cmpl $-0x1, %eax
jne 0x3385
leaq 0xd2b(%rip), %rdi       # 0x40a7
callq 0x2180
jmp 0x3383
jmp 0x3385
movq -0x4d8(%rbp), %rax
movl (%rax), %edi
leaq 0xd0a(%rip), %rsi       # 0x409f
movl $0x7, %edx
callq 0x20b0
movq %rax, -0x4e8(%rbp)
jmp 0x33a8
movq -0x4e8(%rbp), %rax
movl %eax, -0x24(%rbp)
cmpl $-0x1, %eax
jne 0x33c7
leaq 0xd1c(%rip), %rdi       # 0x40da
callq 0x2180
jmp 0x33c5
jmp 0x33c7
movl -0x14(%rbp), %edx
leaq 0xcee(%rip), %rsi       # 0x40bf
xorl %eax, %eax
leaq -0x490(%rbp), %rdi
movq %rdi, -0x4f0(%rbp)
callq 0x2050
movq -0x4f0(%rbp), %rsi
leaq -0x450(%rbp), %rdi
callq 0x22c0
jmp 0x33fb
leaq 0xd14(%rip), %rsi       # 0x4116
leaq -0x450(%rbp), %rdi
callq 0x22c0
jmp 0x3410
movq -0x4d0(%rbp), %rdi
leaq 0xbf6(%rip), %rsi       # 0x4014
movq $-0x1, %rdx
callq 0x21b0
movl %eax, -0x1c(%rbp)
movslq -0x1c(%rbp), %rax
cmpq $-0x1, %rax
jne 0x344e
movq -0x4d0(%rbp), %rsi
leaq -0x470(%rbp), %rdi
callq 0x2040
jmp 0x344c
jmp 0x3491
movq -0x4d0(%rbp), %rsi
movl -0x1c(%rbp), %eax
incl %eax
movslq %eax, %rdx
leaq -0x4c0(%rbp), %rdi
movq $-0x1, %rcx
callq 0x21f0
jmp 0x3472
leaq -0x470(%rbp), %rdi
leaq -0x4c0(%rbp), %rsi
callq 0x2220
leaq -0x4c0(%rbp), %rdi
callq 0x2150
leaq -0x450(%rbp), %rdi
leaq -0x470(%rbp), %rsi
callq 0x22d0
jmp 0x34a6
leaq -0x450(%rbp), %rdi
callq 0x2160
movl %eax, -0x4c4(%rbp)
cmpl $0x1e, -0x4c4(%rbp)
jge 0x34e9
leaq 0xc4e(%rip), %rsi       # 0x4116
leaq -0x450(%rbp), %rdi
callq 0x22c0
jmp 0x34d6
jmp 0x34d8
movl -0x4c4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c4(%rbp)
jmp 0x34b8
movq -0x4d8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x504(%rbp)
leaq -0x450(%rbp), %rdi
movq %rdi, -0x510(%rbp)
callq 0x20d0
movq -0x510(%rbp), %rdi
movq %rax, -0x500(%rbp)
callq 0x2160
movl -0x504(%rbp), %edi
movq -0x500(%rbp), %rsi
movq %rax, %rdx
callq 0x20b0
movq %rax, -0x4f8(%rbp)
jmp 0x353c
movq -0x4f8(%rbp), %rax
movl %eax, -0x24(%rbp)
cmpl $-0x1, %eax
jne 0x355b
leaq 0xb55(%rip), %rdi       # 0x40a7
callq 0x2180
jmp 0x3559
jmp 0x355b
jmp 0x355d
movl -0x18(%rbp), %edi
leaq -0x430(%rbp), %rsi
movl $0x400, %edx            # imm = 0x400
callq 0x2270
movq %rax, -0x518(%rbp)
jmp 0x357a
movq -0x518(%rbp), %rax
movl %eax, -0x20(%rbp)
cmpl $0x0, %eax
jle 0x35ca
movq -0x4d8(%rbp), %rax
movl (%rax), %edi
movslq -0x20(%rbp), %rdx
leaq -0x430(%rbp), %rsi
callq 0x20b0
movq %rax, -0x520(%rbp)
jmp 0x35ab
movq -0x520(%rbp), %rax
cmpq $-0x1, %rax
jne 0x35c8
leaq 0xae8(%rip), %rdi       # 0x40a7
callq 0x2180
jmp 0x35c6
jmp 0x35c8
jmp 0x355d
movq -0x4d8(%rbp), %rax
movl (%rax), %edi
leaq 0xab6(%rip), %rsi       # 0x4090
movl $0x5, %edx
callq 0x20b0
movq %rax, -0x528(%rbp)
jmp 0x35ed
movq -0x528(%rbp), %rax
movl %eax, -0x24(%rbp)
cmpl $-0x1, %eax
jne 0x360c
leaq 0xad7(%rip), %rdi       # 0x40da
callq 0x2180
jmp 0x360a
jmp 0x360c
movq -0x4d8(%rbp), %rax
movl (%rax), %edi
leaq 0xab7(%rip), %rsi       # 0x40d3
movl $0x6, %edx
callq 0x20b0
movq %rax, -0x530(%rbp)
jmp 0x362f
movq -0x530(%rbp), %rax
movl %eax, -0x24(%rbp)
cmpl $-0x1, %eax
jne 0x364e
leaq 0xa62(%rip), %rdi       # 0x40a7
callq 0x2180
jmp 0x364c
jmp 0x364e
movl $0x0, -0x4a0(%rbp)
leaq -0x470(%rbp), %rdi
callq 0x2150
leaq -0x450(%rbp), %rdi
callq 0x2150
addq $0x530, %rsp            # imm = 0x530
popq %rbp
retq
movq -0x498(%rbp), %rdi
callq 0x22a0
nopw %cs:(%rax,%rax)