// File: /workspace/github_cpp_makefile_star2_O2/theuni[P]libbtcnet/src/handler.cpp
// Function: CConnectionHandlerInt::Start(int)
void CConnectionHandlerInt::Start(int outgoing_limit)
{
    int result = 0;
    m_shutdown = false;

#ifndef NO_THREADS
    if (m_enable_threading)
        m_main_thread = std::this_thread::get_id();
#endif

    assert(m_outgoing_conn_count == 0);
    assert(m_incoming_conn_count == 0);
    assert(!m_event_base);
    assert(!m_dns_base);
    assert(!m_request_event);
    assert(!m_shutdown_event);

    m_outgoing_conn_limit = outgoing_limit;

    event_type<event_config> cfg(event_config_new());
    result = event_config_set_flag(cfg, EVENT_BASE_FLAG_EPOLL_USE_CHANGELIST);
    assert(result == 0);
    (void)result;

    m_event_base = event_base_new_with_config(cfg);

    if (m_enable_threading) {
        result = enable_threads_for_handler(m_event_base);
        assert(result == 0);
        (void)result;
    }
    cfg.free();

    m_dns_base = evdns_base_new(m_event_base, 1);
    result = evdns_base_set_option(m_dns_base, "randomize-case", "0");
    assert(result == 0);
    (void)result;

    event_base_priority_init(m_event_base, 3);

    m_request_event.reset(m_event_base, -1, EV_PERSIST, std::bind(&CConnectionHandlerInt::RequestOutgoingInt, this));
    m_shutdown_event.reset(m_event_base, -1, 0, std::bind(&CConnectionHandlerInt::ShutdownInt, this));

    m_shutdown_event.priority_set(0);

    m_outgoing_rate_cfg = ev_token_bucket_cfg_new(EV_RATE_LIMIT_MAX, EV_RATE_LIMIT_MAX, EV_RATE_LIMIT_MAX, EV_RATE_LIMIT_MAX, nullptr);
    m_incoming_rate_cfg = ev_token_bucket_cfg_new(EV_RATE_LIMIT_MAX, EV_RATE_LIMIT_MAX, EV_RATE_LIMIT_MAX, EV_RATE_LIMIT_MAX, nullptr);

    m_outgoing_rate_limit = bufferevent_rate_limit_group_new(m_event_base, m_outgoing_rate_cfg);
    m_incoming_rate_limit = bufferevent_rate_limit_group_new(m_event_base, m_incoming_rate_cfg);

    timeval request_timeout = {0, 500000};
    m_request_event.add(&request_timeout);
    m_interface.OnStartup();

    m_request_event.active();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %esi, %ebp
movq %rdi, %rbx
movb $0x0, 0xed(%rdi)
cmpb $0x1, 0xec(%rdi)
jne 0x77b3
callq 0x4320
movq %rax, 0x168(%rbx)
cmpl $0x0, 0xe0(%rbx)
jne 0x7a83
cmpl $0x0, 0xe4(%rbx)
jne 0x7a9f
cmpq $0x0, 0x190(%rbx)
jne 0x7abb
cmpq $0x0, 0x198(%rbx)
jne 0x7ad7
leaq 0x1a0(%rbx), %r14
movq %r14, %rdi
callq 0xf87e
testb %al, %al
jne 0x7af0
leaq 0x1c8(%rbx), %r12
movq %r12, %rdi
callq 0xf87e
testb %al, %al
jne 0x7b09
movl %ebp, 0xe8(%rbx)
callq 0x45f0
leaq 0x8(%rsp), %r15
movq %r15, %rdi
movq %rax, %rsi
callq 0x945c
movq %r15, %rdi
callq 0x9484
pushq $0x10
popq %rsi
movq %rax, %rdi
callq 0x4650
testl %eax, %eax
jne 0x7b22
leaq 0x8(%rsp), %rdi
callq 0x9484
movq %rax, %rdi
callq 0x44c0
leaq 0x190(%rbx), %r15
movq %r15, %rdi
movq %rax, %rsi
callq 0x94ac
cmpb $0x1, 0xec(%rbx)
jne 0x7892
movq %r15, %rdi
callq 0x9504
movq %rax, %rdi
callq 0x46b0
testl %eax, %eax
jne 0x7b54
leaq 0x8(%rsp), %rdi
callq 0x94ec
movq %r15, %rdi
callq 0x9504
pushq $0x1
popq %rsi
movq %rax, %rdi
callq 0x4730
leaq 0x198(%rbx), %r13
movq %r13, %rdi
movq %rax, %rsi
callq 0x952c
movq %r13, %rdi
callq 0x956c
leaq 0x903a(%rip), %rsi      # 0x1090a
leaq 0x9fff(%rip), %rdx      # 0x118d6
movq %rax, %rdi
callq 0x4250
testl %eax, %eax
jne 0x7b3b
movq %r15, %rdi
callq 0x9504
pushq $0x3
popq %rsi
movq %rax, %rdi
callq 0x45c0
leaq 0x29d(%rip), %rax       # 0x7b9e
leaq 0x30(%rsp), %rsi
movq %rax, (%rsi)
andq $0x0, 0x8(%rsi)
movq %rbx, 0x10(%rsi)
leaq 0x10(%rsp), %rdi
callq 0x9594
pushq $-0x1
popq %rdx
pushq $0x10
popq %rcx
leaq 0x10(%rsp), %r8
movq %r14, %rdi
movq %r15, %rsi
callq 0xf798
leaq 0x10(%rsp), %rdi
callq 0x95dc
leaq 0x335(%rip), %rax       # 0x7c78
leaq 0x30(%rsp), %rsi
movq %rax, (%rsi)
andq $0x0, 0x8(%rsi)
movq %rbx, 0x10(%rsi)
leaq 0x10(%rsp), %rdi
callq 0x9594
pushq $-0x1
popq %rdx
leaq 0x10(%rsp), %r8
movq %r12, %rdi
movq %r15, %rsi
xorl %ecx, %ecx
callq 0xf798
leaq 0x10(%rsp), %rdi
callq 0x95dc
movq %r12, %rdi
xorl %esi, %esi
callq 0xf912
movabsq $0x7fffffffffffffff, %rcx # imm = 0x7FFFFFFFFFFFFFFF
movq %rcx, %rdi
movq %rcx, %rsi
movq %rcx, %rdx
xorl %r8d, %r8d
callq 0x45a0
leaq 0x178(%rbx), %r13
movq %r13, %rdi
movq %rax, %rsi
callq 0x95f8
movabsq $0x7fffffffffffffff, %rcx # imm = 0x7FFFFFFFFFFFFFFF
movq %rcx, %rdi
movq %rcx, %rsi
movq %rcx, %rdx
xorl %r8d, %r8d
callq 0x45a0
leaq 0x170(%rbx), %r12
movq %r12, %rdi
movq %rax, %rsi
callq 0x95f8
movq %r15, %rdi
callq 0x9504
movq %rax, %rbp
movq %r13, %rdi
callq 0x9638
movq %rbp, %rdi
movq %rax, %rsi
callq 0x4200
leaq 0x188(%rbx), %rdi
movq %rax, %rsi
callq 0x9660
movq %r15, %rdi
callq 0x9504
movq %rax, %r15
movq %r12, %rdi
callq 0x9638
movq %r15, %rdi
movq %rax, %rsi
callq 0x4200
leaq 0x180(%rbx), %rdi
movq %rax, %rsi
callq 0x9660
movups 0x98de(%rip), %xmm0     # 0x11320
leaq 0x10(%rsp), %rsi
movaps %xmm0, (%rsi)
movq %r14, %rdi
callq 0xf8f0
movq 0xc0(%rbx), %rdi
movq (%rdi), %rax
callq *0xa0(%rax)
movq %r14, %rdi
callq 0xf8d0
leaq 0x8(%rsp), %rdi
callq 0x96a0
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x8dda(%rip), %rdi      # 0x10864
leaq 0x8d7a(%rip), %rsi      # 0x1080b
leaq 0x8de7(%rip), %rcx      # 0x1087f
pushq $0x35
jmp 0x7b6b
leaq 0x8e00(%rip), %rdi      # 0x108a6
leaq 0x8d5e(%rip), %rsi      # 0x1080b
leaq 0x8dcb(%rip), %rcx      # 0x1087f
pushq $0x36
jmp 0x7b6b
leaq 0x8dff(%rip), %rdi      # 0x108c1
leaq 0x8d42(%rip), %rsi      # 0x1080b
leaq 0x8daf(%rip), %rcx      # 0x1087f
pushq $0x37
jmp 0x7b6b
leaq 0x8df1(%rip), %rdi      # 0x108cf
leaq 0x8d26(%rip), %rsi      # 0x1080b
leaq 0x8d93(%rip), %rcx      # 0x1087f
pushq $0x38
jmp 0x7b6b
leaq 0x8de4(%rip), %rdi      # 0x108db
leaq 0x8d0d(%rip), %rsi      # 0x1080b
leaq 0x8d7a(%rip), %rcx      # 0x1087f
pushq $0x39
jmp 0x7b6b
leaq 0x8ddc(%rip), %rdi      # 0x108ec
leaq 0x8cf4(%rip), %rsi      # 0x1080b
leaq 0x8d61(%rip), %rcx      # 0x1087f
pushq $0x3a
jmp 0x7b6b
leaq 0x8dd5(%rip), %rdi      # 0x108fe
leaq 0x8cdb(%rip), %rsi      # 0x1080b
leaq 0x8d48(%rip), %rcx      # 0x1087f
pushq $0x40
jmp 0x7b6b
leaq 0x8dbc(%rip), %rdi      # 0x108fe
leaq 0x8cc2(%rip), %rsi      # 0x1080b
leaq 0x8d2f(%rip), %rcx      # 0x1087f
pushq $0x4e
jmp 0x7b6b
leaq 0x8da3(%rip), %rdi      # 0x108fe
leaq 0x8ca9(%rip), %rsi      # 0x1080b
leaq 0x8d16(%rip), %rcx      # 0x1087f
pushq $0x47
popq %rdx
callq 0x4260
jmp 0x7b75
jmp 0x7b88
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x95dc
jmp 0x7b8b
jmp 0x7b88
jmp 0x7b88
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x96a0
movq %rbx, %rdi
callq 0x4660
nop