// File: /workspace/github_cpp_makefile_star2_O1/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, %r15
movl 0x10(%rbp), %eax
movl %eax, -0x30(%rbp)
leaq 0x5b4e(%rip), %rsi      # 0x13b77
movl $0x11, %edx
callq 0x43f0
movl 0xe8(%rbp), %esi
movq %r15, %rdi
callq 0x45f0
movq %rax, %r14
leaq 0x5769(%rip), %rsi      # 0x137b4
movl $0x4, %edx
movq %rax, %rdi
callq 0x43f0
movl 0xec(%rbp), %esi
movq %r14, %rdi
callq 0x45f0
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
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
movq $0x0, -0x40(%rbp)
leaq 0x228(%r15), %rbx
movq %rbx, %rdi
callq 0x44d0
testl %eax, %eax
jne 0xe4a6
leaq 0x10(%rbp), %r13
leaq 0x210(%r15), %rax
movq 0x210(%r15), %rcx
movq %rax, -0x38(%rbp)
cmpq %rax, %rcx
je 0xe12f
movl 0xd8(%r13), %edx
movl 0xdc(%r13), %esi
xorl %eax, %eax
movl 0x30(%rcx), %edi
cmpl %esi, %edx
jge 0xe0f6
cmpl %edi, %edx
setl %r9b
cmpl %esi, %edi
setle %r8b
jmp 0xe11a
testl %edi, %edi
setns %r9b
cmpl %esi, %edi
setle %r10b
movb $0x1, %r8b
testb %r10b, %r9b
jne 0xe11d
cmpl %edi, %edx
setl %r9b
cmpl $0x3e9, %edi            # imm = 0x3E9
setl %r8b
andb %r9b, %r8b
movzbl %r8b, %edi
addq %rdi, %rax
movq (%rcx), %rcx
cmpq -0x38(%rbp), %rcx
jne 0xe0e1
jmp 0xe131
xorl %eax, %eax
movq %rbx, -0x58(%rbp)
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 0xe2fa
leaq 0x4(%r13), %rax
movq %rax, -0x60(%rbp)
movl 0x30(%rbx), %eax
movl 0xd8(%r13), %ecx
movl 0xdc(%r13), %edx
cmpl %edx, %ecx
jge 0xe185
cmpl %eax, %ecx
setl %cl
cmpl %edx, %eax
setle %al
jmp 0xe1a2
testl %eax, %eax
setns %sil
cmpl %edx, %eax
setle %dl
testb %dl, %sil
jne 0xe1ac
cmpl %eax, %ecx
setl %cl
cmpl $0x3e9, %eax            # imm = 0x3E9
setl %al
andb %cl, %al
testb %al, %al
je 0xe2ed
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 0x5994(%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 0x597f(%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 0x570a
movq %r15, %rdi
leaq -0xa0(%rbp), %rsi
leaq -0xe8(%rbp), %rdx
callq 0xdd5c
movq %rax, 0xd0(%r13)
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0xe2a5
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 0x11963
testq %r14, %r14
je 0xe2db
movq %r14, %rdi
callq 0x4360
cmpl $0x4, -0x30(%rbp)
jne 0xe2ed
leaq -0x50(%rbp), %rdi
movq %r12, %rsi
callq 0xa420
movq (%rbx), %rbx
cmpq -0x38(%rbp), %rbx
jne 0xe164
movq -0x50(%rbp), %rax
cmpq %rax, -0x48(%rbp)
je 0xe45e
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 0x570a
leaq -0x80(%rbp), %rsi
callq 0xd28e
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0xe34f
callq 0x4360
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rdx
subq %rax, %rdx
sarq $0x5, %rdx
cmpq %r14, %rdx
jbe 0xe495
movq -0x8(%rax,%rbx), %rsi
movq (%rax,%rbx), %rdx
movq %r15, %rdi
callq 0x43f0
movq %rax, %r13
movl $0x7, %edx
movq %rax, %rdi
leaq 0x5738(%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 0xe484
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 0x570a
movq %r12, %rdi
movq %r13, %rsi
callq 0xe6b4
movq -0x38(%rbp), %rdi
movq %r12, %rsi
callq 0x1003a
movq -0xe8(%rbp), %rdi
leaq -0xd8(%rbp), %rax
cmpq %rax, %rdi
je 0xe427
callq 0x4360
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
cmpq %rax, %rdi
je 0xe43f
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 0xe317
movq -0x58(%rbp), %rdi
callq 0x42a0
leaq -0x50(%rbp), %rdi
callq 0xa38c
movb $0x1, %al
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x54ea(%rip), %rdi      # 0x13975
movq %r14, %rsi
xorl %eax, %eax
callq 0x44e0
leaq 0x54d9(%rip), %rdi      # 0x13975
movq %r14, %rsi
xorl %eax, %eax
callq 0x44e0
movl %eax, %edi
callq 0x4240
jmp 0xe515
jmp 0xe515
movq %rax, %r14
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
jmp 0xe505
movq %rax, %r14
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
jmp 0xe505
jmp 0xe515
jmp 0xe515
jmp 0xe515
movq %rax, %r14
jmp 0xe4f7
movq %rax, %r14
movq -0xe8(%rbp), %rdi
leaq -0xd8(%rbp), %rax
cmpq %rax, %rdi
je 0xe4f7
callq 0x4360
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
cmpq %rax, %rdi
je 0xe518
callq 0x4360
jmp 0xe518
jmp 0xe515
jmp 0xe515
movq %rax, %r14
leaq -0x50(%rbp), %rdi
callq 0xa38c
movq %r14, %rdi
callq 0x4630