// File: /workspace/github_cpp_makefile_star2_O2/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 $0xc8, %rsp
movq 0x5d3b(%rip), %rdi      # 0xa210
callq 0x29ba
movq 0x5d2f(%rip), %rdi      # 0xa210
callq 0x2d62
movq 0x5aeb(%rip), %rdi      # 0x9fd8
leaq 0x1e61(%rip), %rsi      # 0x6355
callq 0x2200
movq 0x5d10(%rip), %rdi      # 0xa210
callq 0x2a48
movq 0x5d04(%rip), %rdi      # 0xa210
callq 0x2d62
leaq -0xb0(%rbp), %r15
leaq -0x60(%rbp), %r12
leaq -0xd0(%rbp), %r13
leaq -0x50(%rbp), %rax
movq %rax, -0x60(%rbp)
andq $0x0, -0x58(%rbp)
movb $0x0, -0x50(%rbp)
movq 0x5cd5(%rip), %rsi      # 0xa210
movq %r15, %rdi
callq 0x2afe
movq %r12, -0x40(%rbp)
leaq -0x2c(%rbp), %rax
movq %rax, -0x38(%rbp)
leaq -0x40(%rbp), %rdi
movq %r15, %rsi
callq 0x4c8e
leaq -0xa8(%rbp), %rdi
callq 0x2110
movq 0x5ca2(%rip), %rdi      # 0xa210
callq 0x2d62
movq 0x5d26(%rip), %rax      # 0xa2a0
movq 0x8(%rax), %rcx
subq (%rax), %rcx
cmpq $0x1e00, %rcx           # imm = 0x1E00
jne 0x45c0
movq 0x5c7f(%rip), %rbx      # 0xa210
leaq -0xf0(%rbp), %r14
movq %r14, %rdi
leaq 0x1dc8(%rip), %rsi      # 0x636a
movq %r15, %rdx
callq 0x271a
movq %rbx, %rdi
movq %r14, %rsi
pushq $-0x1
popq %rdx
callq 0x2c8e
movq %r14, %rdi
jmp 0x467b
movq 0x5c49(%rip), %rsi      # 0xa210
movl -0x2c(%rbp), %edx
movq %r15, %rdi
callq 0x2bd6
movq 0x59ff(%rip), %rdi      # 0x9fd8
leaq 0x1db5(%rip), %rsi      # 0x6395
callq 0x2200
movq %rax, %rdi
movq %r15, %rsi
callq 0x21e0
movq %rax, %rdi
callq 0x2120
movq 0x5ca1(%rip), %r14      # 0xa2a0
movl -0x2c(%rbp), %ebx
leaq -0x88(%rbp), %rdi
movq %r15, %rsi
callq 0x22b0
movq %r13, %rdi
movq %r12, %rsi
callq 0x22b0
movq %r14, %rdi
movl %ebx, %esi
leaq -0x88(%rbp), %rbx
movq %rbx, %rdx
movq %r13, %rcx
callq 0x4cb6
movq %r13, %rdi
callq 0x2110
movq %rbx, %rdi
callq 0x2110
leaq -0x68(%rbp), %rdi
xorl %esi, %esi
leaq -0x1329(%rip), %rdx     # 0x3327
leaq -0x2c(%rbp), %rcx
callq 0x2380
testl %eax, %eax
je 0x4678
movq 0x5974(%rip), %rdi      # 0x9fd8
leaq 0x1d37(%rip), %rsi      # 0x63a2
callq 0x2200
movq %rax, %rdi
callq 0x2120
movq %r15, %rdi
callq 0x2110
movq %r12, %rdi
callq 0x2110
jmp 0x4523
movq %rax, %rbx
leaq -0xd0(%rbp), %rdi
callq 0x2110
jmp 0x46a1
movq %rax, %rbx
leaq -0x88(%rbp), %rdi
callq 0x2110
jmp 0x46c9
movq %rax, %rbx
leaq -0xf0(%rbp), %rdi
jmp 0x46d0
jmp 0x46c1
jmp 0x46c1
jmp 0x46c1
movq %rax, %rbx
jmp 0x46d5
movq %rax, %rbx
leaq -0xb0(%rbp), %rdi
callq 0x2110
leaq -0x60(%rbp), %rdi
callq 0x2110
movq %rbx, %rdi
callq 0x2350