// File: /workspace/github_cpp_makefile_star2_O1/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 $0x48, %rsp
movq %rdi, %rbx
leaq 0x37196(%rip), %rax     # 0x46a98
movl (%rax), %eax
xorl %esi, %esi
cmpl $0x2, %eax
setge %sil
leaq 0x25105(%rip), %rdx     # 0x34a19
leaq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x9718
cmpb $0x1, (%r14)
jne 0xf93d
movq 0x10(%rsp), %rdi
leaq 0x250b6(%rip), %rsi     # 0x349e9
movl $0x14, %edx
callq 0x7580
leaq 0x8(%rsp), %rdi
callq 0x8f94
movq 0x120(%rbx), %r14
movq 0x128(%rbx), %r15
cmpq %r15, %r14
je 0xf969
movq (%r14), %rdi
movq (%rdi), %rax
callq *0x20(%rax)
addq $0x8, %r14
jmp 0xf955
leaq 0x37250(%rip), %rbp     # 0x46bc0
cmpl $0x0, 0x104(%rbp)
je 0xf9c3
leaq 0xe0(%rbx), %r14
xorl %r13d, %r13d
leaq 0x8(%rsp), %r15
movl $0xc0, %edi
movl $0x40, %esi
callq 0x7540
movq %rax, %r12
movl $0x500000, %esi         # imm = 0x500000
movq %rax, %rdi
callq 0x1023c
movq %r12, 0x8(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x1020c
incl %r13d
cmpl 0x104(%rbp), %r13d
jb 0xf988
movq 0xe0(%rbx), %r14
movq 0xe8(%rbx), %r15
cmpq %r15, %r14
je 0xf9e4
movq (%r14), %rdi
callq 0x10312
addq $0x8, %r14
jmp 0xf9d1
movq %rbx, 0x18(%rsp)
leaq 0x370a8(%rip), %r14     # 0x46a98
movl (%r14), %eax
xorl %esi, %esi
cmpl $0x2, %eax
setge %sil
leaq 0x25016(%rip), %rdx     # 0x34a19
leaq 0x8(%rsp), %rdi
callq 0x9718
cmpb $0x1, 0x8(%rsp)
jne 0xfa2a
movq 0x10(%rsp), %rdi
leaq 0x24fde(%rip), %rsi     # 0x349fe
movl $0x12, %edx
callq 0x7580
callq 0x7460
leaq 0x40(%rsp), %rsi
movq %rax, (%rsi)
leaq 0x8(%rsp), %rdi
callq 0x1039a
leaq 0x8(%rsp), %rdi
callq 0x8f94
leaq 0x8(%rbx), %rdi
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %rsi
movaps %xmm0, (%rsi)
movaps %xmm0, 0x10(%rsi)
movq %rbx, (%rsi)
leaq 0x53c(%rip), %rax       # 0xffa4
movq %rax, 0x18(%rsi)
leaq 0x6e1(%rip), %rax       # 0x10154
movq %rax, 0x10(%rsi)
movl $0x1, %edx
callq 0xa43c
movq 0x30(%rsp), %rax
testq %rax, %rax
je 0xfa9a
leaq 0x20(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movl (%r14), %eax
xorl %esi, %esi
cmpl $0x2, %eax
setge %sil
leaq 0x24f6c(%rip), %rdx     # 0x34a19
leaq 0x8(%rsp), %rdi
callq 0x9718
cmpb $0x1, 0x8(%rsp)
jne 0xfad4
movq 0x10(%rsp), %rdi
leaq 0x24f47(%rip), %rsi     # 0x34a11
movl $0x7, %edx
callq 0x7580
leaq 0x8(%rsp), %rdi
callq 0x8f94
movq 0x20(%rbx), %r14
testq %r14, %r14
je 0xfb08
xorl %ebp, %ebp
movq 0x10(%r14), %rdi
movb $0x1, %al
lock
cmpxchgb %bpl, 0x10(%rdi)
jne 0xfb00
movl 0x50(%rdi), %esi
movq (%rdi), %rax
callq *0x10(%rax)
movq (%r14), %r14
testq %r14, %r14
jne 0xfae9
movq 0xe0(%rbx), %r15
movq 0xe8(%rbx), %r12
cmpq %r12, %r15
je 0xfb42
movq (%r15), %r14
movb $0x1, 0x41(%r14)
movb $0x1, 0x40(%r14)
movq %r14, %rdi
callq 0x104fc
addq $0x8, %r14
movq %r14, %rdi
callq 0x7960
addq $0x8, %r15
jmp 0xfb16
movq 0x120(%rbx), %r14
movq 0x128(%rbx), %rbx
cmpq %rbx, %r14
je 0xfb64
movq (%r14), %rdi
movq (%rdi), %rax
callq *0x30(%rax)
addq $0x8, %r14
jmp 0xfb50
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xfbaa
jmp 0xfbaa
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x8f94
jmp 0xfbf5
jmp 0xfbdd
jmp 0xfbb9
movq %rax, %rbx
movq 0x30(%rsp), %rax
testq %rax, %rax
je 0xfbbc
leaq 0x20(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0xfbbc
jmp 0xfbdd
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x8f94
jmp 0xfbbc
movq %rax, %rbx
movq %rbx, %rdi
callq 0x71a0
leaq 0x18(%rsp), %rdi
callq 0xfbfe
callq 0x77c0
movq %rax, %rbx
callq 0x78f0
jmp 0xfbf5
movq %rax, %rdi
callq 0x8fc6
movq %rax, %rbx
movl $0x40, %esi
movq %r12, %rdi
callq 0x7690
movq %rbx, %rdi
callq 0x79b0
nop