// File: /workspace/github_c_makefile_star2_O0/qq-smart[P]qq_sh_server/event/qq_event_accept.c
// Function: qq_event_accept
void
qq_event_accept(qq_event_t *ev)
{
    socklen_t          socklen;
    qq_err_t           err;
    qq_socket_t        s;
    qq_event_t        *rev, *wev;
    struct sockaddr    sa;
    qq_listening_t    *ls;
    qq_connection_t   *c, *lc;

    qq_log_debug("qq_event_accept(%p)", ev);

    if (ev->timedout) {
        if (qq_enable_accept_events((qq_cycle_t *) qq_cycle) != QQ_OK) {
            return;
        }
        ev->timedout = 0;
    }

    lc = ev->data;
    ls = lc->listening;
    ev->ready = 0;

    qq_log_debug("accept on %s", ls->addr_text);

    for (;;) {
        socklen = sizeof(struct sockaddr);

        s = accept(lc->fd, &sa, &socklen);
        if (s == (qq_socket_t) -1) {
            err = errno;

            if (err == QQ_EAGAIN) {
                qq_log_debug("accept() not ready");
                return;
            }

            qq_log_error(err, "accept() failed");

            if (err == QQ_ECONNABORTED) {
                continue;
            }

            if (err == QQ_EMFILE || err == QQ_ENFILE) {
                if (qq_disable_accept_events((qq_cycle_t *) qq_cycle)
                    != QQ_OK)
                {
                    return;
                }
            }
            return;
        }

        c = qq_get_connection(s);
        if (c == NULL) {
            if (close(s) == -1) {
                qq_log_error(errno, "close sockets failed");
            }
            return;
        }
        c->type = SOCK_STREAM;

        c->pool = qq_create_pool(ls->pool_size);
        if (c->pool == NULL) {
            qq_close_accepted_connection(c);
            return;
        }

        c->sockaddr = qq_palloc(c->pool, socklen);
        if (c->sockaddr == NULL) {
            qq_close_accepted_connection(c);
            return;
        }
        memcpy(c->sockaddr, &sa, socklen);

        if (qq_nonblocking(s) == -1) {
            qq_log_error(errno, "set sockets nonblocking_n failed");
            qq_close_accepted_connection(c);
            return;
        }

        c->recv = qq_tcp_recv;
        c->send = qq_tcp_send;

        c->socklen = socklen;
        c->listening = ls;
        c->local_sockaddr = (struct sockaddr*) &ls->sockaddr;
        c->local_socklen = ls->socklen;

        rev = c->read;
        wev = c->write;
        wev->ready = 1;

        if (ev->deferred_accept) {
            rev->ready = 1;
        }

        c->addr_text = qq_pnalloc(c->pool, QQ_SOCKADDR_STRLEN);
        if (c->addr_text == NULL) {
            qq_close_accepted_connection(c);
            return;
        }
        memset(c->addr_text, 0, QQ_SOCKADDR_STRLEN);
        c->addr_text_len = qq_sock_ntop((struct sockaddr_in *)c->sockaddr, c->addr_text);
        if (c->addr_text_len == 0) {
            qq_close_accepted_connection(c);
            return;
        }        
        qq_log_debug("connection address: %s, address len: %d",
            c->addr_text, c->addr_text_len);

        if (qq_epoll_add_connection(c) == QQ_ERROR) {
            qq_close_accepted_connection(c);
            return;
        }

        ls->handler(c);
        return;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rsi
leaq 0xb85f(%rip), %rdi      # 0xf646
movb $0x0, %al
callq 0x9e70
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
shrl $0xa, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x3e2d
leaq 0x104d9(%rip), %rax     # 0x142e0
movq (%rax), %rdi
callq 0x4180
cmpq $0x0, %rax
je 0x3e1a
jmp 0x4173
movq -0x8(%rbp), %rax
movl 0x8(%rax), %ecx
andl $0xfffffbff, %ecx       # imm = 0xFFFFFBFF
orl $0x0, %ecx
movl %ecx, 0x8(%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movl 0x8(%rax), %ecx
andl $-0x21, %ecx
orl $0x0, %ecx
movl %ecx, 0x8(%rax)
movq -0x40(%rbp), %rsi
addq $0x18, %rsi
leaq 0xb7f7(%rip), %rdi      # 0xf65a
movb $0x0, %al
callq 0x9e70
movl $0x10, -0xc(%rbp)
movq -0x50(%rbp), %rax
movl 0x18(%rax), %edi
leaq -0x38(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rsi
leaq -0xc(%rbp), %rdx
callq 0x20a0
movl %eax, -0x14(%rbp)
cmpl $-0x1, -0x14(%rbp)
jne 0x3eff
callq 0x2030
movl (%rax), %eax
movl %eax, -0x10(%rbp)
cmpl $0xb, -0x10(%rbp)
jne 0x3eb9
leaq 0xb7ba(%rip), %rdi      # 0xf667
movb $0x0, %al
callq 0x9e70
jmp 0x4173
movl -0x10(%rbp), %edi
leaq 0xb7b7(%rip), %rsi      # 0xf67a
movb $0x0, %al
callq 0x9cc0
cmpl $0x67, -0x10(%rbp)
jne 0x3ed2
jmp 0x3e6a
cmpl $0x18, -0x10(%rbp)
je 0x3ede
cmpl $0x17, -0x10(%rbp)
jne 0x3efa
leaq 0x103fb(%rip), %rax     # 0x142e0
movq (%rax), %rdi
callq 0x4230
cmpq $0x0, %rax
je 0x3ef8
jmp 0x4173
jmp 0x3efa
jmp 0x4173
movl -0x14(%rbp), %edi
callq 0x2920
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x3f39
movl -0x14(%rbp), %edi
callq 0x2350
cmpl $-0x1, %eax
jne 0x3f34
callq 0x2030
movl (%rax), %edi
leaq 0xb75d(%rip), %rsi      # 0xf68a
movb $0x0, %al
callq 0x9cc0
jmp 0x4173
movq -0x48(%rbp), %rax
movl $0x1, 0x48(%rax)
movq -0x40(%rbp), %rax
movq 0x50(%rax), %rdi
callq 0xba30
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x48(%rbp), %rax
cmpq $0x0, 0x40(%rax)
jne 0x3f75
movq -0x48(%rbp), %rdi
callq 0x42e0
jmp 0x4173
movq -0x48(%rbp), %rax
movq 0x40(%rax), %rdi
movl -0xc(%rbp), %eax
movl %eax, %esi
callq 0xba90
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x48(%rbp), %rax
cmpq $0x0, 0x50(%rax)
jne 0x3fab
movq -0x48(%rbp), %rdi
callq 0x42e0
jmp 0x4173
movq -0x48(%rbp), %rax
movq 0x50(%rax), %rdi
movl -0xc(%rbp), %eax
movl %eax, %edx
leaq -0x38(%rbp), %rsi
callq 0x21e0
movl -0x14(%rbp), %eax
movl %eax, -0x5c(%rbp)
movl -0x14(%rbp), %edi
movl $0x3, %esi
movb $0x0, %al
callq 0x2180
movl -0x5c(%rbp), %edi
movl %eax, %edx
orl $0x800, %edx            # imm = 0x800
movl $0x4, %esi
movb $0x0, %al
callq 0x2180
cmpl $-0x1, %eax
jne 0x4015
callq 0x2030
movl (%rax), %edi
leaq 0xb69f(%rip), %rsi      # 0xf69f
movb $0x0, %al
callq 0x9cc0
movq -0x48(%rbp), %rdi
callq 0x42e0
jmp 0x4173
movq -0x48(%rbp), %rax
leaq 0x9090(%rip), %rcx      # 0xd0b0
movq %rcx, 0x28(%rax)
movq -0x48(%rbp), %rax
leaq 0x9261(%rip), %rcx      # 0xd290
movq %rcx, 0x30(%rax)
movl -0xc(%rbp), %ecx
movq -0x48(%rbp), %rax
movl %ecx, 0x58(%rax)
movq -0x40(%rbp), %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x40(%rbp), %rcx
addq $0x4, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x70(%rax)
movq -0x40(%rbp), %rax
movl 0x14(%rax), %ecx
movq -0x48(%rbp), %rax
movl %ecx, 0x78(%rax)
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movl 0x8(%rax), %ecx
andl $-0x21, %ecx
orl $0x20, %ecx
movl %ecx, 0x8(%rax)
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
shrl $0xd, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x40b1
movq -0x20(%rbp), %rax
movl 0x8(%rax), %ecx
andl $-0x21, %ecx
orl $0x20, %ecx
movl %ecx, 0x8(%rax)
movq -0x48(%rbp), %rax
movq 0x40(%rax), %rdi
movl $0x16, %esi
callq 0xbb00
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x60(%rax)
movq -0x48(%rbp), %rax
cmpq $0x0, 0x60(%rax)
jne 0x40e7
movq -0x48(%rbp), %rdi
callq 0x42e0
jmp 0x4173
movq -0x48(%rbp), %rax
movq 0x60(%rax), %rdi
xorl %esi, %esi
movl $0x16, %edx
callq 0x2170
movq -0x48(%rbp), %rax
movq 0x50(%rax), %rdi
movq -0x48(%rbp), %rax
movq 0x60(%rax), %rsi
callq 0x4b00
movl %eax, %ecx
movq -0x48(%rbp), %rax
movl %ecx, 0x68(%rax)
movq -0x48(%rbp), %rax
cmpl $0x0, 0x68(%rax)
jne 0x412e
movq -0x48(%rbp), %rdi
callq 0x42e0
jmp 0x4173
movq -0x48(%rbp), %rax
movq 0x60(%rax), %rsi
movq -0x48(%rbp), %rax
movl 0x68(%rax), %edx
leaq 0xb57c(%rip), %rdi      # 0xf6c0
movb $0x0, %al
callq 0x9e70
movq -0x48(%rbp), %rdi
callq 0x3290
cmpq $-0x1, %rax
jne 0x4165
movq -0x48(%rbp), %rdi
callq 0x42e0
jmp 0x4173
movq -0x40(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x48(%rbp), %rdi
callq *%rax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)