// File: /workspace/github_cpp_makefile_star2_O1/luisremis[P]SDFS/Membership.cpp
// Function: Membership::Membership(bool, int)
Membership::Membership(bool introducer, int port)
{
	logFile.open("logMembership.log");

	isIntroducer = introducer;
	this->port = port;
	leader.active = false;

	sockfd = bindSocket(port);

    if(isIntroducer){
        logFile << "I am the introducer! " << std::endl;
        getAdress("Address.add");
    }
    else{
        getAdress("AddrIntro.add");
    }

    roundLock.lock();
    roundId = 0;
    roundLock.unlock();

    join();

    std::thread th3(&Membership::forJoinThread, this);
    std::thread th1(&Membership::listeningThread, this);
    std::thread th2(&Membership::detectThread, this);

    listening.swap(th1);
    detecting.swap(th2);
    joinThread.swap(th3);

    killListeningThread = false;
	killDetectingThread = false;

	//runLeaderElection();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl %edx, %r15d
movl %esi, %r12d
movq %rdi, %rbx
callq 0x45c0
leaq 0x280(%rbx), %rax
xorps %xmm0, %xmm0
movups %xmm0, 0x260(%rbx)
movups %xmm0, 0x250(%rbx)
movups %xmm0, 0x240(%rbx)
movups %xmm0, 0x230(%rbx)
movups %xmm0, 0x220(%rbx)
movups %xmm0, 0x210(%rbx)
movups %xmm0, 0x200(%rbx)
movq %rax, -0x48(%rbp)
movq %rax, 0x270(%rbx)
xorl %eax, %eax
movq %rax, 0x278(%rbx)
movb %al, 0x280(%rbx)
movups %xmm0, 0x2a0(%rbx)
movups %xmm0, 0x2b0(%rbx)
movq %rax, 0x2c0(%rbx)
leaq 0x2e8(%rbx), %r13
movq %r13, 0x2d8(%rbx)
movq %rax, 0x2e0(%rbx)
movb %al, 0x2e8(%rbx)
leaq 0x398(%rbx), %r14
movups %xmm0, 0x2f8(%rbx)
movups %xmm0, 0x308(%rbx)
movups %xmm0, 0x318(%rbx)
movups %xmm0, 0x328(%rbx)
movups %xmm0, 0x338(%rbx)
movq %rax, 0x348(%rbx)
movups %xmm0, 0x388(%rbx)
movups %xmm0, 0x378(%rbx)
movups %xmm0, 0x368(%rbx)
movups %xmm0, 0x358(%rbx)
movq %r14, %rdi
callq 0x4480
leaq 0xdb04(%rip), %rsi      # 0x133d8
movq %rbx, %rdi
movl $0x10, %edx
callq 0x4060
movb %r12b, 0x2cc(%rbx)
movl %r15d, 0x298(%rbx)
movl $0x0, 0x294(%rbx)
movl %r15d, %edi
callq 0x11498
movl %eax, 0x29c(%rbx)
cmpb $0x1, 0x2cc(%rbx)
jne 0x5989
leaq 0xdad3(%rip), %rsi      # 0x133ea
movl $0x15, %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
leaq -0x88(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0xdaa2(%rip), %rsi      # 0x13400
leaq 0xdaa6(%rip), %rdx      # 0x1340b
leaq -0x98(%rbp), %rdi
callq 0xa686
leaq -0x98(%rbp), %rsi
movq %rbx, %rdi
callq 0x5bd8
movq -0x98(%rbp), %rdi
jmp 0x59b9
leaq -0x68(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0xda73(%rip), %rsi      # 0x1340c
leaq 0xda79(%rip), %rdx      # 0x13419
leaq -0x78(%rbp), %rdi
callq 0xa686
leaq -0x78(%rbp), %rsi
movq %rbx, %rdi
callq 0x5bd8
movq -0x78(%rbp), %rdi
cmpq %r12, %rdi
je 0x59c3
callq 0x4360
leaq 0x2a0(%rbx), %r15
movq %r15, %rdi
callq 0x44d0
testl %eax, %eax
jne 0x5ade
movl $0x0, 0x2c8(%rbx)
movq %r15, %rdi
callq 0x42a0
movq %rbx, %rdi
callq 0x5ebc
leaq 0x5d7(%rip), %rax       # 0x5fd2
leaq -0x58(%rbp), %rsi
movq %rax, (%rsi)
movq $0x0, 0x8(%rsi)
leaq -0x30(%rbp), %rdx
movq %rbx, (%rdx)
leaq -0x40(%rbp), %rdi
callq 0xa21c
leaq 0x8a3(%rip), %rax       # 0x62c4
leaq -0x58(%rbp), %rsi
movq %rax, (%rsi)
movq $0x0, 0x8(%rsi)
leaq -0x38(%rbp), %rdx
movq %rbx, (%rdx)
leaq -0x30(%rbp), %rdi
callq 0xa21c
leaq 0x104f(%rip), %rax      # 0x6a96
leaq -0x58(%rbp), %rsi
movq %rax, (%rsi)
movq $0x0, 0x8(%rsi)
leaq -0xa0(%rbp), %rdx
movq %rbx, (%rdx)
leaq -0x38(%rbp), %rdi
callq 0xa21c
movq 0x338(%rbx), %rax
movq -0x30(%rbp), %rcx
movq %rcx, 0x338(%rbx)
movq %rax, -0x30(%rbp)
movq 0x340(%rbx), %rdx
movq -0x38(%rbp), %rcx
movq %rcx, 0x340(%rbx)
movq %rdx, -0x38(%rbp)
movq 0x348(%rbx), %rcx
movq -0x40(%rbp), %rsi
movq %rsi, 0x348(%rbx)
movq %rcx, -0x40(%rbp)
movw $0x0, 0x350(%rbx)
testq %rdx, %rdx
jne 0x5bd2
testq %rax, %rax
jne 0x5bd2
testq %rcx, %rcx
jne 0x5bd2
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %edi
callq 0x4240
movq %rax, %r15
movq -0x98(%rbp), %rdi
jmp 0x5afa
jmp 0x5b25
movq %rax, %r15
movq -0x78(%rbp), %rdi
cmpq %r12, %rdi
je 0x5b28
callq 0x4360
jmp 0x5b28
jmp 0x5b25
cmpq $0x0, -0x30(%rbp)
je 0x5b14
jmp 0x5bd2
movq %rax, %r15
cmpq $0x0, -0x40(%rbp)
je 0x5b28
jmp 0x5bd2
jmp 0x5b25
movq %rax, %r15
leaq 0x358(%rbx), %r12
movq %r14, %rdi
callq 0x4660
movq %r12, %rdi
callq 0xa2be
cmpq $0x0, 0x348(%rbx)
jne 0x5bd2
cmpq $0x0, 0x340(%rbx)
jne 0x5bd2
cmpq $0x0, 0x338(%rbx)
jne 0x5bd2
leaq 0x2f8(%rbx), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x5b75
callq 0x4360
movq 0x2d8(%rbx), %rdi
cmpq %r13, %rdi
je 0x5b86
callq 0x4360
leaq 0x200(%rbx), %r14
movq 0x270(%rbx), %rdi
cmpq -0x48(%rbp), %rdi
je 0x5b9f
callq 0x4360
leaq 0x258(%rbx), %rdi
leaq 0x218(%rbx), %r12
callq 0xa33e
movq %r12, %rdi
callq 0xa33e
movq %r14, %rdi
callq 0xa38c
movq %rbx, %rdi
callq 0x46c8
movq %r15, %rdi
callq 0x4630
callq 0x4110
nop