// File: /workspace/github_cpp_makefile_star2_O3/cybozu[P]yrmcds/src/server.cpp
// Function: yrmcds::server::serve_master()
void server::serve_master() {
    cybozu::logger::info() << "Entering master mode";

    for( auto& handler: m_handlers )
        handler->on_master_start();

    auto callback = [this](cybozu::reactor&) {
        std::time_t now = std::time(nullptr);
        g_current_time.store(now, std::memory_order_relaxed);

        if( ! m_syncer.empty() )
            m_syncer.check();
        for( auto& handler: m_handlers )
            handler->on_master_interval();

        if( reactor_gc_ready() ) {
            m_reactor.fix_garbage();
            m_syncer.add_request(
                std::unique_ptr<sync_request>(
                    new sync_request([this]{ m_reactor.gc(); })
                    ));
        }
    };

    for( unsigned int i = 0; i < g_config.workers(); ++i )
        m_workers.emplace_back(new cybozu::worker(WORKER_BUFSIZE));
    for( auto& w: m_workers )
        w->start();

    auto stop = [this] {
        m_reactor.invalidate();
        for( auto& w: m_workers )
            w->stop();
        for( auto& handler: m_handlers )
            handler->on_master_end();
    };

    try {
        cybozu::logger::info() << "Reactor thread id="
                               << std::this_thread::get_id();
        m_reactor.run(callback);
        cybozu::logger::info() << "Exiting";
    } catch( ... ) {
        stop();
        throw;
    }

    stop();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
leaq 0x371e6(%rip), %rax     # 0x46a88
movl (%rax), %eax
xorl %esi, %esi
cmpl $0x2, %eax
setge %sil
leaq 0x251a9(%rip), %rdx     # 0x34a5d
movq %rsp, %r14
movq %r14, %rdi
callq 0x96e6
cmpb $0x1, (%r14)
jne 0xf8db
movq 0x8(%rsp), %rdi
leaq 0x2515c(%rip), %rsi     # 0x34a2d
movl $0x14, %edx
callq 0x7570
movq %rsp, %rdi
callq 0x8f4e
movq 0x120(%rbx), %r14
movq 0x128(%rbx), %r15
cmpq %r15, %r14
je 0xf905
movq (%r14), %rdi
movq (%rdi), %rax
callq *0x20(%rax)
addq $0x8, %r14
jmp 0xf8f1
leaq 0x372b4(%rip), %rbp     # 0x46bc0
cmpl $0x0, 0x104(%rbp)
je 0xf95c
leaq 0xe0(%rbx), %r14
xorl %r13d, %r13d
movq %rsp, %r15
movl $0xc0, %edi
movl $0x40, %esi
callq 0x7530
movq %rax, %r12
movl $0x500000, %esi         # imm = 0x500000
movq %rax, %rdi
callq 0x101d4
movq %r12, (%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x1019c
incl %r13d
cmpl 0x104(%rbp), %r13d
jb 0xf922
movq 0xe0(%rbx), %r14
movq 0xe8(%rbx), %r15
cmpq %r15, %r14
je 0xf97d
movq (%r14), %rdi
callq 0x102ac
addq $0x8, %r14
jmp 0xf96a
leaq 0x37104(%rip), %r14     # 0x46a88
movl (%r14), %eax
xorl %esi, %esi
cmpl $0x2, %eax
setge %sil
leaq 0x250c6(%rip), %rdx     # 0x34a5d
movq %rsp, %rdi
callq 0x96e6
cmpb $0x1, (%rsp)
jne 0xf9bb
movq 0x8(%rsp), %rdi
leaq 0x25091(%rip), %rsi     # 0x34a42
movl $0x12, %edx
callq 0x7570
callq 0x7450
leaq 0x30(%rsp), %rsi
movq %rax, (%rsi)
movq %rsp, %rdi
callq 0x10334
movq %rsp, %rdi
callq 0x8f4e
leaq 0x8(%rbx), %rdi
leaq 0x10(%rsp), %rsi
movq $0x0, 0x8(%rsi)
movq %rbx, (%rsi)
leaq 0x533(%rip), %rax       # 0xff26
movq %rax, 0x18(%rsi)
leaq 0x6d6(%rip), %rax       # 0x100d4
movq %rax, 0x10(%rsi)
movl $0x1, %edx
callq 0xa418
movq 0x20(%rsp), %rax
testq %rax, %rax
je 0xfa25
leaq 0x10(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movl (%r14), %eax
xorl %esi, %esi
cmpl $0x2, %eax
setge %sil
leaq 0x25025(%rip), %rdx     # 0x34a5d
movq %rsp, %rdi
callq 0x96e6
cmpb $0x1, (%rsp)
jne 0xfa5c
movq 0x8(%rsp), %rdi
leaq 0x25003(%rip), %rsi     # 0x34a55
movl $0x7, %edx
callq 0x7570
movq %rsp, %rdi
callq 0x8f4e
movq 0x20(%rbx), %r14
testq %r14, %r14
je 0xfa8e
xorl %ebp, %ebp
movq 0x10(%r14), %rdi
movb $0x1, %al
lock
cmpxchgb %bpl, 0x10(%rdi)
jne 0xfa86
movl 0x50(%rdi), %esi
movq (%rdi), %rax
callq *0x10(%rax)
movq (%r14), %r14
testq %r14, %r14
jne 0xfa6f
movq 0xe0(%rbx), %r15
movq 0xe8(%rbx), %r12
cmpq %r12, %r15
je 0xfac8
movq (%r15), %r14
movb $0x1, 0x41(%r14)
movb $0x1, 0x40(%r14)
movq %r14, %rdi
callq 0x10486
addq $0x8, %r14
movq %r14, %rdi
callq 0x7950
addq $0x8, %r15
jmp 0xfa9c
movq 0x120(%rbx), %r14
movq 0x128(%rbx), %rbx
cmpq %rbx, %r14
je 0xfaea
movq (%r14), %rdi
movq (%rdi), %rax
callq *0x30(%rax)
addq $0x8, %r14
jmp 0xfad6
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xfb2e
jmp 0xfb2e
movq %rax, %rbx
movq %rsp, %rdi
callq 0x8f4e
jmp 0xfb75
jmp 0xfb5d
jmp 0xfb3b
movq %rax, %r14
movq 0x20(%rsp), %rax
testq %rax, %rax
je 0xfb3e
leaq 0x10(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0xfb3e
jmp 0xfb5d
movq %rax, %r14
movq %rsp, %rdi
callq 0x8f4e
jmp 0xfb3e
movq %rax, %r14
movq %r14, %rdi
callq 0x71a0
movq %rbx, %rdi
callq 0xfb7e
callq 0x77b0
movq %rax, %rbx
callq 0x78e0
jmp 0xfb75
movq %rax, %rdi
callq 0x8f80
movq %rax, %rbx
movl $0x40, %esi
movq %r12, %rdi
callq 0x7680
movq %rbx, %rdi
callq 0x79a0
nop