// File: /workspace/github_cpp_makefile_star2_O3/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 0xdb10(%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 0x1130c
movl %eax, 0x29c(%rbx)
cmpb $0x1, 0x2cc(%rbx)
jne 0x597d
leaq 0xdadf(%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 0xdaae(%rip), %rsi      # 0x13400
leaq 0xdab2(%rip), %rdx      # 0x1340b
leaq -0x98(%rbp), %rdi
callq 0xa592
leaq -0x98(%rbp), %rsi
movq %rbx, %rdi
callq 0x5bcc
movq -0x98(%rbp), %rdi
jmp 0x59ad
leaq -0x68(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0xda7f(%rip), %rsi      # 0x1340c
leaq 0xda85(%rip), %rdx      # 0x13419
leaq -0x78(%rbp), %rdi
callq 0xa592
leaq -0x78(%rbp), %rsi
movq %rbx, %rdi
callq 0x5bcc
movq -0x78(%rbp), %rdi
cmpq %r12, %rdi
je 0x59b7
callq 0x4360
leaq 0x2a0(%rbx), %r15
movq %r15, %rdi
callq 0x44d0
testl %eax, %eax
jne 0x5ad2
movl $0x0, 0x2c8(%rbx)
movq %r15, %rdi
callq 0x42a0
movq %rbx, %rdi
callq 0x5eb0
leaq 0x5d7(%rip), %rax       # 0x5fc6
leaq -0x58(%rbp), %rsi
movq %rax, (%rsi)
movq $0x0, 0x8(%rsi)
leaq -0x30(%rbp), %rdx
movq %rbx, (%rdx)
leaq -0x40(%rbp), %rdi
callq 0xa12a
leaq 0x881(%rip), %rax       # 0x6296
leaq -0x58(%rbp), %rsi
movq %rax, (%rsi)
movq $0x0, 0x8(%rsi)
leaq -0x38(%rbp), %rdx
movq %rbx, (%rdx)
leaq -0x30(%rbp), %rdi
callq 0xa12a
leaq 0x102d(%rip), %rax      # 0x6a68
leaq -0x58(%rbp), %rsi
movq %rax, (%rsi)
movq $0x0, 0x8(%rsi)
leaq -0xa0(%rbp), %rdx
movq %rbx, (%rdx)
leaq -0x38(%rbp), %rdi
callq 0xa12a
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 0x5bc6
testq %rax, %rax
jne 0x5bc6
testq %rcx, %rcx
jne 0x5bc6
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 0x5aee
jmp 0x5b19
movq %rax, %r15
movq -0x78(%rbp), %rdi
cmpq %r12, %rdi
je 0x5b1c
callq 0x4360
jmp 0x5b1c
jmp 0x5b19
cmpq $0x0, -0x30(%rbp)
je 0x5b08
jmp 0x5bc6
movq %rax, %r15
cmpq $0x0, -0x40(%rbp)
je 0x5b1c
jmp 0x5bc6
jmp 0x5b19
movq %rax, %r15
leaq 0x358(%rbx), %r12
movq %r14, %rdi
callq 0x4660
movq %r12, %rdi
callq 0xa1bc
cmpq $0x0, 0x348(%rbx)
jne 0x5bc6
cmpq $0x0, 0x340(%rbx)
jne 0x5bc6
cmpq $0x0, 0x338(%rbx)
jne 0x5bc6
leaq 0x2f8(%rbx), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x5b69
callq 0x4360
movq 0x2d8(%rbx), %rdi
cmpq %r13, %rdi
je 0x5b7a
callq 0x4360
leaq 0x200(%rbx), %r14
movq 0x270(%rbx), %rdi
cmpq -0x48(%rbp), %rdi
je 0x5b93
callq 0x4360
leaq 0x258(%rbx), %rdi
leaq 0x218(%rbx), %r12
callq 0xa246
movq %r12, %rdi
callq 0xa246
movq %r14, %rdi
callq 0xa29e
movq %rbx, %rdi
callq 0x46c8
movq %r15, %rdi
callq 0x4630
callq 0x4110
nop