// File: /workspace/github_c_makefile_star2_O3/qq-smart[P]qq_sh_server/core/qq_listening.c
// Function: qq_create_listening
qq_int_t
qq_create_listening(qq_cycle_t *cycle)
{
    size_t                  size;
    int                     i;
    qq_listening_t         *ls;
    qq_listening_config_t  *p, *n;

    size = sizeof(qq_listening_t) * cycle->nlistening;
    cycle->listening = qq_pcalloc(cycle->pool, size);
    if (cycle->listening == NULL) {
        qq_log_error(0, "qq_listening_t malloc(%u) failed", size);
        return QQ_ERROR;
    }

    cycle->current_listening_config = cycle->listening_config;

    ls = cycle->listening;
    for (i = 0; i < cycle->nlistening; i++) {
        ls[i].sockaddr.sin_family = AF_INET;
        ls[i].sockaddr.sin_addr.s_addr = htonl(INADDR_ANY);
        ls[i].sockaddr.sin_port = htons(cycle->current_listening_config->port);
        ls[i].socklen = sizeof(struct sockaddr);

        ls[i].addr_text_len = qq_sock_ntop(&ls[i].sockaddr, ls[i].addr_text);
        qq_log_debug("listening address: %s, address len: %d",
            ls[i].addr_text, ls[i].addr_text_len);

        ls[i].fd = (qq_socket_t) -1;
        ls[i].type = cycle->current_listening_config->type;

        ls[i].backlog = QQ_LISTEN_BACKLOG;
        ls[i].rcvbuf = QQ_SOCK_REVBUF_SIZE;
        ls[i].sndbuf = QQ_SOCK_SNDBUF_SIZE;

        ls[i].handler = cycle->current_listening_config->handler;
        ls[i].pool_size = cycle->current_listening_config->pool_size;

        cycle->current_listening_config = cycle->current_listening_config->next;
    }

    for (p = cycle->listening_config, n = cycle->listening_config->next;
         /* void */;
         p = n, n = n->next) {
        free(p);
        if (n == NULL) {
            break;
        }
    }

    return QQ_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq (%rdi), %rdi
movq 0x38(%rbx), %rax
shlq $0x5, %rax
leaq (%rax,%rax,2), %r15
movq %r15, %rsi
callq 0x7d16
movq %rax, 0x40(%rbx)
testq %rax, %rax
je 0x65f2
movq 0x48(%rbx), %rdi
movq %rdi, 0x50(%rbx)
cmpq $0x0, 0x38(%rbx)
je 0x65de
movq %rax, %r14
movabsq $0x2000000001ff, %r13   # imm = 0x2000000001FF
xorl %r15d, %r15d
movw $0x2, 0x4(%r14)
movl $0x0, 0x8(%r14)
movzwl 0xc(%rdi), %eax
rolw $0x8, %ax
leaq 0x4(%r14), %rdi
movw %ax, 0x6(%r14)
movl $0x10, 0x14(%r14)
leaq 0x18(%r14), %r12
movq %r12, %rsi
callq 0x3ba8
movl %eax, 0x30(%r14)
leaq 0x4462(%rip), %rdi      # 0xa9ea
movq %r12, %rsi
movl %eax, %edx
xorl %eax, %eax
callq 0x6c74
movl $0xffffffff, (%r14)     # imm = 0xFFFFFFFF
movq 0x50(%rbx), %rax
movl 0x8(%rax), %ecx
movl %ecx, 0x34(%r14)
movq %r13, 0x38(%r14)
movl $0x2000, 0x40(%r14)     # imm = 0x2000
movq 0x18(%rax), %rcx
movq %rcx, 0x48(%r14)
movq 0x10(%rax), %rcx
movq %rcx, 0x50(%r14)
movq (%rax), %rdi
movq %rdi, 0x50(%rbx)
incq %r15
addq $0x60, %r14
cmpq %r15, 0x38(%rbx)
ja 0x6549
movq 0x48(%rbx), %rdi
xorl %ebx, %ebx
movq (%rdi), %r14
callq 0x2338
movq %r14, %rdi
testq %r14, %r14
jne 0x65e0
jmp 0x660c
leaq 0x43d0(%rip), %rsi      # 0xa9c9
xorl %edi, %edi
movq %r15, %rdx
xorl %eax, %eax
callq 0x6b27
movq $-0x1, %rbx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq