// File: lega911[P]ijson/src/server.cpp
// Function: Server::_accept()
void Server::_accept() {
    while (true) {
        struct sockaddr_in peer_addr;
        socklen_t peer_addr_len = sizeof(peer_addr);
        int fd = accept(_fd, (struct sockaddr *)&peer_addr, &peer_addr_len);
        if(fd < 0) {
            if(log & 1) std::cout << ltime() << "warning: accept error\n";
            continue;
        }
        if(fd >= MAX_CONNECTS) {
            std::cout << "socket fd (" << fd << ") >= " << MAX_CONNECTS << std::endl;
            THROW("socket fd error");
        }
        unblock_socket(fd);

        if(!_valid_ip(peer_addr.sin_addr.s_addr)) {
            close(fd);
            if(log & 8) std::cout << ltime() << "Client filtered\n";
            continue;
        };

        if(connections[fd]) THROW("Connection place is not empty");
        Connect* conn = new Connect(this, fd);
        connections[fd] = conn;
        conn->link();

        if(fd > max_fd) max_fd = fd;
        if(log & 16) std::cout << ltime() << "connect " << fd << " " << (void*)conn << std::endl;

        loops[active_loop]->accept(conn);
        stat_connect++;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movl $0x10, -0x1c(%rbp)
movl (%rax), %edi
leaq -0x18(%rbp), %rsi
leaq -0x1c(%rbp), %rdx
callq 0x190e0
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jge 0x27b2b
movq -0x40(%rbp), %rax
movl 0x20(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x27b29
callq 0x36960
movq %rax, %rsi
movq 0x1f4bb(%rip), %rdi     # 0x46fd0
callq 0x192e0
movq %rax, %rdi
leaq 0x117d3(%rip), %rsi     # 0x392f7
callq 0x192e0
jmp 0x27ad4
cmpl $0x4000, -0x20(%rbp)    # imm = 0x4000
jl 0x27be7
movq 0x1f491(%rip), %rdi     # 0x46fd0
leaq 0x117c8(%rip), %rsi     # 0x3930e
callq 0x192e0
movq %rax, %rdi
movl -0x20(%rbp), %esi
callq 0x19490
movq %rax, %rdi
leaq 0x117ba(%rip), %rsi     # 0x3931a
callq 0x192e0
movq %rax, %rdi
movl $0x4000, %esi           # imm = 0x4000
callq 0x19490
movq %rax, %rdi
movq 0x1f434(%rip), %rsi     # 0x46fb0
callq 0x19320
movl $0x30, %edi
callq 0x19180
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x48(%rbp)
leaq 0x11784(%rip), %rsi     # 0x39320
leaq 0x116a3(%rip), %rdx     # 0x39246
leaq 0x11786(%rip), %r8      # 0x39330
movl $0x51, %ecx
callq 0x22ba0
jmp 0x27bb6
movq -0x48(%rbp), %rdi
leaq 0x1f13f(%rip), %rsi     # 0x46d00
leaq -0x4ab8(%rip), %rdx     # 0x23110
callq 0x19480
movq -0x48(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
callq 0x19210
jmp 0x27dcd
movl -0x20(%rbp), %edi
callq 0x27570
movq -0x40(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x27a20
testb $0x1, %al
jne 0x27c3e
movl -0x20(%rbp), %edi
callq 0x19500
movq -0x40(%rbp), %rax
movl 0x20(%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x27c39
callq 0x36960
movq %rax, %rsi
movq 0x1f3ab(%rip), %rdi     # 0x46fd0
callq 0x192e0
movq %rax, %rdi
leaq 0x11713(%rip), %rsi     # 0x39347
callq 0x192e0
jmp 0x27ad4
movq -0x40(%rbp), %rax
movslq -0x20(%rbp), %rcx
cmpq $0x0, 0x50(%rax,%rcx,8)
je 0x27cb4
movl $0x30, %edi
callq 0x19180
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x50(%rbp)
leaq 0x116ef(%rip), %rsi     # 0x39358
leaq 0x115d6(%rip), %rdx     # 0x39246
leaq 0x116b9(%rip), %r8      # 0x39330
movl $0x5b, %ecx
callq 0x22ba0
jmp 0x27c83
movq -0x50(%rbp), %rdi
leaq 0x1f072(%rip), %rsi     # 0x46d00
leaq -0x4b85(%rip), %rdx     # 0x23110
callq 0x19480
movq -0x50(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
callq 0x19210
jmp 0x27dcd
movl $0x1e8, %edi            # imm = 0x1E8
callq 0x27250
movq -0x40(%rbp), %rsi
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x58(%rbp)
movl -0x20(%rbp), %edx
callq 0x2cc60
jmp 0x27cd6
movq -0x40(%rbp), %rax
movq -0x58(%rbp), %rcx
movq %rcx, -0x38(%rbp)
movq -0x38(%rbp), %rdx
movslq -0x20(%rbp), %rcx
movq %rdx, 0x50(%rax,%rcx,8)
movq -0x38(%rbp), %rdi
callq 0x2cf70
movq -0x40(%rbp), %rcx
movl -0x20(%rbp), %eax
cmpl 0x8(%rcx), %eax
jle 0x27d2f
movq -0x40(%rbp), %rax
movl -0x20(%rbp), %ecx
movl %ecx, 0x8(%rax)
jmp 0x27d2f
movq -0x58(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl $0x1e8, %esi            # imm = 0x1E8
callq 0x19300
jmp 0x27dcd
movq -0x40(%rbp), %rax
movl 0x20(%rax), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x27d96
callq 0x36960
movq %rax, %rsi
movq 0x1f283(%rip), %rdi     # 0x46fd0
callq 0x192e0
movq %rax, %rdi
leaq 0x10346(%rip), %rsi     # 0x380a2
callq 0x192e0
movq %rax, %rdi
movl -0x20(%rbp), %esi
callq 0x19490
movq %rax, %rdi
leaq 0x1092e(%rip), %rsi     # 0x386a4
callq 0x192e0
movq %rax, %rdi
movq -0x38(%rbp), %rsi
callq 0x19250
movq %rax, %rdi
movq 0x1f21f(%rip), %rsi     # 0x46fb0
callq 0x19320
movq -0x40(%rbp), %rcx
movq 0x20050(%rcx), %rax
movslq 0x4(%rcx), %rcx
movq (%rax,%rcx,8), %rdi
movq -0x38(%rbp), %rsi
callq 0x27de0
movq -0x40(%rbp), %rax
movq 0x20080(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x20080(%rax)
jmp 0x27ad4
movq -0x28(%rbp), %rdi
callq 0x194a0
nopw %cs:(%rax,%rax)