// File: /workspace/github_cpp_makefile_star2_O1/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 0x7ffd
leaq 0x258(%rbx), %rsi
leaq -0x40(%rbp), %r15
movq %r15, %rdi
callq 0xa586
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 0x7fd4
leaq -0x40(%rbp), %rdi
callq 0xad4c
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
je 0x7f2d
leaq 0x10(%rbp), %rax
addq $0x5, %rax
movq %rax, -0x50(%rbp)
xorl %r12d, %r12d
xorl %r15d, %r15d
movl $0xb, %edx
movq %rbx, %rdi
leaq 0xbbb6(%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 0x7fec
movq (%rax,%r12), %rsi
movq 0x8(%rax,%r12), %rdx
movq %rbx, %rdi
callq 0x43f0
movq %rax, %r14
movl $0x1, %edx
movq %rax, %rdi
leaq 0xb527(%rip), %rsi      # 0x13322
callq 0x43f0
leaq -0x70(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x112b0
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 0x7e59
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 0x7fec
leaq -0x70(%rbp), %r13
movq %r13, %rdi
movq -0x50(%rbp), %rsi
callq 0x112b0
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 0x7eb2
callq 0x4360
testl %r14d, %r14d
je 0x7ee3
incq %r15
movq -0x38(%rbp), %rax
subq -0x40(%rbp), %rax
sarq $0x3, %rax
movabsq $-0x3333333333333333, %rcx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rcx, %rax
addq $0x28, %r12
cmpq %r15, %rax
ja 0x7d9e
jmp 0x7f2d
leaq -0x40(%rbp), %rdi
addq (%rdi), %r12
movq %r12, %rsi
callq 0xad4c
leaq 0xba76(%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
movl -0x44(%rbp), %eax
testl %eax, %eax
movl $0x4, %r12d
cmovnel %eax, %r12d
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
sete %al
testl %r12d, %r12d
setle %cl
orb %al, %cl
leaq 0x10(%rbp), %r13
jne 0x7fd4
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 0x115b6
shlq $0x3, %r15
addq -0x40(%rbp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0xad4c
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
je 0x7fd4
leal -0x1(%r12), %eax
cmpl $0x1, %r12d
movl %eax, %r12d
jg 0x7f59
leaq -0x40(%rbp), %rdi
callq 0xa33e
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xb982(%rip), %rdi      # 0x13975
movq %r15, %rsi
xorl %eax, %eax
callq 0x44e0
movl %eax, %edi
callq 0x4240
jmp 0x8014
jmp 0x8014
jmp 0x8014
jmp 0x8028
jmp 0x8014
jmp 0x8014
jmp 0x8014
jmp 0x8014
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
callq 0xa33e
movq %rbx, %rdi
callq 0x4630
movq %rax, %rbx
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x8017
callq 0x4360
jmp 0x8017
nop