// File: /workspace/github_cpp_makefile_star2_O2/vianna274[P]dropbox/src/Server.cpp
// Function: Dropbox::Server::run()
void Server::run(){

    thread listenToServersThread(&Server::listenToServers, this, &(this->listenToServersSocket));
    listenToServersThread.detach();

    if(!this->isMain) {
        this->makeConnection();
    }
    while(true){
        if(this->isMain){
            connectNewClient();
        }
        else {
            this->electionMutex.lock();
            if (this->status == STATUS_NORMAL) {
                this->electionMutex.unlock();
                MessageData packet = make_packet(TYPE_PING, 1, 1, -1, "");
                talkToPrimaryMtx.lock();
                bool isPrimaryAlive = this->talkToPrimary->send(&packet, 100);
                talkToPrimaryMtx.unlock();
                this->electionMutex.lock();
                if(!isPrimaryAlive && this->status == STATUS_NORMAL){
                    this->status = BEGIN_ELECTION;
                    this->electionMutex.unlock();
                    backupList.lock();
                    this->removeFromBackup(this->backups, this->ipMain);
                    backupList.unlock();
                } else {
                    this->electionMutex.unlock();
                }
                this_thread::sleep_for(chrono::milliseconds(3000));
            } else {
                this->electionMutex.unlock();
            }
        }
        
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1048, %rsp           # imm = 0x1048
movq %rdi, %rbx
leaq 0x1d2(%rip), %rax       # 0x75a0
leaq -0x1070(%rbp), %rsi
movq %rax, (%rsi)
andq $0x0, 0x8(%rsi)
leaq -0x40(%rbp), %rdx
movq %rdi, (%rdx)
leaq 0x130(%rdi), %rax
leaq -0x60(%rbp), %rcx
movq %rax, (%rcx)
leaq -0x58(%rbp), %r14
movq %r14, %rdi
callq 0xa14c
movq %r14, %rdi
callq 0x3530
cmpb $0x0, 0x9f8(%rbx)
jne 0x7417
movq %rbx, %rdi
callq 0x7d66
leaq 0x20(%rbx), %r14
leaq 0xc0(%rbx), %rax
movq %rax, -0x38(%rbp)
leaq 0x98(%rbx), %rax
movq %rax, -0x30(%rbp)
leaq 0x970(%rbx), %rax
movq %rax, -0x50(%rbp)
leaq 0x9d8(%rbx), %rax
movq %rax, -0x48(%rbp)
leaq -0x78(%rbp), %r13
cmpb $0x1, 0x9f8(%rbx)
jne 0x745e
movq %rbx, %rdi
callq 0x7dd0
jmp 0x744b
movq %r14, %rdi
callq 0x50d8
movq %r13, %r12
movl 0x180(%rbx), %r13d
movq %r14, %rdi
callq 0x3250
cmpl $0x18, %r13d
movq %r12, %r13
jne 0x744b
leaq -0x1070(%rbp), %rdi
pushq $0x11
popq %rsi
pushq $0x1
popq %rcx
movl %ecx, %edx
pushq $-0x1
popq %r8
leaq 0x5162(%rip), %r9       # 0xc5fd
callq 0x57f0
movq -0x38(%rbp), %rdi
callq 0x50d8
movq 0x178(%rbx), %rdi
leaq -0x1070(%rbp), %rsi
pushq $0x64
popq %rdx
callq 0xb5a8
movl %eax, %r13d
movq -0x38(%rbp), %rdi
callq 0x3250
movq %r14, %rdi
callq 0x50d8
cmpl $0x18, 0x180(%rbx)
setne %al
orb %al, %r13b
movq %r14, %rdi
jne 0x7547
movl $0x1c, 0x180(%rbx)
movq %r14, %rdi
callq 0x3250
movq -0x30(%rbp), %rdi
callq 0x50d8
movq %r12, %rdi
movq -0x50(%rbp), %rsi
callq 0xa1da
leaq -0x98(%rbp), %r13
movq %r13, %rdi
movq -0x48(%rbp), %rsi
callq 0x33d0
movq %rbx, %rdi
movq %r13, %r15
movq %r12, %r13
movq %r12, %rsi
movq %r15, %rdx
callq 0x814a
movq %r15, %rdi
callq 0x3170
movq %r13, %rdi
callq 0xa056
movq -0x30(%rbp), %rdi
callq 0x3250
movq $0xbb8, -0x40(%rbp)     # imm = 0xBB8
leaq -0x40(%rbp), %rdi
callq 0x50ee
movq %r12, %r13
jmp 0x744b
movq %rax, %rbx
leaq -0x98(%rbp), %rdi
callq 0x3170
jmp 0x7579
movq %rax, %rbx
leaq -0x78(%rbp), %rdi
callq 0xa056
jmp 0x758f
jmp 0x758c
jmp 0x758c
jmp 0x758c
jmp 0x758c
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x50c8
movq %rbx, %rdi
callq 0x3540