// File: /workspace/github_c_makefile_star2_O0/qq-smart[P]qq_sh_server/event/qq_event.c
// Function: qq_event_init
qq_int_t
qq_event_init(qq_cycle_t *cycle)
{
    qq_uint_t           i;
    qq_event_t         *rev, *wev;
    qq_listening_t     *ls;
    qq_connection_t    *c, *next;

    qq_queue_init(&qq_posted_accept_events);
    qq_queue_init(&qq_posted_events);

    if (qq_event_timer_init() == QQ_ERROR) {
        return QQ_ERROR;
    }
	
    if (qq_epoll_init() == QQ_ERROR) {
        return QQ_ERROR;
    }

    cycle->connection_n = QQ_CONNECTION_NUMBER;
    cycle->connections = qq_alloc(sizeof(qq_connection_t) * cycle->connection_n);
    if (cycle->connections == NULL) {
        qq_log_error(0, "connection malloc(%d) failed", cycle->connection_n);
        return QQ_ERROR;
    }
    c = cycle->connections;

    cycle->read_events = qq_alloc(sizeof(qq_event_t) * cycle->connection_n);
    if (cycle->read_events == NULL) {
        qq_log_error(0, "read_events malloc(%d) failed", cycle->connection_n);
        return QQ_ERROR;
    }
    rev = cycle->read_events;
    for (i = 0; i < cycle->connection_n; i++) {
        rev[i].closed = 1;
        rev[i].instance = 1;
    }

    cycle->write_events = qq_alloc(sizeof(qq_event_t) * cycle->connection_n);
    if (cycle->write_events == NULL) {
        qq_log_error(0, "write_events malloc(%d) failed", cycle->connection_n);
        return QQ_ERROR;
    }
    wev = cycle->write_events;
    for (i = 0; i < cycle->connection_n; i++) {
        wev[i].closed = 1;
    }

    i = cycle->connection_n;
    next = NULL;
    do {
        i--;

        c[i].data = next;
        c[i].read = &cycle->read_events[i];
        c[i].write = &cycle->write_events[i];
        c[i].fd = (qq_socket_t) -1;

        next = &c[i];
    } while (i);
    cycle->free_connections = next;
    cycle->free_connection_n = cycle->connection_n;

    ls = cycle->listening;
    for (i = 0; i < cycle->nlistening; i++) {
        c = qq_get_connection(ls[i].fd);
        if (c == NULL) {
            qq_log_error(0, "qq_get_connection() failed");
            return QQ_ERROR;
        }

        c->type = ls[i].type;
        c->listening = &ls[i];
        ls[i].connection = c;

        rev = c->read;
        rev->accept = 1;

        rev->handler = (c->type == SOCK_STREAM) ? qq_event_accept
                                                : qq_event_recvmsg;

        if (qq_epoll_add_event(rev, QQ_READ_EVENT) == QQ_ERROR) {
            qq_log_error(0, "qq_epoll_add_event() failed");
            return QQ_ERROR;
        }
    }

    return QQ_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
leaq 0x10a65(%rip), %rax     # 0x142f8
movq %rax, (%rax)
leaq 0x10a5b(%rip), %rax     # 0x142f8
movq %rax, 0x8(%rax)
leaq 0x10a60(%rip), %rax     # 0x14308
movq %rax, (%rax)
leaq 0x10a56(%rip), %rax     # 0x14308
movq %rax, 0x8(%rax)
callq 0x4940
cmpq $-0x1, %rax
jne 0x38ce
movq $-0x1, -0x8(%rbp)
jmp 0x3c84
callq 0x2f10
cmpq $-0x1, %rax
jne 0x38e6
movq $-0x1, -0x8(%rbp)
jmp 0x3c84
movq -0x10(%rbp), %rax
movq $0x4e20, 0x8(%rax)      # imm = 0x4E20
movq -0x10(%rbp), %rax
imulq $0xa0, 0x8(%rax), %rdi
callq 0x2470
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x393e
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
xorl %edi, %edi
leaq 0xbc6b(%rip), %rsi      # 0xf595
movb $0x0, %al
callq 0x9cc0
movq $-0x1, -0x8(%rbp)
jmp 0x3c84
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
imulq $0x58, 0x8(%rax), %rdi
callq 0x2470
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x28(%rax)
jne 0x3993
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
xorl %edi, %edi
leaq 0xbc33(%rip), %rsi      # 0xf5b2
movb $0x0, %al
callq 0x9cc0
movq $-0x1, -0x8(%rbp)
jmp 0x3c84
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x20(%rbp)
movq $0x0, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x39f9
movq -0x20(%rbp), %rax
imulq $0x58, -0x18(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %ecx
andl $0xfffeffff, %ecx       # imm = 0xFFFEFFFF
orl $0x10000, %ecx          # imm = 0x10000
movl %ecx, 0x8(%rax)
movq -0x20(%rbp), %rax
imulq $0x58, -0x18(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %ecx
andl $-0x5, %ecx
orl $0x4, %ecx
movl %ecx, 0x8(%rax)
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x39a7
movq -0x10(%rbp), %rax
imulq $0x58, 0x8(%rax), %rdi
callq 0x2470
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x30(%rax)
jne 0x3a42
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
xorl %edi, %edi
leaq 0xbba2(%rip), %rsi      # 0xf5d0
movb $0x0, %al
callq 0x9cc0
movq $-0x1, -0x8(%rbp)
jmp 0x3c84
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x28(%rbp)
movq $0x0, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x3a90
movq -0x28(%rbp), %rax
imulq $0x58, -0x18(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %ecx
andl $0xfffeffff, %ecx       # imm = 0xFFFEFFFF
orl $0x10000, %ecx          # imm = 0x10000
movl %ecx, 0x8(%rax)
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x3a56
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x18(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x18(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x18(%rbp)
movq -0x40(%rbp), %rcx
movq -0x38(%rbp), %rax
imulq $0xa0, -0x18(%rbp), %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rcx
imulq $0x58, -0x18(%rbp), %rax
addq %rax, %rcx
movq -0x38(%rbp), %rax
imulq $0xa0, -0x18(%rbp), %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rcx
imulq $0x58, -0x18(%rbp), %rax
addq %rax, %rcx
movq -0x38(%rbp), %rax
imulq $0xa0, -0x18(%rbp), %rdx
addq %rdx, %rax
movq %rcx, 0x10(%rax)
movq -0x38(%rbp), %rax
imulq $0xa0, -0x18(%rbp), %rcx
addq %rcx, %rax
movl $0xffffffff, 0x18(%rax) # imm = 0xFFFFFFFF
movq -0x38(%rbp), %rax
imulq $0xa0, -0x18(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x3aa4
movq -0x40(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x30(%rbp)
movq $0x0, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x38(%rcx), %rax
jae 0x3c7c
movq -0x30(%rbp), %rax
imulq $0x60, -0x18(%rbp), %rcx
addq %rcx, %rax
movl (%rax), %edi
callq 0x2920
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x3bbd
xorl %edi, %edi
leaq 0xba46(%rip), %rsi      # 0xf5ef
movb $0x0, %al
callq 0x9cc0
movq $-0x1, -0x8(%rbp)
jmp 0x3c84
movq -0x30(%rbp), %rax
imulq $0x60, -0x18(%rbp), %rcx
addq %rcx, %rax
movl 0x34(%rax), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x48(%rax)
movq -0x30(%rbp), %rcx
imulq $0x60, -0x18(%rbp), %rax
addq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x38(%rbp), %rcx
movq -0x30(%rbp), %rax
imulq $0x60, -0x18(%rbp), %rdx
addq %rdx, %rax
movq %rcx, 0x58(%rax)
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movl 0x8(%rax), %ecx
andl $-0x3, %ecx
orl $0x2, %ecx
movl %ecx, 0x8(%rax)
movq -0x38(%rbp), %rax
movl 0x48(%rax), %edx
leaq 0x72b(%rip), %rcx       # 0x4350
leaq 0x1a4(%rip), %rax       # 0x3dd0
cmpl $0x1, %edx
cmoveq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x20(%rbp), %rdi
movl $0x1, %esi
callq 0x3030
cmpq $-0x1, %rax
jne 0x3c69
xorl %edi, %edi
leaq 0xb9b2(%rip), %rsi      # 0xf60a
movb $0x0, %al
callq 0x9cc0
movq $-0x1, -0x8(%rbp)
jmp 0x3c84
jmp 0x3c6b
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x3b70
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nop