// File: /workspace/github_cpp_makefile_star2_O3/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 0x44d0
testl %eax, %eax
jne 0x7f7e
leaq 0x258(%rbx), %rsi
leaq -0x40(%rbp), %r15
movq %r15, %rdi
callq 0xa492
movq %r14, %rdi
callq 0x42a0
movq (%r15), %rsi
movq 0x8(%r15), %rax
subq %rsi, %rax
sarq $0x3, %rax
movabsq $-0x3333333333333333, %rcx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rcx, %rax
cmpq $0x3, %rax
jb 0x7f55
leaq -0x40(%rbp), %rdi
callq 0xabfc
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
je 0x7f55
leaq 0x10(%rbp), %rax
addq $0x5, %rax
movq %rax, -0x50(%rbp)
xorl %r12d, %r12d
xorl %r15d, %r15d
movl $0xb, %edx
movq %rbx, %rdi
leaq 0xbc3e(%rip), %rsi      # 0x13963
callq 0x43f0
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movabsq $-0x3333333333333333, %rcx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rcx, %rdx
cmpq %r15, %rdx
jbe 0x7f6d
movq (%rax,%r12), %rsi
movq 0x8(%rax,%r12), %rdx
movq %rbx, %rdi
callq 0x43f0
movq %rax, %r14
movl $0x1, %edx
movq %rax, %rdi
leaq 0xb5af(%rip), %rsi      # 0x13322
callq 0x43f0
leaq -0x70(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x11124
movq -0x70(%rbp), %rsi
movq -0x68(%rbp), %rdx
movq %r14, %rdi
callq 0x43f0
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
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x7dd1
callq 0x4360
movq -0x40(%rbp), %r14
movq -0x38(%rbp), %rdx
subq %r14, %rdx
sarq $0x3, %rdx
movabsq $-0x3333333333333333, %rax # imm = 0xCCCCCCCCCCCCCCCD
imulq %rax, %rdx
cmpq %r15, %rdx
jbe 0x7f6d
leaq -0x70(%rbp), %r13
movq %r13, %rdi
movq -0x50(%rbp), %rsi
callq 0x11124
addq %r12, %r14
movq %r14, %rdi
movq %r13, %rsi
callq 0x4050
movl %eax, %r14d
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x7e2a
callq 0x4360
testl %r14d, %r14d
je 0x7e61
incq %r15
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movabsq $-0x3333333333333333, %rsi # imm = 0xCCCCCCCCCCCCCCCD
imulq %rsi, %rdx
addq $0x28, %r12
cmpq %r15, %rdx
ja 0x7d16
jmp 0x7eb3
leaq -0x40(%rbp), %rdi
addq (%rdi), %r12
movq %r12, %rsi
callq 0xabfc
leaq 0xbaf8(%rip), %rsi      # 0x1396f
movl $0x5, %edx
movq %rbx, %rdi
callq 0x43f0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4380
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x4260
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
movl -0x44(%rbp), %edx
testl %edx, %edx
movl $0x4, %r12d
cmovnel %edx, %r12d
cmpq %rax, %rcx
sete %al
testl %r12d, %r12d
setle %cl
orb %al, %cl
leaq 0x10(%rbp), %r13
jne 0x7f55
leaq -0x40(%rbp), %r14
callq 0x4100
cltq
movq -0x40(%rbp), %rcx
movq -0x38(%rbp), %rsi
subq %rcx, %rsi
sarq $0x3, %rsi
movabsq $-0x3333333333333333, %rdx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rdx, %rsi
xorl %edx, %edx
divq %rsi
movl 0x298(%rbx), %eax
movl 0x29c(%rbx), %edi
movslq %edx, %rdx
leaq (%rdx,%rdx,4), %r15
leaq (%rcx,%r15,8), %rsi
movl %eax, %edx
movq %r13, %rcx
movl $0x14, %r8d
callq 0x1142c
shlq $0x3, %r15
addq -0x40(%rbp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0xabfc
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
je 0x7f55
leal -0x1(%r12), %eax
cmpl $0x1, %r12d
movl %eax, %r12d
jg 0x7eda
leaq -0x40(%rbp), %rdi
callq 0xa246
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xba01(%rip), %rdi      # 0x13975
movq %r15, %rsi
xorl %eax, %eax
callq 0x44e0
movl %eax, %edi
callq 0x4240
jmp 0x7f95
jmp 0x7f95
jmp 0x7f95
jmp 0x7f95
jmp 0x7f95
jmp 0x7f9a
jmp 0x7f95
jmp 0x7f95
movq %rax, %rbx
jmp 0x7faf
movq %rax, %rbx
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x7faf
callq 0x4360
leaq -0x40(%rbp), %rdi
callq 0xa246
movq %rbx, %rdi
callq 0x4630