// File: /workspace/github_cpp_makefile_star2_O3/davidcairuz[P]network-internet-relay-chat/server.cpp
// Function: main
int main(int argc, char* argv[]) {
    socket_server->Bind();
    socket_server->Check();

    cout << "Chat Initialized =D\n";

    socket_server->Listen();
    socket_server->Check();

    pthread_t tid;

    while (1) {
        string ip;
        int new_client;
        tie(new_client, ip) = socket_server->Accept();
        socket_server->Check();
        
        if (active->clients.size() == Socket::max_clients) {
            socket_server->Write("Too many people here, you are not welcome\n");
            continue;
        } 

        string nickname = socket_server->Read(new_client);
        
        cout << "New client: " << nickname << endl;
        active->insert(new_client, nickname, ip);

        if (pthread_create(&tid, NULL, server_thread, &new_client) != 0)
            cout << "Failed to create thread" << endl;
    }

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq 0x576b(%rip), %rdi      # 0xb218
callq 0x2bd0
movq 0x575f(%rip), %rdi      # 0xb218
callq 0x305e
movq 0x5513(%rip), %rdi      # 0xafd8
leaq 0x2889(%rip), %rsi      # 0x8355
movl $0x14, %edx
callq 0x22b0
movq 0x573b(%rip), %rdi      # 0xb218
callq 0x2c8a
movq 0x572f(%rip), %rdi      # 0xb218
callq 0x305e
leaq -0x50(%rbp), %r13
leaq -0xc8(%rbp), %r12
leaq -0x68(%rbp), %rax
movq %rax, -0x78(%rbp)
movq $0x0, -0x70(%rbp)
movb $0x0, -0x68(%rbp)
movq 0x5704(%rip), %rsi      # 0xb218
leaq -0x58(%rbp), %rdi
callq 0x2d68
movl -0x58(%rbp), %eax
movl %eax, -0x2c(%rbp)
leaq -0x78(%rbp), %rdi
movq %r13, %rsi
callq 0x22e0
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x5b48
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2250
movq 0x56c9(%rip), %rdi      # 0xb218
callq 0x305e
movq 0x574d(%rip), %rax      # 0xb2a8
movq 0x8(%rax), %rcx
subq (%rax), %rcx
cmpq $0x1e00, %rcx           # imm = 0x1E00
jne 0x5bca
movq 0x56a6(%rip), %r14      # 0xb218
movq %r12, -0xd8(%rbp)
leaq -0xd8(%rbp), %r15
movq %r15, %rdi
leaq 0x27e0(%rip), %rsi      # 0x836a
leaq 0x2803(%rip), %rdx      # 0x8394
callq 0x28ae
movq %r14, %rdi
movq %r15, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x2f66
movq -0xd8(%rbp), %rdi
cmpq %r12, %rdi
je 0x5d6a
movq -0xc8(%rbp), %rsi
incq %rsi
callq 0x2250
jmp 0x5d6a
movq 0x5647(%rip), %rsi      # 0xb218
movl -0x2c(%rbp), %edx
leaq -0x58(%rbp), %rdi
callq 0x2e72
movq %r13, %r15
movl $0xc, %edx
movq 0x53ec(%rip), %rdi      # 0xafd8
leaq 0x27a2(%rip), %rsi      # 0x8395
callq 0x22b0
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq 0x53d1(%rip), %rdi      # 0xafd8
callq 0x22b0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2220
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2170
movq 0x566b(%rip), %r13      # 0xb2a8
movl -0x2c(%rbp), %r14d
leaq -0x88(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
addq %rsi, %rdx
leaq -0x98(%rbp), %rdi
callq 0x2810
leaq -0xa8(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x78(%rbp), %rsi
movq -0x70(%rbp), %rdx
addq %rsi, %rdx
leaq -0xb8(%rbp), %rbx
movq %rbx, %rdi
callq 0x2810
movq %r13, %rdi
movl %r14d, %esi
leaq -0x98(%rbp), %rdx
movq %rbx, %rcx
callq 0x6274
movq -0xb8(%rbp), %rdi
leaq -0xa8(%rbp), %rax
cmpq %rax, %rdi
je 0x5cc5
movq -0xa8(%rbp), %rsi
incq %rsi
callq 0x2250
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
cmpq %rax, %rdi
je 0x5ce7
movq -0x88(%rbp), %rsi
incq %rsi
callq 0x2250
leaq -0xe0(%rbp), %rdi
xorl %esi, %esi
leaq -0x2102(%rip), %rdx     # 0x3bf5
leaq -0x2c(%rbp), %rcx
callq 0x23b0
testl %eax, %eax
je 0x5d4e
movl $0x17, %edx
movq 0x52c8(%rip), %rdi      # 0xafd8
leaq 0x268b(%rip), %rsi      # 0x83a2
callq 0x22b0
movq 0x52b5(%rip), %rcx      # 0xafd8
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x2220
movsbl %al, %esi
movq 0x5297(%rip), %rdi      # 0xafd8
callq 0x2030
movq %rax, %rdi
callq 0x2170
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x5d67
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x2250
movq %r15, %r13
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
je 0x5af9
movq -0x68(%rbp), %rsi
incq %rsi
callq 0x2250
jmp 0x5af9
movq %rax, %rbx
movq -0xb8(%rbp), %rdi
leaq -0xa8(%rbp), %rax
cmpq %rax, %rdi
je 0x5db6
movq -0xa8(%rbp), %rsi
incq %rsi
callq 0x2250
jmp 0x5db6
movq %rax, %rbx
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
cmpq %rax, %rdi
je 0x5e00
movq -0x88(%rbp), %rsi
incq %rsi
callq 0x2250
jmp 0x5e00
movq %rax, %rbx
movq -0xd8(%rbp), %rdi
cmpq %r12, %rdi
je 0x5e19
movq -0xc8(%rbp), %rsi
jmp 0x5e11
jmp 0x5df8
jmp 0x5df8
jmp 0x5df8
movq %rax, %rbx
jmp 0x5e19
movq %rax, %rbx
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x5e19
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x2250
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
je 0x5e32
movq -0x68(%rbp), %rsi
incq %rsi
callq 0x2250
movq %rbx, %rdi
callq 0x2380