// File: 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
subq $0x130, %rsp            # imm = 0x130
movq %rsi, -0xf8(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x108(%rbp)
leaq -0x40(%rbp), %rdi
movq %rdi, -0x100(%rbp)
callq 0xb570
movq -0x100(%rbp), %rdi
movq -0xf8(%rbp), %rsi
callq 0x4050
jmp 0x920d
movq -0x108(%rbp), %rdi
movl -0x14(%rbp), %eax
movl %eax, -0x20(%rbp)
movl $0x1, -0x1c(%rbp)
addq $0x230, %rdi            # imm = 0x230
callq 0xb5f0
jmp 0x922f
movb $0x0, -0x4d(%rbp)
movl $0x0, -0x54(%rbp)
movl $0x0, -0x58(%rbp)
movq -0x108(%rbp), %rdi
movslq -0x58(%rbp), %rax
movq %rax, -0x110(%rbp)
addq $0x258, %rdi            # imm = 0x258
callq 0xb990
movq %rax, %rcx
movq -0x110(%rbp), %rax
cmpq %rcx, %rax
jae 0x92d1
movq -0x108(%rbp), %rdi
addq $0x258, %rdi            # imm = 0x258
movslq -0x58(%rbp), %rsi
callq 0xb8d0
movq %rax, %rdi
leaq -0x40(%rbp), %rsi
callq 0x4040
movl %eax, -0x114(%rbp)
jmp 0x9299
movl -0x114(%rbp), %eax
cmpl $0x0, %eax
jne 0x92c1
movb $0x1, -0x4d(%rbp)
movl -0x58(%rbp), %eax
movl %eax, -0x54(%rbp)
jmp 0x92c1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x9473
jmp 0x92c3
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x9241
testb $0x1, -0x4d(%rbp)
je 0x9305
movq -0x108(%rbp), %rdi
movl -0x20(%rbp), %eax
movl %eax, -0x118(%rbp)
addq $0x258, %rdi            # imm = 0x258
movslq -0x54(%rbp), %rsi
callq 0xb8d0
movl -0x118(%rbp), %ecx
movl %ecx, 0x20(%rax)
jmp 0x93ee
leaq -0xb8(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0xb8f0
jmp 0x9317
leaq -0x90(%rbp), %rdi
movl $0x6, %esi
leaq -0xb8(%rbp), %rdx
callq 0xb160
jmp 0x9331
leaq -0xb8(%rbp), %rdi
callq 0xb7f0
leaq -0xf0(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0xb1d0
jmp 0x9352
movq -0x108(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x8840
jmp 0x9367
leaq -0xf0(%rbp), %rdi
callq 0xb930
movq -0x108(%rbp), %rdi
addq $0x258, %rdi            # imm = 0x258
leaq -0x40(%rbp), %rsi
callq 0xba50
jmp 0x938c
leaq -0x90(%rbp), %rdi
callq 0xb930
jmp 0x93ee
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0xb7f0
jmp 0x9473
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x93dd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0xb930
leaq -0x90(%rbp), %rdi
callq 0xb930
jmp 0x9473
movq -0x108(%rbp), %rdi
addq $0x230, %rdi            # imm = 0x230
callq 0xb620
jmp 0x9403
movq -0x108(%rbp), %rdi
leaq 0x1351d(%rip), %rsi     # 0x1c92e
callq 0x43f0
movq %rax, -0x120(%rbp)
jmp 0x941f
movq -0x120(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x4370
movq %rax, -0x128(%rbp)
jmp 0x9438
movq -0x128(%rbp), %rdi
movq 0x1db62(%rip), %rsi     # 0x26fa8
callq 0x4410
jmp 0x944d
movb -0x4d(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x12c(%rbp)
leaq -0x40(%rbp), %rdi
callq 0xb7f0
movl -0x12c(%rbp), %eax
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
leaq -0x40(%rbp), %rdi
callq 0xb7f0
movq -0x48(%rbp), %rdi
callq 0x46a0
nopw %cs:(%rax,%rax)