// File: /workspace/github_cpp_makefile_star2_O3/luisremis[P]SDFS/Membership.cpp
// Function: Membership::newLeaderMsg(Message, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void Membership::newLeaderMsg( Message msg, std::string sender )
{
	logFile << "New leader recieved... lets check that..." << std::endl;
	bool flag = false;
	if ( isBiggerThanMine(sender, my_ip_str) )
	{
		membersLock.lock();

		for (int i = 0; i < members.size(); ++i)
		{
			if ( 0 == sender.compare(members.at(i).ip_str) )
			{
				logFile<< "Ok, new leader acepted: " <<  sender << std::endl;
				leader = members.at(i);
				leader.active = true;
				flag = true;
			}
			// Message msg;
			// msg.type = MSG_NEWLEADER_ACK;
			// sendUDP( sockfd,  other, port, (char*)&msg, sizeof(Message) );
		}

		membersLock.unlock();

		if(!flag)
		{
			runLeaderElection();
		}
	}
	else
	{
		logFile << "I am bigger than that guy! Re runnig election" <<  sender << std::endl;
		runLeaderElection();
	}

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %r14
movq %rdi, %rbx
leaq 0xa95f(%rip), %rsi      # 0x138d9
movl $0x29, %edx
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
leaq -0x68(%rbp), %r12
movq %r12, -0x10(%r12)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq -0x78(%rbp), %rdi
callq 0x56fa
leaq -0x48(%rbp), %r13
movq %r13, -0x10(%r13)
movq 0x2d8(%rbx), %rsi
movq 0x2e0(%rbx), %rdx
addq %rsi, %rdx
leaq -0x58(%rbp), %rdi
callq 0x56fa
leaq -0x78(%rbp), %rsi
leaq -0x58(%rbp), %rdx
movq %rbx, %rdi
callq 0x96ba
movl %eax, %r15d
movq -0x58(%rbp), %rdi
cmpq %r13, %rdi
je 0x900a
callq 0x4360
movq -0x78(%rbp), %rdi
cmpq %r12, %rdi
je 0x9018
callq 0x4360
testb %r15b, %r15b
je 0x915a
leaq 0x230(%rbx), %r15
movq %r15, %rdi
callq 0x44d0
testl %eax, %eax
jne 0x91d9
movq 0x258(%rbx), %rsi
cmpq %rsi, 0x260(%rbx)
je 0x91a9
movq %r15, -0x30(%rbp)
leaq 0x270(%rbx), %rax
movq %rax, -0x38(%rbp)
xorl %r12d, %r12d
xorl %r13d, %r13d
xorl %r15d, %r15d
addq %r12, %rsi
movq %r14, %rdi
callq 0x4050
testl %eax, %eax
jne 0x9116
movl $0x18, %edx
movq %rbx, %rdi
leaq 0xa87d(%rip), %rsi      # 0x13903
callq 0x43f0
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq %rbx, %rdi
callq 0x43f0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x4380
movsbl %al, %esi
movq %r15, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x4260
movq 0x258(%rbx), %r15
movq 0x260(%rbx), %rdx
subq %r15, %rdx
sarq $0x3, %rdx
movabsq $-0x3333333333333333, %rax # imm = 0xCCCCCCCCCCCCCCCD
imulq %rax, %rdx
cmpq %r13, %rdx
jbe 0x91c8
leaq (%r15,%r12), %rsi
movq -0x38(%rbp), %rdi
callq 0x4210
movq 0x20(%r15,%r12), %rax
movq %rax, 0x290(%rbx)
movl $0x1, 0x294(%rbx)
movb $0x1, %r15b
incq %r13
movq 0x258(%rbx), %rsi
movq 0x260(%rbx), %rax
subq %rsi, %rax
sarq $0x3, %rax
movabsq $-0x3333333333333333, %rcx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rcx, %rax
addq $0x28, %r12
cmpq %r13, %rax
ja 0x9064
movq -0x30(%rbp), %rdi
callq 0x42a0
testb $0x1, %r15b
je 0x91b1
jmp 0x91b9
leaq 0xa7bb(%rip), %rsi      # 0x1391c
movl $0x2d, %edx
movq %rbx, %rdi
callq 0x43f0
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq %rbx, %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
jmp 0x91b1
movq %r15, %rdi
callq 0x42a0
movq %rbx, %rdi
callq 0x9932
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xa7a6(%rip), %rdi      # 0x13975
movq %r13, %rsi
xorl %eax, %eax
callq 0x44e0
movl %eax, %edi
callq 0x4240
movq %rax, %rbx
movq -0x58(%rbp), %rdi
cmpq %r13, %rdi
je 0x91f6
callq 0x4360
jmp 0x91f6
movq %rax, %rbx
movq -0x78(%rbp), %rdi
cmpq %r12, %rdi
je 0x9204
callq 0x4360
movq %rbx, %rdi
callq 0x4630