// File: /workspace/github_cpp_makefile_star2_O3/luisremis[P]SDFS/Membership.cpp
// Function: Membership::addMember(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int)
int Membership::addMember(std::string newAddress, int timeStamp){
    Node newMember;
    newMember.ip_str = newAddress;
    newMember.timeStamp = timeStamp;
    newMember.active = 1;
    
    membersLock.lock();

    bool exist = false;
    int position = 0;
    for(int i=0; i < members.size(); i++){
        if( members[i].ip_str.compare( newMember.ip_str )==0 ){
            exist = true;
            position = i;
        }
    }
    
    if(exist){
        members[position].timeStamp = newMember.timeStamp;
    }
    else{
        //if add a new member, tell the memUpMsgQueue
        MemberUpdateMsg msg(MSG_JOIN, newMember);
        pushMsgToFileSysQueue(msg);

        members.push_back(newMember);
    }

    membersLock.unlock();

    logFile << "New member: " << newMember.ip_str << std::endl;

    return exist;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movl %edx, %r14d
movq %rdi, %rbx
leaq -0x40(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq -0x50(%rbp), %rdi
callq 0x4210
movl %r14d, -0x30(%rbp)
movl $0x1, -0x2c(%rbp)
leaq 0x230(%rbx), %r14
movq %r14, %rdi
callq 0x44d0
testl %eax, %eax
jne 0x83b5
movq %r14, -0x58(%rbp)
movq 0x258(%rbx), %rdi
xorl %r12d, %r12d
cmpq %rdi, 0x260(%rbx)
je 0x8289
xorl %r14d, %r14d
xorl %r15d, %r15d
xorl %r13d, %r13d
addq %r14, %rdi
leaq -0x50(%rbp), %rsi
callq 0x4050
testl %eax, %eax
movzbl %r13b, %r13d
movl $0x1, %eax
cmovel %eax, %r13d
cmovel %r15d, %r12d
incq %r15
movq 0x258(%rbx), %rdi
movq 0x260(%rbx), %rax
subq %rdi, %rax
sarq $0x3, %rax
movabsq $-0x3333333333333333, %rcx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rcx, %rax
addq $0x28, %r14
cmpq %r15, %rax
ja 0x8222
testb $0x1, %r13b
je 0x828c
movslq %r12d, %rax
movl -0x30(%rbp), %ecx
leaq (%rax,%rax,4), %rax
movl %ecx, 0x20(%rdi,%rax,8)
jmp 0x8332
xorl %r13d, %r13d
leaq -0x70(%rbp), %r14
movq %r14, -0x10(%r14)
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
addq %rsi, %rdx
leaq -0x80(%rbp), %rdi
callq 0x56fa
movq -0x30(%rbp), %rax
leaq -0x80(%rbp), %rdx
movq %rax, 0x20(%rdx)
leaq -0xf0(%rbp), %rdi
movl $0x6, %esi
callq 0x9ede
movq -0x80(%rbp), %rdi
cmpq %r14, %rdi
je 0x82d3
callq 0x4360
leaq -0xb8(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x9f42
leaq -0xb8(%rbp), %rsi
movq %rbx, %rdi
callq 0x7a90
leaq 0x258(%rbx), %r15
leaq -0xa0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8311
callq 0x4360
leaq -0x50(%rbp), %rsi
movq %r15, %rdi
callq 0xa388
leaq -0xd8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8332
callq 0x4360
movq -0x58(%rbp), %rdi
callq 0x42a0
leaq 0xb614(%rip), %rsi      # 0x13956
movl $0xc, %edx
movq %rbx, %rdi
callq 0x43f0
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq %rbx, %rdi
callq 0x43f0
movq %rax, %rbx
movq (%rax), %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
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x839b
callq 0x4360
andb $0x1, %r13b
movzbl %r13b, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %edi
callq 0x4240
movq %rax, %rbx
leaq -0xa0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x83e9
callq 0x4360
jmp 0x83e9
movq %rax, %rbx
movq -0x80(%rbp), %rdi
cmpq %r14, %rdi
jne 0x83f9
jmp 0x8407
jmp 0x8404
movq %rax, %rbx
leaq -0xd8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8407
callq 0x4360
jmp 0x8407
jmp 0x8404
jmp 0x8404
movq %rax, %rbx
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x8419
callq 0x4360
movq %rbx, %rdi
callq 0x4630
nop