// File: /workspace/github_cpp_makefile_star2_O3/cybozu[P]yrmcds/src/main.cpp
// Function: main
int main(int argc, char** argv) {
    std::vector<std::string> args;
    for( int i = 1; i < argc; ++i )
        args.push_back(argv[i]);

    if( std::find(args.begin(), args.end(), "-h") != args.end() ) {
        print_help();
        return 0;
    }

    if( std::find(args.begin(), args.end(), "-v") != args.end() ) {
        print_version();
        return 0;
    }

    using cybozu::logger;

    seed_siphash();

    try {
        if( ! load_config(args) )
            return 1;

        if( yrmcds::g_config.lock_memory() ) {
            if( ::mlockall( MCL_CURRENT | MCL_FUTURE ) == -1 )
                cybozu::throw_unix_error(errno, "mlockall");
        }

        // first, set group id (as root)
        const std::string& g = yrmcds::g_config.group();
        if( ! g.empty() ) {
            if( getuid() != 0 ) {
                std::cerr << "Ignored group configuration." << std::endl;
            } else {
                struct group* grp = getgrnam(g.c_str());
                if( grp == nullptr ) {
                    std::cerr << "No such group: " << g << std::endl;
                    return 1;
                }
                if( setgid(grp->gr_gid) == -1 ) {
                    std::cerr << "Failed to set group id!" << std::endl;
                    return 1;
                }
            }
        }

        const std::string& u = yrmcds::g_config.user();
        if( ! u.empty() ) {
            if( getuid() != 0 ) {
                std::cerr << "Ignored user configuration." << std::endl;
            } else {
                struct passwd* p = getpwnam(u.c_str());
                if( p == nullptr ) {
                    std::cerr << "No such user: " << u << std::endl;
                    return 1;
                }
                if( setuid(p->pw_uid) == -1 ) {
                    std::cerr << "Failed to set user id!" << std::endl;
                    return 1;
                }
            }
        }

        // make it core dumpable
        if( prctl(PR_SET_DUMPABLE, 1) == -1 ) {
            std::cerr << "WARNING: failed to enable core dump!" << std::endl;
        }

        // setup logger
        logger::set_threshold(yrmcds::g_config.threshold());
        if( ! yrmcds::g_config.logfile().empty() )
            logger::instance().open(yrmcds::g_config.logfile());

        yrmcds::server().serve();

    } catch( const std::system_error& e ) {
        cybozu::demangler t( typeid(e).name() );
        logger::error() << "[" << t.name() << "] (" << e.code() << ") "
                        << e.what();
        std::cerr << "Exception [" << t.name() << "] (" << e.code() << ") "
                  << e.what() << std::endl;
        return 1;

    } catch( const std::exception& e ) {
        cybozu::demangler t( typeid(e).name() );
        logger::error() << "[" << t.name() << "] " << e.what();
        std::cerr << "Exception [" << t.name() << "] " << e.what() << std::endl;
        return 1;
    }

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x13e8, %rsp           # imm = 0x13E8
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
cmpl $0x2, %edi
jl 0x8327
movq %rsi, %rbx
movl %edi, %ebp
movl $0x1, %r13d
leaq 0x60(%rsp), %r14
leaq 0x30(%rsp), %r15
leaq 0x10(%rsp), %r12
movq (%rbx,%r13,8), %rsi
movq %r14, %rdi
movq %r15, %rdx
callq 0x8d50
movq %r12, %rdi
movq %r14, %rsi
callq 0x97f6
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x8313
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x7500
incq %r13
cmpq %r13, %rbp
jne 0x82dd
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
jmp 0x832b
xorl %esi, %esi
xorl %edi, %edi
leaq 0x2bcd2(%rip), %rdx     # 0x34004
callq 0x9a65
movq 0x18(%rsp), %rsi
cmpq %rsi, %rax
je 0x838c
movq 0x3dc50(%rip), %rbx     # 0x45f98
leaq 0x2bd86(%rip), %rsi     # 0x340d5
movl $0x22, %edx
movq %rbx, %rdi
callq 0x7570
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x74d0
movsbl %al, %esi
movq 0x3dc1e(%rip), %rdi     # 0x45f98
callq 0x7030
movq %rax, %rdi
callq 0x7340
jmp 0x87ef
movq 0x10(%rsp), %rdi
leaq 0x2bc6f(%rip), %rdx     # 0x34007
callq 0x9a65
cmpq 0x18(%rsp), %rax
je 0x843d
movq 0x3dbe9(%rip), %rbx     # 0x45f98
leaq 0x2be5a(%rip), %rsi     # 0x34210
movl $0x15, %edx
movq %rbx, %rdi
callq 0x7570
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x74d0
movsbl %al, %esi
movq 0x3dbb7(%rip), %rdi     # 0x45f98
callq 0x7030
movq %rax, %rdi
callq 0x7340
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x74d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x7030
movq %rax, %rdi
callq 0x7340
movq %rax, %rbx
leaq 0x3e13e(%rip), %r14     # 0x46560
movq %r14, %rdi
callq 0x71b0
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x7570
jmp 0x87ef
leaq 0x60(%rsp), %rdi
callq 0x9098
movq %rsp, %rdi
movq $0x0, (%rdi)
movq $-0x1, 0x8(%rdi)
leaq 0x60(%rsp), %rsi
movq %rdi, %rdx
callq 0x9112
movq %rax, 0x30(%rsp)
leaq 0x60(%rsp), %rsi
movq %rsp, %rdi
movq %rdi, %rdx
callq 0x9112
leaq 0x30(%rsp), %rdi
movq %rax, 0x8(%rdi)
callq 0xb80c
leaq 0x60(%rsp), %rdi
callq 0x74a0
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
leaq 0x2bc73(%rip), %rdx     # 0x34117
callq 0x91fe
movq 0x18(%rsp), %rcx
cmpq %rcx, %rax
je 0x84d4
addq $0x20, %rax
cmpq %rcx, %rax
je 0x880f
leaq 0x3e6f9(%rip), %rdi     # 0x46bc0
movq %rax, %rsi
callq 0xc4fc
jmp 0x855c
leaq 0x40(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x58(%rsp), %rsi
movq $0x1a, (%rsi)
leaq 0x30(%rsp), %rdi
xorl %edx, %edx
callq 0x79d0
leaq 0x30(%rsp), %rdi
movq %rax, (%rdi)
movq 0x58(%rsp), %rcx
movq %rcx, 0x10(%rdi)
movups 0x2bc17(%rip), %xmm0    # 0x34124
movups %xmm0, 0xa(%rax)
movups 0x2bc02(%rip), %xmm0    # 0x3411a
movups %xmm0, (%rax)
movq %rcx, 0x8(%rdi)
movq (%rdi), %rax
movb $0x0, (%rax,%rcx)
leaq 0x60(%rsp), %rsi
callq 0x9b58
testb %al, %al
je 0x8545
leaq 0x3e685(%rip), %rdi     # 0x46bc0
leaq 0x30(%rsp), %rsi
callq 0xc4fc
movq 0x30(%rsp), %rdi
cmpq %r15, %rdi
je 0x855c
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x7500
leaq 0x3e65d(%rip), %r14     # 0x46bc0
cmpb $0x1, 0x100(%r14)
jne 0x8647
movq 0xd8(%r14), %rax
cmpq 0xe0(%r14), %rax
jbe 0x8647
movq 0x3da5c(%rip), %rbx     # 0x45fe8
leaq 0x2bba2(%rip), %rsi     # 0x34135
movl $0x9, %edx
movq %rbx, %rdi
callq 0x7570
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x74d0
movsbl %al, %esi
movq 0x3da2a(%rip), %rdi     # 0x45fe8
callq 0x7030
movq %rax, %rdi
callq 0x7340
movq %rax, %rbx
leaq 0x2bb6a(%rip), %rsi     # 0x3413f
movl $0x46, %edx
movq %rax, %rdi
callq 0x7570
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x74d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x7030
movq %rax, %rdi
callq 0x7340
movq %rax, %rbx
leaq 0x2bb73(%rip), %rsi     # 0x34186
movl $0x3f, %edx
movq %rax, %rdi
callq 0x7570
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x74d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x7030
movq %rax, %rdi
callq 0x7340
cmpb $0x1, 0x101(%r14)
jne 0x8664
movl $0x3, %edi
callq 0x7970
cmpl $-0x1, %eax
je 0x895f
cmpq $0x0, 0x90(%r14)
je 0x86c1
callq 0x7230
testl %eax, %eax
je 0x885c
movq 0x3d966(%rip), %rbx     # 0x45fe8
leaq 0x2b98a(%rip), %rsi     # 0x34013
movl $0x1c, %edx
movq %rbx, %rdi
callq 0x7570
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x74d0
movsbl %al, %esi
movq 0x3d934(%rip), %rdi     # 0x45fe8
callq 0x7030
movq %rax, %rdi
callq 0x7340
cmpq $0x0, 0x70(%r14)
je 0x871b
callq 0x7230
testl %eax, %eax
je 0x889b
movq 0x3d90c(%rip), %rbx     # 0x45fe8
leaq 0x2b975(%rip), %rsi     # 0x34058
movl $0x1b, %edx
movq %rbx, %rdi
callq 0x7570
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x74d0
movsbl %al, %esi
movq 0x3d8da(%rip), %rdi     # 0x45fe8
callq 0x7030
movq %rax, %rdi
callq 0x7340
movl $0x4, %edi
movl $0x1, %esi
xorl %eax, %eax
callq 0x7650
cmpl $-0x1, %eax
jne 0x8777
movq 0x3d8b0(%rip), %rbx     # 0x45fe8
leaq 0x2b95b(%rip), %rsi     # 0x3409a
movl $0x24, %edx
movq %rbx, %rdi
callq 0x7570
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x74d0
movsbl %al, %esi
movq 0x3d87e(%rip), %rdi     # 0x45fe8
callq 0x7030
movq %rax, %rdi
callq 0x7340
movl 0xa8(%r14), %eax
leaq 0x3e303(%rip), %rcx     # 0x46a88
movl %eax, (%rcx)
cmpq $0x0, 0xb8(%r14)
je 0x87aa
callq 0x8de6
movl $0xb0, %esi
addq 0x3d7be(%rip), %rsi     # 0x45f60
movq %rax, %rdi
callq 0x8e04
leaq 0x60(%rsp), %rdi
callq 0xf25c
leaq 0x60(%rsp), %rdi
callq 0xf45c
leaq 0x180(%rsp), %rdi
callq 0x9510
leaq 0x168(%rsp), %rdi
callq 0x9594
leaq 0x140(%rsp), %rdi
callq 0x9564
leaq 0x68(%rsp), %rdi
callq 0xa284
xorl %ebx, %ebx
leaq 0x10(%rsp), %rdi
callq 0x903a
movl %ebx, %eax
addq $0x13e8, %rsp           # imm = 0x13E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x3d7d2(%rip), %rbx     # 0x45fe8
leaq 0x2b8e3(%rip), %rsi     # 0x34100
movl $0x19, %edx
movq %rbx, %rdi
callq 0x7570
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x74d0
movsbl %al, %esi
movq 0x3d7a0(%rip), %rdi     # 0x45fe8
callq 0x7030
movl $0x1, %ebx
movq %rax, %rdi
callq 0x7340
jmp 0x87f1
movq 0x88(%r14), %rdi
callq 0x74b0
testq %rax, %rax
je 0x88d7
movl 0x10(%rax), %edi
callq 0x79b0
cmpl $-0x1, %eax
jne 0x86c1
movq 0x3d763(%rip), %r14     # 0x45fe8
leaq 0x2b7b4(%rip), %rsi     # 0x34040
movl $0x17, %edx
movq %r14, %rdi
callq 0x7570
jmp 0x890c
movq 0x68(%r14), %rdi
callq 0x73e0
testq %rax, %rax
je 0x891e
movl 0x10(%rax), %edi
callq 0x7a40
cmpl $-0x1, %eax
jne 0x871b
movq 0x3d727(%rip), %r14     # 0x45fe8
leaq 0x2b7bb(%rip), %rsi     # 0x34083
movl $0x16, %edx
movq %r14, %rdi
callq 0x7570
jmp 0x894d
movq 0x3d70a(%rip), %rdi     # 0x45fe8
leaq 0x2b74b(%rip), %rsi     # 0x34030
movl $0xf, %edx
callq 0x7570
movq 0x88(%r14), %rsi
movq 0x90(%r14), %rdx
movq 0x3d6e4(%rip), %rdi     # 0x45fe8
callq 0x7570
movq %rax, %r14
movl $0x1, %ebx
movq %r14, %rdi
callq 0x7200
jmp 0x87f1
movq 0x3d6c3(%rip), %rdi     # 0x45fe8
leaq 0x2b748(%rip), %rsi     # 0x34074
movl $0xe, %edx
callq 0x7570
movq 0x68(%r14), %rsi
movq 0x70(%r14), %rdx
movq 0x3d6a3(%rip), %rdi     # 0x45fe8
callq 0x7570
movq %rax, %r14
movl $0x1, %ebx
movq %r14, %rdi
callq 0x7200
jmp 0x87f1
callq 0x7040
movl (%rax), %edi
leaq 0x2b69d(%rip), %rsi     # 0x3400a
callq 0x8d8d
jmp 0x89ce
jmp 0x89ce
movq %rdx, %r14
movq %rax, %rbx
movq 0x30(%rsp), %rdi
cmpq %r15, %rdi
je 0x89d4
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x7500
jmp 0x89d4
movq %rdx, %r14
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x8e5e
jmp 0x89d4
jmp 0x89ce
jmp 0x89c6
jmp 0x89ce
jmp 0x89ce
jmp 0x8d19
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x74a0
jmp 0x8d3d
movq %rax, %rdi
callq 0x8f80
movq %rdx, %r14
movq %rax, %rbx
cmpl $0x3, %r14d
jne 0x8b58
movq %rbx, %rdi
callq 0x71a0
movq %rax, %rbx
movq (%rax), %rax
movq -0x8(%rax), %rax
movq 0x8(%rax), %rax
xorl %esi, %esi
cmpb $0x2a, (%rax)
sete %sil
addq %rax, %rsi
leaq 0x60(%rsp), %rdi
callq 0xba74
leaq 0x3e077(%rip), %rax     # 0x46a88
movl (%rax), %esi
notl %esi
shrl $0x1f, %esi
leaq 0x2b7a7(%rip), %rdx     # 0x341c6
movq %rsp, %rdi
callq 0x96e6
leaq 0x2b69e(%rip), %rsi     # 0x340cc
movq %rsp, %rdi
callq 0x8e94
movq %rax, %r14
cmpb $0x1, (%rax)
jne 0x8a51
movq 0x8(%r14), %rdi
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rdx
callq 0x7570
leaq 0x2b676(%rip), %rsi     # 0x340ce
movq %r14, %rdi
callq 0x8f8c
movq %rax, %r15
leaq 0x10(%rbx), %r14
cmpb $0x1, (%rax)
jne 0x8a78
movq 0x8(%r15), %rdi
movq %r14, %rsi
callq 0x8fbf
leaq 0x2b653(%rip), %rsi     # 0x340d2
movq %r15, %rdi
callq 0x8ec8
movq %rax, %r15
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
leaq 0x50(%rsp), %rsi
movq %rax, (%rsi)
movq %r15, %rdi
callq 0x8efc
movq %rsp, %rdi
callq 0x8f4e
movq 0x3d536(%rip), %rdi     # 0x45fe8
leaq 0x2b609(%rip), %rsi     # 0x340c2
movl $0xb, %edx
callq 0x7570
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rdx
movq 0x3d514(%rip), %rdi     # 0x45fe8
callq 0x7570
movq %rax, %r15
leaq 0x2b5eb(%rip), %rsi     # 0x340ce
movl $0x3, %edx
movq %rax, %rdi
callq 0x7570
movq %r15, %rdi
movq %r14, %rsi
callq 0x8fbf
movq %rax, %r14
leaq 0x2b5cd(%rip), %rsi     # 0x340d2
movl $0x2, %edx
movq %rax, %rdi
callq 0x7570
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movq %r14, %rdi
movq %rax, %rsi
callq 0x74e0
movq %rax, %rdi
callq 0x7200
leaq 0x70(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8b49
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x7500
movl $0x1, %ebx
callq 0x78e0
jmp 0x87f1
cmpl $0x2, %r14d
jne 0x8d3d
movq %rbx, %rdi
callq 0x71a0
movq %rax, %rbx
movq (%rax), %rax
movq -0x8(%rax), %rax
movq 0x8(%rax), %rax
xorl %esi, %esi
cmpb $0x2a, (%rax)
sete %sil
addq %rax, %rsi
leaq 0x60(%rsp), %rdi
callq 0xba74
leaq 0x3def3(%rip), %rax     # 0x46a88
movl (%rax), %esi
notl %esi
shrl $0x1f, %esi
leaq 0x2b623(%rip), %rdx     # 0x341c6
movq %rsp, %rdi
callq 0x96e6
leaq 0x2b51a(%rip), %rsi     # 0x340cc
movq %rsp, %rdi
callq 0x8e94
movq %rax, %r14
cmpb $0x1, (%rax)
jne 0x8bd5
movq 0x8(%r14), %rdi
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rdx
callq 0x7570
leaq 0x2b4e3(%rip), %rsi     # 0x340bf
movq %r14, %rdi
callq 0x8ec8
movq %rax, %r14
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
leaq 0x50(%rsp), %rsi
movq %rax, (%rsi)
movq %r14, %rdi
callq 0x8efc
movq %rsp, %rdi
callq 0x8f4e
movq 0x3d3d9(%rip), %rdi     # 0x45fe8
leaq 0x2b4ac(%rip), %rsi     # 0x340c2
movl $0xb, %edx
callq 0x7570
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rdx
movq 0x3d3b7(%rip), %rdi     # 0x45fe8
callq 0x7570
movq %rax, %r14
leaq 0x2b47f(%rip), %rsi     # 0x340bf
movl $0x2, %edx
movq %rax, %rdi
callq 0x7570
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movq %r14, %rdi
movq %rax, %rsi
callq 0x74e0
movq %rax, %rdi
callq 0x7200
leaq 0x70(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8c84
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x7500
movl $0x1, %ebx
callq 0x78e0
jmp 0x87f1
jmp 0x8d19
jmp 0x8cac
jmp 0x8cc6
movq %rax, %rbx
jmp 0x8ce4
jmp 0x8d19
jmp 0x8cb9
jmp 0x8ceb
movq %rax, %rbx
jmp 0x8d09
movq %rax, %rbx
movq %rsp, %rdi
callq 0x8f4e
jmp 0x8cc9
movq %rax, %rbx
movq %rsp, %rdi
callq 0x8f4e
jmp 0x8cee
movq %rax, %rbx
leaq 0x70(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8ce4
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x7500
callq 0x78e0
jmp 0x8d3d
movq %rax, %rbx
leaq 0x70(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8d09
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x7500
callq 0x78e0
jmp 0x8d3d
jmp 0x89c6
jmp 0x8d19
jmp 0x8d19
movq %rax, %rbx
jmp 0x8d3d
movq %rax, %rbx
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x8d3d
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x7500
leaq 0x10(%rsp), %rdi
callq 0x903a
movq %rbx, %rdi
callq 0x79a0
nop