// File: /workspace/github_cpp_makefile_star2_O1/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 0x55f7(%rip), %rdi      # 0xb218
callq 0x2bc8
movq 0x55eb(%rip), %rdi      # 0xb218
callq 0x3056
movq 0x539f(%rip), %rdi      # 0xafd8
leaq 0x2715(%rip), %rsi      # 0x8355
movl $0x14, %edx
callq 0x22b0
movq 0x55c7(%rip), %rdi      # 0xb218
callq 0x2c82
movq 0x55bb(%rip), %rdi      # 0xb218
callq 0x3056
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 0x5590(%rip), %rsi      # 0xb218
leaq -0x58(%rbp), %rdi
callq 0x2d60
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 0x5cbc
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2250
movq 0x5555(%rip), %rdi      # 0xb218
callq 0x3056
movq 0x55d9(%rip), %rax      # 0xb2a8
movq 0x8(%rax), %rcx
subq (%rax), %rcx
cmpq $0x1e00, %rcx           # imm = 0x1E00
jne 0x5d3e
movq 0x5532(%rip), %r14      # 0xb218
movq %r12, -0xd8(%rbp)
leaq -0xd8(%rbp), %r15
movq %r15, %rdi
leaq 0x266c(%rip), %rsi      # 0x836a
leaq 0x268f(%rip), %rdx      # 0x8394
callq 0x28aa
movq %r14, %rdi
movq %r15, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x2f5e
movq -0xd8(%rbp), %rdi
cmpq %r12, %rdi
je 0x5ede
movq -0xc8(%rbp), %rsi
incq %rsi
callq 0x2250
jmp 0x5ede
movq 0x54d3(%rip), %rsi      # 0xb218
movl -0x2c(%rbp), %edx
leaq -0x58(%rbp), %rdi
callq 0x2e6a
movq %r13, %r15
movl $0xc, %edx
movq 0x5278(%rip), %rdi      # 0xafd8
leaq 0x262e(%rip), %rsi      # 0x8395
callq 0x22b0
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq 0x525d(%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 0x54f7(%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 0x63e4
movq -0xb8(%rbp), %rdi
leaq -0xa8(%rbp), %rax
cmpq %rax, %rdi
je 0x5e39
movq -0xa8(%rbp), %rsi
incq %rsi
callq 0x2250
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
cmpq %rax, %rdi
je 0x5e5b
movq -0x88(%rbp), %rsi
incq %rsi
callq 0x2250
leaq -0xe0(%rbp), %rdi
xorl %esi, %esi
leaq -0x2250(%rip), %rdx     # 0x3c1b
leaq -0x2c(%rbp), %rcx
callq 0x23b0
testl %eax, %eax
je 0x5ec2
movl $0x17, %edx
movq 0x5154(%rip), %rdi      # 0xafd8
leaq 0x2517(%rip), %rsi      # 0x83a2
callq 0x22b0
movq 0x5141(%rip), %rcx      # 0xafd8
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x2220
movsbl %al, %esi
movq 0x5123(%rip), %rdi      # 0xafd8
callq 0x2030
movq %rax, %rdi
callq 0x2170
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x5edb
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x2250
movq %r15, %r13
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
je 0x5c6d
movq -0x68(%rbp), %rsi
incq %rsi
callq 0x2250
jmp 0x5c6d
movq %rax, %rbx
movq -0xb8(%rbp), %rdi
leaq -0xa8(%rbp), %rax
cmpq %rax, %rdi
je 0x5f2a
movq -0xa8(%rbp), %rsi
incq %rsi
callq 0x2250
jmp 0x5f2a
movq %rax, %rbx
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
cmpq %rax, %rdi
je 0x5f74
movq -0x88(%rbp), %rsi
incq %rsi
callq 0x2250
jmp 0x5f74
movq %rax, %rbx
movq -0xd8(%rbp), %rdi
cmpq %r12, %rdi
je 0x5f8d
movq -0xc8(%rbp), %rsi
jmp 0x5f85
jmp 0x5f6c
jmp 0x5f6c
jmp 0x5f6c
movq %rax, %rbx
jmp 0x5f8d
movq %rax, %rbx
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x5f8d
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x2250
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
je 0x5fa6
movq -0x68(%rbp), %rsi
incq %rsi
callq 0x2250
movq %rbx, %rdi
callq 0x2380