// File: /workspace/github_cpp_makefile_star2_O1/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       # 0x8d28
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 0xd14a
movq %r14, %rdi
callq 0x3570
cmpb $0x0, 0x9f8(%rbx)
jne 0x8b13
movq %rbx, %rdi
callq 0x99e0
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 0x8b53
movq %rbx, %rdi
callq 0x9a5a
jmp 0x8b40
movq %r14, %rdi
callq 0x3470
testl %eax, %eax
jne 0x8cc7
movq %r13, %r15
movl 0x180(%rbx), %r13d
movq %r14, %rdi
callq 0x3280
cmpl $0x18, %r13d
movq %r15, %r13
jne 0x8b40
leaq -0x1070(%rbp), %rdi
movl $0x11, %esi
movl $0x1, %edx
movl $0x1, %ecx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
leaq 0x7a94(%rip), %r9       # 0x10635
callq 0x657c
movq -0x38(%rbp), %rdi
callq 0x3470
testl %eax, %eax
jne 0x8cd5
movq 0x178(%rbx), %rdi
leaq -0x1070(%rbp), %rsi
movl $0x64, %edx
callq 0xe796
movl %eax, %r13d
movq -0x38(%rbp), %rdi
callq 0x3280
movq %r14, %rdi
callq 0x3470
testl %eax, %eax
jne 0x8cce
cmpl $0x18, 0x180(%rbx)
setne %al
orb %al, %r13b
movq %r14, %rdi
movq %r15, %r13
jne 0x8c8f
movl $0x1c, 0x180(%rbx)
movq %r14, %rdi
callq 0x3280
movq -0x30(%rbp), %rdi
callq 0x3470
testl %eax, %eax
jne 0x8cce
leaq -0x90(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0xd1ee
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 0x6244
movq %rbx, %rdi
leaq -0x90(%rbp), %rsi
movq %r13, %rdx
callq 0x9fec
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
je 0x8c7f
callq 0x3320
leaq -0x90(%rbp), %rdi
callq 0xcf94
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 0x8b40
callq 0x3060
cmpl $0x4, (%rax)
je 0x8ca4
jmp 0x8b40
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 0x8cf6
callq 0x3320
jmp 0x8cf6
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
callq 0xcf94
jmp 0x8d13
jmp 0x8d10
jmp 0x8d10
jmp 0x8d10
jmp 0x8d10
jmp 0x8d10
jmp 0x8d10
movq %rax, %rbx
cmpq $0x0, -0x48(%rbp)
jne 0x8d22
movq %rbx, %rdi
callq 0x3580
callq 0x30e0
nop