// File: shaovie[P]reactor/src/reactor.cpp
// Function: reactor::open(options const&)
int reactor::open(const options &opt) {
    if (opt.poller_num < 1) {
        fprintf(stderr, "reactor: poller_num=%d < 1\n", opt.poller_num);
        return -1;
    }
    this->poller_num = opt.poller_num;
    this->pollers = new poller[this->poller_num]();

    int cpu_num = std::thread::hardware_concurrency();
    for (int i = 0; i < this->poller_num; ++i) {
        if (opt.set_cpu_affinity) {
            int cpu_id = i % cpu_num;
            this->pollers[i].set_cpu_id(cpu_id);
        }
        if (this->pollers[i].open(opt) != 0) {
            return -1; // destroy ?
        }
    }
    if (opt.with_timer_shared == true) {
        this->timer = new timer_shared(opt.timer_init_size);
        if (this->timer->open() != 0)
            return -1; // destroy ?
        if (this->add_ev_handler(this->timer, this->timer->get_fd(), ev_handler::ev_read) != 0)
            return -1; // destroy ?
    }
    return 0;
}

// Assembly:
subq $0x78, %rsp
movq %rdi, 0x68(%rsp)
movq %rsi, 0x60(%rsp)
movq 0x68(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x60(%rsp), %rax
cmpl $0x1, 0x8(%rax)
jge 0x21050
movq 0x8fa6(%rip), %rax      # 0x29fd0
movq (%rax), %rdi
movq 0x60(%rsp), %rax
movl 0x8(%rax), %edx
leaq 0x2385(%rip), %rsi      # 0x233c1
movb $0x0, %al
callq 0x15860
movl $0xffffffff, 0x74(%rsp) # imm = 0xFFFFFFFF
jmp 0x2126f
movq 0x38(%rsp), %rax
movq 0x60(%rsp), %rcx
movl 0x8(%rcx), %ecx
movl %ecx, (%rax)
movslq (%rax), %rax
movq %rax, 0x28(%rsp)
movl $0x88, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
addq $0x8, %rdi
setb %al
orb %al, %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x14050
movq %rax, %rcx
movq 0x28(%rsp), %rax
movq %rax, (%rcx)
addq $0x8, %rcx
movq %rcx, 0x30(%rsp)
cmpq $0x0, %rax
je 0x21106
movq 0x30(%rsp), %rax
movq 0x28(%rsp), %rcx
imulq $0x88, %rcx, %rdx
movq %rax, %rcx
addq %rdx, %rcx
movq %rcx, 0x18(%rsp)
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rdi
movq %rdi, 0x10(%rsp)
xorl %esi, %esi
movl $0x88, %edx
callq 0x14900
movq 0x10(%rsp), %rdi
callq 0x145c0
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
addq $0x88, %rax
cmpq %rcx, %rax
movq %rax, 0x20(%rsp)
jne 0x210cc
movq 0x38(%rsp), %rax
movq 0x30(%rsp), %rcx
movq %rcx, 0x8(%rax)
callq 0x15710
movl %eax, 0x5c(%rsp)
movl $0x0, 0x58(%rsp)
movq 0x38(%rsp), %rcx
movl 0x58(%rsp), %eax
cmpl (%rcx), %eax
jge 0x211b0
movq 0x60(%rsp), %rax
testb $0x1, (%rax)
je 0x2116a
movl 0x58(%rsp), %eax
cltd
idivl 0x5c(%rsp)
movq 0x38(%rsp), %rax
movl %edx, 0x54(%rsp)
movq 0x8(%rax), %rdi
movslq 0x58(%rsp), %rax
imulq $0x88, %rax, %rax
addq %rax, %rdi
movl 0x54(%rsp), %esi
callq 0x159e0
movq 0x38(%rsp), %rax
movq 0x8(%rax), %rdi
movslq 0x58(%rsp), %rax
imulq $0x88, %rax, %rax
addq %rax, %rdi
movq 0x60(%rsp), %rsi
callq 0x14da0
cmpl $0x0, %eax
je 0x2119e
movl $0xffffffff, 0x74(%rsp) # imm = 0xFFFFFFFF
jmp 0x2126f
jmp 0x211a0
movl 0x58(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x58(%rsp)
jmp 0x21125
movq 0x60(%rsp), %rax
movb 0x1(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x21267
movl $0x80, %edi
callq 0x15120
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x8(%rsp)
movq 0x60(%rsp), %rax
movl 0x14(%rax), %esi
callq 0x14f10
jmp 0x211ea
movq 0x38(%rsp), %rax
movq 0x8(%rsp), %rcx
movq %rcx, 0x10(%rax)
movq 0x10(%rax), %rdi
callq 0x14300
cmpl $0x0, %eax
je 0x2122a
movl $0xffffffff, 0x74(%rsp) # imm = 0xFFFFFFFF
jmp 0x2126f
movq 0x8(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x48(%rsp)
movl %eax, 0x44(%rsp)
callq 0x15060
jmp 0x21278
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rcx
movq %rcx, (%rsp)
movq 0x10(%rax), %rdi
movq (%rdi), %rax
callq *0x40(%rax)
movq 0x38(%rsp), %rdi
movq (%rsp), %rsi
movl %eax, %edx
movl $0x2001, %ecx           # imm = 0x2001
callq 0x15740
cmpl $0x0, %eax
je 0x21265
movl $0xffffffff, 0x74(%rsp) # imm = 0xFFFFFFFF
jmp 0x2126f
jmp 0x21267
movl $0x0, 0x74(%rsp)
movl 0x74(%rsp), %eax
addq $0x78, %rsp
retq
movq 0x48(%rsp), %rdi
callq 0x15ce0
nopw %cs:(%rax,%rax)