// File: /workspace/github_cpp_makefile_star2_O2/shaovie[P]reactor/src/poller.cpp
// Function: poller::open(options const&)
int poller::open(const options &opt) {
    if (opt.poll_io_buf_size < 1) {
        fprintf(stderr, "reactor: poll_io_buf_size=%d < 1\n", opt.poll_io_buf_size);
        return -1;
    }
    if (opt.timer_init_size < 1) {
        fprintf(stderr, "reactor: timer_init_size=%d < 1\n", opt.timer_init_size);
        return -1;
    }
    if (opt.ready_events_size < 1) {
        fprintf(stderr, "reactor: ready_events_size=%d < 1\n", opt.ready_events_size);
        return -1;
    }
    if (opt.max_fd_estimate < 1) {
        fprintf(stderr, "reactor: max_fd_estimate=%d < 1\n", opt.max_fd_estimate);
        return -1;
    }
    int fd = ::epoll_create1(EPOLL_CLOEXEC);
    if (fd == -1) {
        fprintf(stderr, "reactor: epoll_create1 fail! %s\n", strerror(errno));
        return -1;
    }
    this->efd = fd;

    // The following failed operation, ignoring resource release
    this->poll_descs = new poll_desc_map(opt.max_fd_estimate);
    std::default_random_engine dre;
    dre.seed(this->efd);
    this->seq.store(dre(), std::memory_order_relaxed);

    this->ready_events_size = opt.ready_events_size;
    this->ready_events = new struct epoll_event[this->ready_events_size]();

    this->io_buf_size = opt.poll_io_buf_size;
    this->io_buf = new char[this->io_buf_size];

    this->timer = new timer_qheap(opt.timer_init_size);
    if (timer->open() == -1) {
        this->destroy();
        return -1;
    }

    if (this->add(timer, timer->get_fd(), ev_handler::ev_read) != 0) {
        fprintf(stderr, "reactor: add timer to poller fail! %s\n", strerror(errno));
        this->destroy();
        return -1;
    }

    this->async_sendq = new async_send(256);
    if (this->async_sendq->open(this) != 0) {
        this->destroy();
        return -1;
    }

    this->poll_sync_opterate = new poll_sync_opt(8);
    if (this->poll_sync_opterate->open(this) != 0) {
        this->destroy();
        return -1;
    }

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl 0x4(%rsi), %edx
testl %edx, %edx
jle 0xa545
movq %rsi, %r14
movl 0x14(%rsi), %edx
testl %edx, %edx
jle 0xa558
movl 0xc(%r14), %edx
testl %edx, %edx
jle 0xa56b
movl 0x10(%r14), %edx
testl %edx, %edx
jle 0xa57e
movq %rdi, %rbx
movl $0x80000, %edi          # imm = 0x80000
callq 0x9870
cmpl $-0x1, %eax
je 0xa59b
movl %eax, 0x4(%rbx)
pushq $0x70
popq %rdi
callq 0x96c0
movq %rax, %r15
movl 0x10(%r14), %esi
movq %rax, %rdi
callq 0x9b10
movq %r15, 0x30(%rbx)
movslq 0x4(%rbx), %rax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorl %edx, %edx
divq %rcx
cmpq $0x1, %rdx
adcq $0x0, %rdx
imulq $0x41a7, %rdx, %rax     # imm = 0x41A7
xorl %edx, %edx
divq %rcx
movq %rdx, 0x48(%rbx)
movslq 0xc(%r14), %rax
movl %eax, 0x8(%rbx)
pushq $0xc
popq %rcx
mulq %rcx
pushq $-0x1
popq %r15
cmovnoq %rax, %r15
movq %r15, %rdi
callq 0x9030
movq %rax, %r12
movq %rax, %rdi
xorl %esi, %esi
movq %r15, %rdx
callq 0x93b0
movq %r12, 0x18(%rbx)
movl 0x4(%r14), %eax
movl %eax, 0xc(%rbx)
testl %eax, %eax
pushq $-0x1
popq %rbp
cmovsl %ebp, %eax
movslq %eax, %rdi
callq 0x9030
movq %rax, 0x10(%rbx)
pushq $0x58
popq %rdi
callq 0x96c0
movq %rax, %r15
movl 0x14(%r14), %esi
movq %rax, %rdi
callq 0x9910
movq %r15, 0x20(%rbx)
movq %r15, %rdi
callq 0x9140
cmpl $-0x1, %eax
je 0xa5f1
movq 0x20(%rbx), %r14
movq (%r14), %rax
movq %r14, %rdi
callq *0x40(%rax)
movq %rbx, %rdi
movq %r14, %rsi
movl %eax, %edx
movl $0x2001, %ecx           # imm = 0x2001
callq 0x9b70
testl %eax, %eax
jne 0xa5c7
pushq $0x78
popq %rdi
callq 0x96c0
movq %rax, %r15
movq %rax, %rdi
movl $0x100, %esi            # imm = 0x100
callq 0x9b30
movq %r15, 0x28(%rbx)
movq %r15, %rdi
movq %rbx, %rsi
callq 0x9810
testl %eax, %eax
jne 0xa5f1
pushq $0x78
popq %rdi
callq 0x96c0
movq %rax, %r15
pushq $0x8
popq %rsi
movq %rax, %rdi
callq 0x93f0
movq %r15, 0x38(%rbx)
movq %r15, %rdi
movq %rbx, %rsi
callq 0x9240
testl %eax, %eax
jne 0xa5f1
xorl %ebp, %ebp
jmp 0xa5f9
movq 0x7a84(%rip), %rax      # 0x11fd0
movq (%rax), %rdi
leaq 0x3b11(%rip), %rsi      # 0xe067
jmp 0xa58f
movq 0x7a71(%rip), %rax      # 0x11fd0
movq (%rax), %rdi
leaq 0x3b20(%rip), %rsi      # 0xe089
jmp 0xa58f
movq 0x7a5e(%rip), %rax      # 0x11fd0
movq (%rax), %rdi
leaq 0x3b2e(%rip), %rsi      # 0xe0aa
jmp 0xa58f
movq 0x7a4b(%rip), %rax      # 0x11fd0
movq (%rax), %rdi
leaq 0x3b3e(%rip), %rsi      # 0xe0cd
xorl %eax, %eax
callq 0x9940
pushq $-0x1
popq %rbp
jmp 0xa5f9
movq 0x7a2e(%rip), %rax      # 0x11fd0
movq (%rax), %rbx
callq 0x9060
movl (%rax), %edi
callq 0x91d0
leaq 0x3b36(%rip), %rsi      # 0xe0ee
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x9940
jmp 0xa596
movq 0x7a02(%rip), %rax      # 0x11fd0
movq (%rax), %r14
callq 0x9060
movl (%rax), %edi
callq 0x91d0
leaq 0x3b2b(%rip), %rsi      # 0xe10f
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x9940
movq %rbx, %rdi
callq 0x9610
movl %ebp, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
jmp 0xa60a
jmp 0xa60a
jmp 0xa60a
movq %rax, %rbx
movq %r15, %rdi
callq 0x9690
movq %rbx, %rdi
callq 0x9aa0
nop