// File: /workspace/github_cpp_makefile_star2_O1/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 0x834b
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 0x8d96
movq %r12, %rdi
movq %r14, %rsi
callq 0x9830
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x8343
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x7510
incq %r13
cmpq %r13, %rbp
jne 0x830d
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
leaq 0x2bca8(%rip), %rdx     # 0x34004
callq 0x9a97
movq 0x18(%rsp), %rsi
cmpq %rsi, %rax
je 0x83b6
movq 0x3dc26(%rip), %rbx     # 0x45f98
leaq 0x2bd5c(%rip), %rsi     # 0x340d5
movl $0x22, %edx
movq %rbx, %rdi
callq 0x7580
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x74e0
movsbl %al, %esi
movq 0x3dbf4(%rip), %rdi     # 0x45f98
callq 0x7030
movq %rax, %rdi
callq 0x7340
jmp 0x8986
movq 0x10(%rsp), %rdi
leaq 0x2bc45(%rip), %rdx     # 0x34007
callq 0x9a97
cmpq 0x18(%rsp), %rax
je 0x8467
movq 0x3dbbf(%rip), %rbx     # 0x45f98
leaq 0x2be30(%rip), %rsi     # 0x34210
movl $0x15, %edx
movq %rbx, %rdi
callq 0x7580
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x74e0
movsbl %al, %esi
movq 0x3db8d(%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 0x74e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x7030
movq %rax, %rdi
callq 0x7340
movq %rax, %rbx
leaq 0x3e124(%rip), %r14     # 0x46570
movq %r14, %rdi
callq 0x71b0
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x7580
jmp 0x8986
leaq 0x60(%rsp), %rdi
callq 0x90dc
movq %rsp, %rdi
movq $0x0, (%rdi)
movq $-0x1, 0x8(%rdi)
leaq 0x60(%rsp), %rsi
movq %rdi, %rdx
callq 0x9156
movq %rax, 0x30(%rsp)
leaq 0x60(%rsp), %rsi
movq %rsp, %rdi
movq %rdi, %rdx
callq 0x9156
leaq 0x30(%rsp), %rdi
movq %rax, 0x8(%rdi)
callq 0xb874
leaq 0x60(%rsp), %rdi
callq 0x74b0
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
leaq 0x2bc49(%rip), %rdx     # 0x34117
callq 0x9242
movq 0x18(%rsp), %rcx
cmpq %rcx, %rax
je 0x84fe
addq $0x20, %rax
cmpq %rcx, %rax
je 0x86f6
leaq 0x3e6cf(%rip), %rdi     # 0x46bc0
movq %rax, %rsi
callq 0xc552
jmp 0x8586
leaq 0x40(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x58(%rsp), %rsi
movq $0x1a, (%rsi)
leaq 0x30(%rsp), %rdi
xorl %edx, %edx
callq 0x79e0
leaq 0x30(%rsp), %rdi
movq %rax, (%rdi)
movq 0x58(%rsp), %rcx
movq %rcx, 0x10(%rdi)
movups 0x2bbed(%rip), %xmm0    # 0x34124
movups %xmm0, 0xa(%rax)
movups 0x2bbd8(%rip), %xmm0    # 0x3411a
movups %xmm0, (%rax)
movq %rcx, 0x8(%rdi)
movq (%rdi), %rax
movb $0x0, (%rax,%rcx)
leaq 0x60(%rsp), %rsi
callq 0x9b80
testb %al, %al
je 0x856f
leaq 0x3e65b(%rip), %rdi     # 0x46bc0
leaq 0x30(%rsp), %rsi
callq 0xc552
movq 0x30(%rsp), %rdi
cmpq %r15, %rdi
je 0x8586
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x7510
leaq 0x3e633(%rip), %r15     # 0x46bc0
cmpb $0x1, 0x100(%r15)
jne 0x8671
movq 0xd8(%r15), %rax
cmpq 0xe0(%r15), %rax
jbe 0x8671
movq 0x3da32(%rip), %rbx     # 0x45fe8
leaq 0x2bb78(%rip), %rsi     # 0x34135
movl $0x9, %edx
movq %rbx, %rdi
callq 0x7580
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x74e0
movsbl %al, %esi
movq 0x3da00(%rip), %rdi     # 0x45fe8
callq 0x7030
movq %rax, %rdi
callq 0x7340
movq %rax, %rbx
leaq 0x2bb40(%rip), %rsi     # 0x3413f
movl $0x46, %edx
movq %rax, %rdi
callq 0x7580
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x74e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x7030
movq %rax, %rdi
callq 0x7340
movq %rax, %rbx
leaq 0x2bb49(%rip), %rsi     # 0x34186
movl $0x3f, %edx
movq %rax, %rdi
callq 0x7580
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x74e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x7030
movq %rax, %rdi
callq 0x7340
cmpb $0x1, 0x101(%r15)
jne 0x868e
movl $0x3, %edi
callq 0x7980
cmpl $-0x1, %eax
je 0x89a6
xorl %ebx, %ebx
cmpq $0x0, 0x90(%r15)
je 0x87d3
callq 0x7230
testl %eax, %eax
je 0x8746
movq 0x3d936(%rip), %r14     # 0x45fe8
leaq 0x2b95a(%rip), %rsi     # 0x34013
movl $0x1c, %edx
movq %r14, %rdi
callq 0x7580
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x74e0
movsbl %al, %esi
movq 0x3d904(%rip), %rdi     # 0x45fe8
callq 0x7030
movq %rax, %rdi
callq 0x7340
jmp 0x87d3
movq 0x3d8eb(%rip), %rbx     # 0x45fe8
leaq 0x2b9fc(%rip), %rsi     # 0x34100
movl $0x19, %edx
movq %rbx, %rdi
callq 0x7580
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x74e0
movsbl %al, %esi
movq 0x3d8b9(%rip), %rdi     # 0x45fe8
callq 0x7030
movl $0x1, %ebx
movq %rax, %rdi
callq 0x7340
jmp 0x8988
movq 0x88(%r15), %rdi
callq 0x74c0
testq %rax, %rax
je 0x876a
movl 0x10(%rax), %edi
callq 0x79c0
cmpl $-0x1, %eax
je 0x87a1
xorl %ebx, %ebx
movb $0x1, %al
jmp 0x87cb
movq 0x3d877(%rip), %rdi     # 0x45fe8
leaq 0x2b8b8(%rip), %rsi     # 0x34030
movl $0xf, %edx
callq 0x7580
movq 0x88(%r15), %rsi
movq 0x90(%r15), %rdx
movq 0x3d851(%rip), %rdi     # 0x45fe8
callq 0x7580
movq %rax, %rbx
jmp 0x87bc
movq 0x3d840(%rip), %rbx     # 0x45fe8
leaq 0x2b891(%rip), %rsi     # 0x34040
movl $0x17, %edx
movq %rbx, %rdi
callq 0x7580
movq %rbx, %rdi
callq 0x7200
movl $0x1, %ebx
xorl %eax, %eax
testb %al, %al
je 0x8988
cmpq $0x0, 0x70(%r15)
je 0x88b2
callq 0x7230
testl %eax, %eax
je 0x8832
movq 0x3d7fa(%rip), %rbx     # 0x45fe8
leaq 0x2b863(%rip), %rsi     # 0x34058
movl $0x1b, %edx
movq %rbx, %rdi
callq 0x7580
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x74e0
movsbl %al, %esi
movq 0x3d7c8(%rip), %rdi     # 0x45fe8
callq 0x7030
movq %rax, %rdi
callq 0x7340
jmp 0x88b2
movq 0x68(%r15), %rdi
callq 0x73f0
testq %rax, %rax
je 0x886c
movl 0x10(%rax), %edi
callq 0x7a50
movb $0x1, %cl
cmpl $-0x1, %eax
jne 0x88aa
movq 0x3d792(%rip), %rbx     # 0x45fe8
leaq 0x2b826(%rip), %rsi     # 0x34083
movl $0x16, %edx
movq %rbx, %rdi
callq 0x7580
jmp 0x889b
movq 0x3d775(%rip), %rdi     # 0x45fe8
leaq 0x2b7fa(%rip), %rsi     # 0x34074
movl $0xe, %edx
callq 0x7580
movq 0x68(%r15), %rsi
movq 0x70(%r15), %rdx
movq 0x3d755(%rip), %rdi     # 0x45fe8
callq 0x7580
movq %rax, %rbx
movq %rbx, %rdi
callq 0x7200
movl $0x1, %ebx
xorl %ecx, %ecx
testb %cl, %cl
je 0x8988
movl $0x4, %edi
movl $0x1, %esi
xorl %eax, %eax
callq 0x7660
cmpl $-0x1, %eax
jne 0x890e
movq 0x3d719(%rip), %rbx     # 0x45fe8
leaq 0x2b7c4(%rip), %rsi     # 0x3409a
movl $0x24, %edx
movq %rbx, %rdi
callq 0x7580
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x74e0
movsbl %al, %esi
movq 0x3d6e7(%rip), %rdi     # 0x45fe8
callq 0x7030
movq %rax, %rdi
callq 0x7340
movl 0xa8(%r15), %eax
leaq 0x3e17c(%rip), %rcx     # 0x46a98
movl %eax, (%rcx)
cmpq $0x0, 0xb8(%r15)
je 0x8941
callq 0x8e2c
movl $0xb0, %esi
addq 0x3d627(%rip), %rsi     # 0x45f60
movq %rax, %rdi
callq 0x8e4a
leaq 0x60(%rsp), %rdi
callq 0xf27c
leaq 0x60(%rsp), %rdi
callq 0xf484
leaq 0x180(%rsp), %rdi
callq 0x954c
leaq 0x168(%rsp), %rdi
callq 0x95ca
leaq 0x140(%rsp), %rdi
callq 0x959a
leaq 0x68(%rsp), %rdi
callq 0xa2a8
xorl %ebx, %ebx
leaq 0x10(%rsp), %rdi
callq 0x9080
movl %ebx, %eax
addq $0x13e8, %rsp           # imm = 0x13E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x7040
movl (%rax), %edi
leaq 0x2b656(%rip), %rsi     # 0x3400a
callq 0x8dd3
jmp 0x8a15
jmp 0x8a15
movq %rdx, %r14
movq %rax, %rbx
movq 0x30(%rsp), %rdi
cmpq %r15, %rdi
je 0x8a1b
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x7510
jmp 0x8a1b
movq %rdx, %r14
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x8ea4
jmp 0x8a1b
jmp 0x8a15
jmp 0x8a0d
jmp 0x8a15
jmp 0x8d60
jmp 0x8a15
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x74b0
jmp 0x8d84
movq %rax, %rdi
callq 0x8fc6
movq %rdx, %r14
movq %rax, %rbx
cmpl $0x3, %r14d
jne 0x8b9f
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 0xbadc
leaq 0x3e040(%rip), %rax     # 0x46a98
movl (%rax), %esi
notl %esi
shrl $0x1f, %esi
leaq 0x2b760(%rip), %rdx     # 0x341c6
movq %rsp, %rdi
callq 0x9718
leaq 0x2b657(%rip), %rsi     # 0x340cc
movq %rsp, %rdi
callq 0x8eda
movq %rax, %r14
cmpb $0x1, (%rax)
jne 0x8a98
movq 0x8(%r14), %rdi
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rdx
callq 0x7580
leaq 0x2b62f(%rip), %rsi     # 0x340ce
movq %r14, %rdi
callq 0x8fd2
movq %rax, %r15
leaq 0x10(%rbx), %r14
cmpb $0x1, (%rax)
jne 0x8abf
movq 0x8(%r15), %rdi
movq %r14, %rsi
callq 0x9005
leaq 0x2b60c(%rip), %rsi     # 0x340d2
movq %r15, %rdi
callq 0x8f0e
movq %rax, %r15
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
leaq 0x50(%rsp), %rsi
movq %rax, (%rsi)
movq %r15, %rdi
callq 0x8f42
movq %rsp, %rdi
callq 0x8f94
movq 0x3d4ef(%rip), %rdi     # 0x45fe8
leaq 0x2b5c2(%rip), %rsi     # 0x340c2
movl $0xb, %edx
callq 0x7580
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rdx
movq 0x3d4cd(%rip), %rdi     # 0x45fe8
callq 0x7580
movq %rax, %r15
leaq 0x2b5a4(%rip), %rsi     # 0x340ce
movl $0x3, %edx
movq %rax, %rdi
callq 0x7580
movq %r15, %rdi
movq %r14, %rsi
callq 0x9005
movq %rax, %r14
leaq 0x2b586(%rip), %rsi     # 0x340d2
movl $0x2, %edx
movq %rax, %rdi
callq 0x7580
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movq %r14, %rdi
movq %rax, %rsi
callq 0x74f0
movq %rax, %rdi
callq 0x7200
leaq 0x70(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8b90
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x7510
movl $0x1, %ebx
callq 0x78f0
jmp 0x8988
cmpl $0x2, %r14d
jne 0x8d84
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 0xbadc
leaq 0x3debc(%rip), %rax     # 0x46a98
movl (%rax), %esi
notl %esi
shrl $0x1f, %esi
leaq 0x2b5dc(%rip), %rdx     # 0x341c6
movq %rsp, %rdi
callq 0x9718
leaq 0x2b4d3(%rip), %rsi     # 0x340cc
movq %rsp, %rdi
callq 0x8eda
movq %rax, %r14
cmpb $0x1, (%rax)
jne 0x8c1c
movq 0x8(%r14), %rdi
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rdx
callq 0x7580
leaq 0x2b49c(%rip), %rsi     # 0x340bf
movq %r14, %rdi
callq 0x8f0e
movq %rax, %r14
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
leaq 0x50(%rsp), %rsi
movq %rax, (%rsi)
movq %r14, %rdi
callq 0x8f42
movq %rsp, %rdi
callq 0x8f94
movq 0x3d392(%rip), %rdi     # 0x45fe8
leaq 0x2b465(%rip), %rsi     # 0x340c2
movl $0xb, %edx
callq 0x7580
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rdx
movq 0x3d370(%rip), %rdi     # 0x45fe8
callq 0x7580
movq %rax, %r14
leaq 0x2b438(%rip), %rsi     # 0x340bf
movl $0x2, %edx
movq %rax, %rdi
callq 0x7580
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movq %r14, %rdi
movq %rax, %rsi
callq 0x74f0
movq %rax, %rdi
callq 0x7200
leaq 0x70(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8ccb
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x7510
movl $0x1, %ebx
callq 0x78f0
jmp 0x8988
jmp 0x8d60
jmp 0x8d60
jmp 0x8cf3
jmp 0x8d0d
movq %rax, %rbx
jmp 0x8d2b
jmp 0x8d00
jmp 0x8d32
movq %rax, %rbx
jmp 0x8d50
movq %rax, %rbx
movq %rsp, %rdi
callq 0x8f94
jmp 0x8d10
movq %rax, %rbx
movq %rsp, %rdi
callq 0x8f94
jmp 0x8d35
movq %rax, %rbx
leaq 0x70(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8d2b
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x7510
callq 0x78f0
jmp 0x8d84
movq %rax, %rbx
leaq 0x70(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8d50
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x7510
callq 0x78f0
jmp 0x8d84
jmp 0x8a0d
jmp 0x8d60
jmp 0x8d60
movq %rax, %rbx
jmp 0x8d84
movq %rax, %rbx
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x8d84
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x7510
leaq 0x10(%rsp), %rdi
callq 0x9080
movq %rbx, %rdi
callq 0x79b0