// File: /workspace/github_cpp_makefile_star2_O3/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 0x264(%rip), %rax       # 0x8cf8
leaq -0x1070(%rbp), %rsi
movq %rax, (%rsi)
movq $0x0, 0x8(%rsi)
leaq -0x58(%rbp), %rdx
movq %rdi, (%rdx)
leaq 0x130(%rdi), %rax
leaq -0x98(%rbp), %rcx
movq %rax, (%rcx)
leaq -0x48(%rbp), %r14
movq %r14, %rdi
callq 0xd11c
movq %r14, %rdi
callq 0x3570
cmpb $0x0, 0x9f8(%rbx)
jne 0x8ae3
movq %rbx, %rdi
callq 0x99aa
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, -0x40(%rbp)
leaq -0x58(%rbp), %r12
leaq -0x78(%rbp), %r13
cmpb $0x1, 0x9f8(%rbx)
jne 0x8b23
movq %rbx, %rdi
callq 0x9a24
jmp 0x8b10
movq %r14, %rdi
callq 0x3470
testl %eax, %eax
jne 0x8c97
movq %r13, %r15
movl 0x180(%rbx), %r13d
movq %r14, %rdi
callq 0x3280
cmpl $0x18, %r13d
movq %r15, %r13
jne 0x8b10
leaq -0x1070(%rbp), %rdi
movl $0x11, %esi
movl $0x1, %edx
movl $0x1, %ecx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
leaq 0x7ac4(%rip), %r9       # 0x10635
callq 0x65b0
movq -0x38(%rbp), %rdi
callq 0x3470
testl %eax, %eax
jne 0x8ca5
movq 0x178(%rbx), %rdi
leaq -0x1070(%rbp), %rsi
movl $0x64, %edx
callq 0xe752
movl %eax, %r13d
movq -0x38(%rbp), %rdi
callq 0x3280
movq %r14, %rdi
callq 0x3470
testl %eax, %eax
jne 0x8c9e
cmpl $0x18, 0x180(%rbx)
setne %al
orb %al, %r13b
movq %r14, %rdi
movq %r15, %r13
jne 0x8c5f
movl $0x1c, 0x180(%rbx)
movq %r14, %rdi
callq 0x3280
movq -0x30(%rbp), %rdi
callq 0x3470
testl %eax, %eax
jne 0x8c9e
leaq -0x90(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0xd1b0
leaq -0x68(%rbp), %rax
movq %rax, -0x78(%rbp)
movq 0x9d8(%rbx), %rsi
movq 0x9e0(%rbx), %rdx
addq %rsi, %rdx
movq %r15, %r13
movq %r15, %rdi
callq 0x6270
movq %rbx, %rdi
leaq -0x90(%rbp), %rsi
movq %r13, %rdx
callq 0x9fbc
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
je 0x8c4f
callq 0x3320
leaq -0x90(%rbp), %rdi
callq 0xcf3c
movq -0x30(%rbp), %rdi
callq 0x3280
movq $0x3, -0x58(%rbp)
movq $0x0, -0x50(%rbp)
movq %r12, %rdi
movq %r12, %rsi
callq 0x30f0
cmpl $-0x1, %eax
jne 0x8b10
callq 0x3060
cmpl $0x4, (%rax)
je 0x8c74
jmp 0x8b10
movl %eax, %edi
callq 0x3250
movl %eax, %edi
callq 0x3250
movl %eax, %edi
callq 0x3250
movq %rax, %rbx
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
je 0x8cc6
callq 0x3320
jmp 0x8cc6
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
callq 0xcf3c
jmp 0x8ce3
jmp 0x8ce0
jmp 0x8ce0
jmp 0x8ce0
jmp 0x8ce0
jmp 0x8ce0
jmp 0x8ce0
movq %rax, %rbx
cmpq $0x0, -0x48(%rbp)
jne 0x8cf2
movq %rbx, %rdi
callq 0x3580
callq 0x30e0
nop