// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/src/networking.c
// Function: acceptCommonHandler
static void acceptCommonHandler(int fd, int flags, char *ip) {
    client *c;
    if ((c = createClient(fd)) == NULL) {
        serverLog(LL_WARNING,
            "Error registering fd event for the new client: %s (fd=%d)",
            strerror(errno),fd);
        close(fd); /* May be already closed, just ignore errors */
        return;
    }
    /* If maxclient directive is set and this is one client more... close the
     * connection. Note that we create the client instead to check before
     * for this condition, since now the socket is already set in non-blocking
     * mode and we can send an error for free using the Kernel I/O */
    if (listLength(server.clients) > server.maxclients) {
        char *err = "-ERR max number of clients reached\r\n";

        /* That's a best effort error message, don't check write errors */
        if (write(c->fd,err,strlen(err)) == -1) {
            /* Nothing to do, Just to avoid the warning... */
        }
        server.stat_rejected_conn++;
        freeClient(c);
        return;
    }

    /* If the server is running in protected mode (the default) and there
     * is no password set, nor a specific interface is bound, we don't accept
     * requests from non loopback interfaces. Instead we try to explain the
     * user what to do to fix it if needed. */
    if (server.protected_mode &&
        server.bindaddr_count == 0 &&
        server.requirepass == NULL &&
        !(flags & CLIENT_UNIX_SOCKET) &&
        ip != NULL)
    {
        if (strcmp(ip,"127.0.0.1") && strcmp(ip,"::1")) {
            char *err =
                "-DENIED Redis is running in protected mode because protected "
                "mode is enabled, no bind address was specified, no "
                "authentication password is requested to clients. In this mode "
                "connections are only accepted from the loopback interface. "
                "If you want to connect from external computers to Redis you "
                "may adopt one of the following solutions: "
                "1) Just disable protected mode sending the command "
                "'CONFIG SET protected-mode no' from the loopback interface "
                "by connecting to Redis from the same host the server is "
                "running, however MAKE SURE Redis is not publicly accessible "
                "from internet if you do so. Use CONFIG REWRITE to make this "
                "change permanent. "
                "2) Alternatively you can just disable the protected mode by "
                "editing the Redis configuration file, and setting the protected "
                "mode option to 'no', and then restarting the server. "
                "3) If you started the server manually just for testing, restart "
                "it with the '--protected-mode no' option. "
                "4) Setup a bind address or an authentication password. "
                "NOTE: You only need to do one of the above things in order for "
                "the server to start accepting connections from the outside.\r\n";
            if (write(c->fd,err,strlen(err)) == -1) {
                /* Nothing to do, Just to avoid the warning... */
            }
            server.stat_rejected_conn++;
            freeClient(c);
            return;
        }
    }

    server.stat_numconnections++;
    c->flags |= flags;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdx, %r14
movl %esi, %ebp
movl %edi, %r15d
callq 0x3f180
testq %rax, %rax
je 0x40978
movq %rax, %rbx
leaq 0xc5f21(%rip), %r15     # 0x106858
movq 0x1c8(%r15), %rax
movl 0x8f4(%r15), %ecx
cmpq %rcx, 0x28(%rax)
jbe 0x409af
movl 0x8(%rbx), %edi
leaq 0x82bcf(%rip), %rsi     # 0xc3524
movl $0x24, %edx
callq 0x26bc0
incq 0x3c8(%r15)
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x40b04
callq 0x26890
movl (%rax), %edi
callq 0x26690
leaq 0x82b5f(%rip), %rsi     # 0xc34ea
movl $0x3, %edi
movq %rax, %rdx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x32ea6
movl %r15d, %edi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x26180
cmpl $0x0, 0x318(%r15)
je 0x40a16
cmpl $0x0, 0x128(%r15)
jne 0x40a16
cmpq $0x0, 0x58(%r15)
jne 0x40a16
movl %ebp, %eax
shrl $0xb, %eax
andl $0x1, %eax
testq %r14, %r14
sete %cl
orb %al, %cl
jne 0x40a16
leaq 0x82b66(%rip), %rsi     # 0xc3549
movq %r14, %rdi
callq 0x26900
testl %eax, %eax
je 0x40a16
leaq 0x82b5d(%rip), %rsi     # 0xc3553
movq %r14, %rdi
callq 0x26900
testl %eax, %eax
je 0x40a16
movl 0x8(%rbx), %edi
leaq 0x82b4b(%rip), %rsi     # 0xc3557
movl $0x44d, %edx            # imm = 0x44D
jmp 0x4095a
incq 0x388(%r15)
orl %ebp, 0x98(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq