// File: luisremis[P]SDFS/Membership.cpp
// Function: Membership::sendBackLocalList(int)
int Membership::sendBackLocalList(int connFd){
	membersLock.lock();

    int size = members.size();
    
    //prepare all the members
    Message * buffer = new Message[size];
    char addr[4];

    for(int i=0; i < size; i++){
    	buffer[i].type = MSG_JOIN;
		buffer[i].roundId = -1;
		ipString2Char4(members[i].ip_str, addr);
		for(int j=0; j < 4; j++)
			buffer[i].carrierAdd[j] = addr[j];
		buffer[i].timeStamp = members[i].timeStamp;
		buffer[i].TTL = 0;
    }
    
    membersLock.unlock();

    Message sizeMsg;
    sizeMsg.timeStamp = size;
    int ret = write(connFd, &sizeMsg, sizeof(Message) );

    for(int i=0; i < size; i++){
    	ret = write(connFd, buffer+i, sizeof(Message) );
    	logFile<<"sendBackLocalList: sending "<<char42String(buffer[i].carrierAdd)<<" "<<buffer[i].timeStamp<< std::endl;
    }
    delete [] buffer;
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x98(%rbp)
addq $0x230, %rdi            # imm = 0x230
callq 0xb5f0
movq -0x98(%rbp), %rdi
addq $0x258, %rdi            # imm = 0x258
callq 0xb990
movl %eax, -0x10(%rbp)
movslq -0x10(%rbp), %rax
movl $0x14, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x4030
movq %rax, -0x18(%rbp)
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x9612
movq -0x98(%rbp), %rdi
movq -0x18(%rbp), %rax
movslq -0x20(%rbp), %rcx
leaq (%rcx,%rcx,4), %rcx
movl $0x6, (%rax,%rcx,4)
movq -0x18(%rbp), %rax
movslq -0x20(%rbp), %rcx
leaq (%rcx,%rcx,4), %rcx
movb $-0x1, 0x4(%rax,%rcx,4)
addq $0x258, %rdi            # imm = 0x258
movslq -0x20(%rbp), %rsi
callq 0xb8d0
movq %rax, %rsi
leaq -0x40(%rbp), %rdi
movq %rdi, -0xa0(%rbp)
callq 0x41e0
movq -0xa0(%rbp), %rdi
leaq -0x1c(%rbp), %rsi
callq 0x1a2b0
jmp 0x956b
leaq -0x40(%rbp), %rdi
callq 0x42a0
movl $0x0, -0x50(%rbp)
cmpl $0x4, -0x50(%rbp)
jge 0x95c5
movslq -0x50(%rbp), %rax
movb -0x1c(%rbp,%rax), %dl
movq -0x18(%rbp), %rax
movslq -0x20(%rbp), %rcx
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movslq -0x50(%rbp), %rcx
movb %dl, 0x5(%rax,%rcx)
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x957b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x42a0
jmp 0x977e
movq -0x98(%rbp), %rdi
addq $0x258, %rdi            # imm = 0x258
movslq -0x20(%rbp), %rsi
callq 0xb8d0
movl 0x20(%rax), %ecx
movq -0x18(%rbp), %rax
movslq -0x20(%rbp), %rdx
imulq $0x14, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0xc(%rax)
movq -0x18(%rbp), %rax
movslq -0x20(%rbp), %rcx
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x10(%rax)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x94ff
movq -0x98(%rbp), %rdi
addq $0x230, %rdi            # imm = 0x230
callq 0xb620
movl -0x10(%rbp), %eax
movl %eax, -0x58(%rbp)
movl -0xc(%rbp), %edi
leaq -0x64(%rbp), %rsi
movl $0x14, %edx
callq 0x4190
movl %eax, -0x68(%rbp)
movl $0x0, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x9756
movl -0xc(%rbp), %edi
movq -0x18(%rbp), %rax
movslq -0x6c(%rbp), %rcx
leaq (%rcx,%rcx,4), %rcx
leaq (%rax,%rcx,4), %rsi
movl $0x14, %edx
callq 0x4190
movq -0x98(%rbp), %rdi
movl %eax, -0x68(%rbp)
leaq 0x12eaf(%rip), %rsi     # 0x1c52f
callq 0x43f0
movq %rax, -0xb8(%rbp)
movq -0x18(%rbp), %rax
movslq -0x6c(%rbp), %rcx
leaq (%rcx,%rcx,4), %rcx
leaq 0x5(%rax,%rcx,4), %rsi
leaq -0x90(%rbp), %rdi
movq %rdi, -0xb0(%rbp)
callq 0x1a480
movq -0xb8(%rbp), %rdi
movq -0xb0(%rbp), %rsi
callq 0x4370
movq %rax, -0xa8(%rbp)
jmp 0x96cc
movq -0xa8(%rbp), %rdi
leaq 0x12c48(%rip), %rsi     # 0x1c322
callq 0x43f0
movq %rax, -0xc0(%rbp)
jmp 0x96e8
movq -0xc0(%rbp), %rdi
movq -0x18(%rbp), %rax
movslq -0x6c(%rbp), %rcx
leaq (%rcx,%rcx,4), %rcx
movl 0xc(%rax,%rcx,4), %esi
callq 0x4670
movq %rax, -0xc8(%rbp)
jmp 0x970d
movq -0xc8(%rbp), %rdi
movq 0x1d88d(%rip), %rsi     # 0x26fa8
callq 0x4410
jmp 0x9722
leaq -0x90(%rbp), %rdi
callq 0x42a0
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x9646
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x42a0
jmp 0x977e
movq -0x18(%rbp), %rax
movq %rax, -0xd0(%rbp)
cmpq $0x0, %rax
je 0x9773
movq -0xd0(%rbp), %rdi
callq 0x44b0
xorl %eax, %eax
addq $0xd0, %rsp
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x46a0
nopw (%rax,%rax)