// File: /workspace/github_cpp_makefile_star2_O3/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 %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movl 0x4(%rsi), %edx
testl %edx, %edx
jle 0x7797
movq %rsi, %r14
movl 0x14(%rsi), %edx
testl %edx, %edx
jle 0x77aa
movl 0xc(%r14), %edx
testl %edx, %edx
jle 0x77bd
movl 0x10(%r14), %edx
testl %edx, %edx
jle 0x77d0
movq %rdi, %rbx
movl $0x80000, %edi          # imm = 0x80000
callq 0x6580
cmpl $-0x1, %eax
je 0x77f9
movl %eax, 0x4(%rbx)
movl $0x70, %edi
callq 0x6490
movq %rax, %r15
movl 0x10(%r14), %esi
movq %rax, %rdi
callq 0x67a0
movq %r15, 0x30(%rbx)
movslq 0x4(%rbx), %rcx
movabsq $0x200000005, %rdx      # imm = 0x200000005
movq %rcx, %rax
mulq %rdx
movq %rcx, %rax
subq %rdx, %rax
shrq %rax
addq %rdx, %rax
shrq $0x1e, %rax
movq %rax, %rdx
shlq $0x1f, %rdx
subq %rdx, %rax
leaq (%rcx,%rax), %rdx
cmpq $0x1, %rdx
adcq %rcx, %rax
imulq $0x41a7, %rax, %rcx     # imm = 0x41A7
movabsq $0x400000008001, %rdx   # imm = 0x400000008001
movq %rcx, %rax
mulq %rdx
shrl $0xd, %edx
movq %rdx, %rax
shlq $0x1f, %rax
subq %rax, %rdx
addq %rcx, %rdx
movq %rdx, 0x48(%rbx)
movslq 0xc(%r14), %rax
movl %eax, 0x8(%rbx)
movl $0xc, %ecx
mulq %rcx
movq $-0x1, %r15
cmovnoq %rax, %r15
movq %r15, %rdi
callq 0x6030
movq %rax, %r12
movq %rax, %rdi
xorl %esi, %esi
movq %r15, %rdx
callq 0x62a0
movq %r12, 0x18(%rbx)
movl 0x4(%r14), %eax
movl %eax, 0xc(%rbx)
testl %eax, %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmovnsl %eax, %ecx
movslq %ecx, %rdi
callq 0x6030
movq %rax, 0x10(%rbx)
movl $0x58, %edi
callq 0x6490
movq %rax, %r15
movl 0x14(%r14), %esi
movq %rax, %rdi
callq 0x65f0
movq %r15, 0x20(%rbx)
movq %r15, %rdi
callq 0x60d0
cmpl $-0x1, %eax
je 0x7789
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 0x67e0
testl %eax, %eax
jne 0x7800
movl $0x78, %edi
callq 0x6490
movq %rax, %r15
movq %rax, %rdi
movl $0x100, %esi            # imm = 0x100
callq 0x67c0
movq %r15, 0x28(%rbx)
movq %r15, %rdi
movq %rbx, %rsi
callq 0x6550
testl %eax, %eax
jne 0x7789
movl $0x78, %edi
callq 0x6490
movq %rax, %r15
movq %rax, %rdi
movl $0x8, %esi
callq 0x62d0
movq %r15, 0x38(%rbx)
movq %r15, %rdi
movq %rbx, %rsi
callq 0x6170
testl %eax, %eax
je 0x7793
movq %rbx, %rdi
callq 0x6420
jmp 0x77e8
xorl %eax, %eax
jmp 0x77ed
movq 0x783a(%rip), %rax      # 0xefd8
movq (%rax), %rdi
leaq 0x38bf(%rip), %rsi      # 0xb067
jmp 0x77e1
movq 0x7827(%rip), %rax      # 0xefd8
movq (%rax), %rdi
leaq 0x38ce(%rip), %rsi      # 0xb089
jmp 0x77e1
movq 0x7814(%rip), %rax      # 0xefd8
movq (%rax), %rdi
leaq 0x38dc(%rip), %rsi      # 0xb0aa
jmp 0x77e1
movq 0x7801(%rip), %rax      # 0xefd8
movq (%rax), %rdi
leaq 0x38ec(%rip), %rsi      # 0xb0cd
xorl %eax, %eax
callq 0x6620
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
callq 0x6a10
jmp 0x77e8
movq %rbx, %rdi
callq 0x69d0
jmp 0x77e8
jmp 0x7810
jmp 0x7810
jmp 0x7810
movq %rax, %rbx
movq %r15, %rdi
callq 0x6470
movq %rbx, %rdi
callq 0x6740
nop