// File: /workspace/github_cpp_makefile_star2_O3/luisremis[P]SDFS/FileSystem.cpp
// Function: FileSystem::sendFileByRange(int, FileSystem::Message_fs)
bool FileSystem::sendFileByRange(int connFd, Message_fs msg )
{
    bool deleteMyCopy = ( (msg.type == MSG_PULL_MV) ? true : false );

    logFile<<"sendFileByRange: "<<msg.minKey<<" to "<<msg.maxKey<<endl;

    std::vector<std::string> toremove;
    filesLock.lock();
    size_t count = 0;
    for( auto &file : files ){
        if( inRange(file.key, msg.minKey, msg.maxKey) )
            count++;
    }
    msg.size = count;
    write(connFd, &msg, sizeof(Message_fs));
    for( auto &file : files )
    {
        if( inRange(file.key, msg.minKey, msg.maxKey) )
        {
            memset(msg.filename, '\0', 200);
            file.filename.copy(msg.filename, file.filename.length() );

            // cout<<"sendFileByRange: "<<file.filename<<" "<<msg.filename<<endl;
            logFile<<"sendFileByRange: "<<file.filename<<" rm:"<<deleteMyCopy<<endl;

            char * buffer; 
            msg.size = readFile(file.filename, &buffer);

            write(connFd, &msg, sizeof(Message_fs));
            splitWrite(connFd, buffer, msg.size);

            delete buffer;

            if(deleteMyCopy)
            {
                //files.remove( file );   //maintain file list
                toremove.push_back(file.filename);
            }
        }
    }

    for (int i = 0; i < toremove.size(); ++i)
    {
        if ( deleteFile( toremove.at(i) ) ) 
        {
            logFile << toremove.at(i) << "deleted" << std::endl;
        }
        files.remove(toremove.at(i));
    }

    filesLock.unlock();

    return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movl %esi, -0x2c(%rbp)
movq %rdi, %rbx
movl 0x10(%rbp), %eax
movl %eax, -0x30(%rbp)
leaq 0x5ca0(%rip), %rsi      # 0x13b77
movl $0x11, %edx
callq 0x43f0
movl 0xe8(%rbp), %r14d
movq %rbx, %rdi
movl %r14d, %esi
callq 0x45f0
movq %rax, %r15
leaq 0x58b7(%rip), %rsi      # 0x137b4
movl $0x4, %edx
movq %rax, %rdi
callq 0x43f0
movl 0xec(%rbp), %r12d
movq %r15, %rdi
movl %r12d, %esi
callq 0x45f0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x4380
movsbl %al, %esi
movq %r15, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x4260
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
movq $0x0, -0x40(%rbp)
leaq 0x228(%rbx), %r15
movq %r15, %rdi
callq 0x44d0
testl %eax, %eax
jne 0xe354
leaq 0x10(%rbp), %r13
leaq 0x210(%rbx), %rax
movq 0x210(%rbx), %rcx
movq %rax, -0x38(%rbp)
cmpq %rax, %rcx
je 0xdfda
xorl %eax, %eax
movl 0x30(%rcx), %edx
cmpl %r12d, %r14d
jge 0xdfa5
cmpl %edx, %r14d
setl %sil
cmpl %r12d, %edx
setle %dl
testb %dl, %sil
jne 0xdfcc
jmp 0xdfcf
testl %edx, %edx
setns %sil
cmpl %r12d, %edx
setle %dil
testb %dil, %sil
jne 0xdfcc
cmpl %edx, %r14d
setge %sil
cmpl $0x3e9, %edx            # imm = 0x3E9
setge %dl
orb %sil, %dl
jne 0xdfcf
incq %rax
movq (%rcx), %rcx
cmpq -0x38(%rbp), %rcx
jne 0xdf89
jmp 0xdfdc
xorl %eax, %eax
movq %r15, -0x58(%rbp)
movq %rbx, %r15
movq %rax, 0xd0(%r13)
movl $0xe0, %edx
movl -0x2c(%rbp), %edi
movq %r13, %rsi
callq 0x4170
movq -0x38(%rbp), %rax
movq (%rax), %rbx
cmpq %rax, %rbx
je 0xe1a8
leaq 0x4(%r13), %rax
movq %rax, -0x60(%rbp)
movl 0x30(%rbx), %eax
movl 0xd8(%r13), %ecx
movl 0xdc(%r13), %edx
cmpl %edx, %ecx
jge 0xe03a
cmpl %eax, %ecx
setl %cl
cmpl %edx, %eax
setle %al
testb %al, %cl
jne 0xe05f
jmp 0xe19b
testl %eax, %eax
setns %sil
cmpl %edx, %eax
setle %dl
testb %dl, %sil
jne 0xe05f
cmpl %eax, %ecx
setge %cl
cmpl $0x3e9, %eax            # imm = 0x3E9
setge %al
orb %cl, %al
jne 0xe19b
leaq 0x10(%rbx), %r12
movl $0xc8, %edx
movq -0x60(%rbp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x4220
movq 0x18(%rbx), %rdx
movq %r12, %rdi
movq %r14, %rsi
xorl %ecx, %ecx
callq 0x40a0
movl $0x11, %edx
movq %r15, %rdi
leaq 0x5ae1(%rip), %rsi      # 0x13b77
callq 0x43f0
movq 0x10(%rbx), %rsi
movq 0x18(%rbx), %rdx
movq %r15, %rdi
callq 0x43f0
movq %rax, %r14
movl $0x4, %edx
movq %rax, %rdi
leaq 0x5acc(%rip), %rsi      # 0x13b89
callq 0x43f0
xorl %esi, %esi
cmpl $0x4, -0x30(%rbp)
sete %sil
movq %r14, %rdi
callq 0x45a0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x4380
movsbl %al, %esi
movq %r14, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x4260
leaq -0x90(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq 0x10(%rbx), %rsi
movq 0x18(%rbx), %rdx
addq %rsi, %rdx
leaq -0xa0(%rbp), %rdi
callq 0x56fa
movq %r15, %rdi
leaq -0xa0(%rbp), %rsi
leaq -0xe8(%rbp), %rdx
callq 0xdc0a
movq %rax, 0xd0(%r13)
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0xe158
callq 0x4360
movl $0xe0, %edx
movl -0x2c(%rbp), %edi
movq %r13, %rsi
callq 0x4170
movq -0xe8(%rbp), %r14
movq 0xd0(%r13), %rdx
movl -0x2c(%rbp), %edi
movq %r14, %rsi
callq 0x117ea
movq %r14, %rdi
callq 0x4360
cmpl $0x4, -0x30(%rbp)
jne 0xe19b
leaq -0x50(%rbp), %rdi
movq %r12, %rsi
callq 0xa33c
movq (%rbx), %rbx
cmpq -0x38(%rbp), %rbx
jne 0xe012
movq -0x50(%rbp), %rax
cmpq %rax, -0x48(%rbp)
je 0xe30c
movl $0x8, %ebx
xorl %r14d, %r14d
leaq -0xe8(%rbp), %r12
leaq -0x70(%rbp), %rcx
movq %rcx, -0x80(%rbp)
movq -0x8(%rax,%rbx), %rsi
movq (%rax,%rbx), %rdx
addq %rsi, %rdx
leaq -0x80(%rbp), %rdi
callq 0x56fa
leaq -0x80(%rbp), %rsi
callq 0xd150
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0xe1fd
callq 0x4360
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rdx
subq %rax, %rdx
sarq $0x5, %rdx
cmpq %r14, %rdx
jbe 0xe343
movq -0x8(%rax,%rbx), %rsi
movq (%rax,%rbx), %rdx
movq %r15, %rdi
callq 0x43f0
movq %rax, %r13
movl $0x7, %edx
movq %rax, %rdi
leaq 0x588a(%rip), %rsi      # 0x13ac2
callq 0x43f0
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x4380
movsbl %al, %esi
movq %r13, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x4260
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rdx
subq %rax, %rdx
sarq $0x5, %rdx
cmpq %r14, %rdx
jbe 0xe332
leaq -0xb0(%rbp), %rcx
movq %rcx, -0xc0(%rbp)
movq -0x8(%rax,%rbx), %rsi
movq (%rax,%rbx), %rdx
addq %rsi, %rdx
leaq -0xc0(%rbp), %r13
movq %r13, %rdi
callq 0x56fa
movq %r12, %rdi
movq %r13, %rsi
callq 0xe562
movq -0x38(%rbp), %rdi
movq %r12, %rsi
callq 0xfef6
movq -0xe8(%rbp), %rdi
leaq -0xd8(%rbp), %rax
cmpq %rax, %rdi
je 0xe2d5
callq 0x4360
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
cmpq %rax, %rdi
je 0xe2ed
callq 0x4360
incq %r14
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rcx
subq %rax, %rcx
sarq $0x5, %rcx
addq $0x20, %rbx
cmpq %r14, %rcx
ja 0xe1c5
movq -0x58(%rbp), %rdi
callq 0x42a0
leaq -0x50(%rbp), %rdi
callq 0xa29e
movb $0x1, %al
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x563c(%rip), %rdi      # 0x13975
movq %r14, %rsi
xorl %eax, %eax
callq 0x44e0
leaq 0x562b(%rip), %rdi      # 0x13975
movq %r14, %rsi
xorl %eax, %eax
callq 0x44e0
movl %eax, %edi
callq 0x4240
jmp 0xe3c3
jmp 0xe3c3
movq %rax, %r14
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
jmp 0xe3b3
movq %rax, %r14
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
jmp 0xe3b3
jmp 0xe3c3
jmp 0xe3c3
jmp 0xe3c3
movq %rax, %r14
jmp 0xe3a5
movq %rax, %r14
movq -0xe8(%rbp), %rdi
leaq -0xd8(%rbp), %rax
cmpq %rax, %rdi
je 0xe3a5
callq 0x4360
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
cmpq %rax, %rdi
je 0xe3c6
callq 0x4360
jmp 0xe3c6
jmp 0xe3c3
jmp 0xe3c3
movq %rax, %r14
leaq -0x50(%rbp), %rdi
callq 0xa29e
movq %r14, %rdi
callq 0x4630