// File: /workspace/github_cpp_makefile_star2_O2/luisremis[P]SDFS/Membership.cpp
// Function: Membership::spreadMessage(Message, int)
void Membership::spreadMessage(Message msg, int forwardNumber)
{
    //choose k or size-1 members
    membersLock.lock();
    std::vector<Node> selectedNode = members; 
    membersLock.unlock();

    if (selectedNode.size() < 3) return;   // Not enough nodes to do something
    // We need to remeve myself and the carrier from the possible list

    selectedNode.erase(selectedNode.begin()); // remove myself

    for (int i = 0; i < selectedNode.size(); ++i)
    {
        logFile << "comparing: " << selectedNode.at(i).ip_str << " " << char42String(msg.carrierAdd) << std::endl;
        if ( selectedNode.at(i).ip_str.compare(char42String(msg.carrierAdd)) == 0 )
        {
            selectedNode.erase(selectedNode.begin() + i); // remove carrier
            logFile << "equal" << std::endl;
            break;
        }
    }

    int k = forwardNumber == 0 ? K_FORWARD : forwardNumber;

    while (selectedNode.size() > 0 && k > 0)
    {
        int random = rand() % selectedNode.size();
        sendUDP( sockfd, selectedNode[random].ip_str, port, (char*)&msg, sizeof(Message) );
        selectedNode.erase(selectedNode.begin()+random);
        k--;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %esi, -0x44(%rbp)
movq %rdi, %rbx
leaq 0x230(%rdi), %r14
movq %r14, %rdi
callq 0x8608
leaq 0x258(%rbx), %rsi
leaq -0x40(%rbp), %r15
movq %r15, %rdi
callq 0x88ba
movq %r14, %rdi
callq 0x4290
movq (%r15), %rsi
movq 0x8(%r15), %rax
subq %rsi, %rax
pushq $0x28
popq %rcx
cqto
idivq %rcx
cmpq $0x3, %rax
jae 0x6c99
leaq -0x40(%rbp), %rdi
callq 0x86dc
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq -0x40(%rbp), %rdi
callq 0x8914
leaq 0x10(%rbp), %rax
addq $0x5, %rax
movq %rax, -0x50(%rbp)
pushq $-0x28
popq %r12
xorl %r15d, %r15d
leaq -0x70(%rbp), %r14
movq -0x38(%rbp), %rax
subq -0x40(%rbp), %rax
cqto
pushq $0x28
popq %rcx
idivq %rcx
cmpq %r15, %rax
jbe 0x6d9b
movq %rbx, %rdi
leaq 0x8c5f(%rip), %rsi      # 0xf93b
callq 0x4370
movq %rax, %r13
leaq -0x40(%rbp), %rdi
movq %r15, %rsi
callq 0x8754
movq %r13, %rdi
movq %rax, %rsi
callq 0x4300
movq %rax, %rdi
leaq 0x861d(%rip), %rsi      # 0xf322
callq 0x4370
movq %rax, %r13
movq %r14, %rdi
movq -0x50(%rbp), %rsi
callq 0xd999
movq %r13, %rdi
movq %r14, %rsi
callq 0x4300
movq %rax, %rdi
callq 0x41d0
movq %r14, %rdi
callq 0x41b0
leaq -0x40(%rbp), %rdi
movq %r15, %rsi
callq 0x8754
movq %rax, %r13
movq %r14, %rdi
movq -0x50(%rbp), %rsi
callq 0xd999
movq %r13, %rdi
movq %r14, %rsi
callq 0x4040
movl %eax, %r13d
movq %r14, %rdi
callq 0x41b0
incq %r15
addq $0x28, %r12
testl %r13d, %r13d
jne 0x6cb9
leaq -0x40(%rbp), %rdi
addq (%rdi), %r12
movq %r12, %rsi
callq 0x8914
leaq 0x8bbc(%rip), %rsi      # 0xf947
movq %rbx, %rdi
callq 0x4370
movq %rax, %rdi
callq 0x41d0
movl -0x44(%rbp), %eax
testl %eax, %eax
pushq $0x4
popq %r13
cmovnel %eax, %r13d
pushq $0x14
popq %r14
leaq -0x40(%rbp), %r15
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
je 0x6c81
testl %r13d, %r13d
jle 0x6c81
callq 0x4100
movslq %eax, %rcx
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rax
subq %rsi, %rax
cqto
pushq $0x28
popq %rdi
idivq %rdi
movq %rax, %rdi
movq %rcx, %rax
xorl %edx, %edx
divq %rdi
movl 0x298(%rbx), %eax
movl 0x29c(%rbx), %edi
movslq %edx, %rcx
imulq $0x28, %rcx, %r12
addq %r12, %rsi
movl %eax, %edx
leaq 0x10(%rbp), %rcx
movl %r14d, %r8d
callq 0xdc23
addq -0x40(%rbp), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x8914
decl %r13d
jmp 0x6db0
jmp 0x6e43
jmp 0x6e43
jmp 0x6e43
jmp 0x6e43
jmp 0x6e43
jmp 0x6e35
jmp 0x6e43
jmp 0x6e43
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0x41b0
jmp 0x6e46
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
callq 0x86dc
movq %rbx, %rdi
callq 0x45d0
nop