// File: /workspace/github_cpp_makefile_star2_O3/yahoo[P]UDPing/src/server.cc
// Function: main
int main(int argc, char** argv) {
    if (!getuid()) {
        // I'm running as root.  Switch to nobody or die!!!
        struct passwd* pwd = getpwnam("nobody");
        if (pwd && pwd->pw_uid) {
            if (setgid(pwd->pw_gid)) {
                cerr << "Couldn't change userid to nobody (setgid failed).  Terminating server" << endl;
            }
            if (setuid(pwd->pw_uid)) {
                cerr << "Couldn't change userid to nobody (setuid failed).  Terminating server" << endl;
            }
        } else {
            cerr << "Couldn't change userid to nobody.  Terminating server" << endl;
            exit(-1);
        }
    }
    char buf[MAXBUF];
    setOptions(new Options(argc, argv, "p:k:l:m:r:s:t:vq"));

    stringstream usage;
    usage << "Usage: udping_server -l <listen hostname> -p <port number> -k <keepalive interval seconds> [-r <receive hostname>]" << endl <<
             "           [-s <statsd host:port>] [-t <tag based statsd host:port>] [-m <tag based statds metric name>] [-v] [-q]" << endl <<
             "-l: address to bind udp listener to" << endl <<
             "-p: udp port to bind listener to" << endl <<
             "-k: seconds to wait for delayed pings to show up before publishing stats" << endl <<
             "-r: address to report stats as being received by, if different from -l" << endl <<
             "-s: statsd host:port (default port 8125)" << endl <<
             "-t: tag based statsd host:port (default port 8125)" << endl <<
             "-m: tag based statsd metric name (default udping)" << endl <<
             "-v: verbose" << endl <<
             "-q: quiet" << endl;
    string listen_host = getOptions()->getStringOption('l', 1, usage.str(), "Hostname not provided\n");
    int listen_port = getOptions()->parseIntOption('p', 1, 1024, 65536, usage.str(), "Port number is out of range 1024-65532\n");
    int keepalive = getOptions()->parseIntOption('k', 1, 1, 60, usage.str(), "Keepalive interval is out of range 1-60s\n");

    char* rh = getOptions()->getStringOption('r', 0, usage.str(), "");
    string receive_host = rh == NULL ? listen_host : rh;

    /* Establish Stats Writer(s) */
    char* statsdInfo = getOptions()->getStringOption('s', 0, usage.str(), "");
    char* statsdTagInfo = getOptions()->getStringOption('t', 0, usage.str(), "");
    char* statsdTagMetric = getOptions()->getStringOption('m', 0, usage.str(), "");
    int quiet = getOptions()->getQuiet();
    StatsWriter* writer = new StatsWriter(listen_host, receive_host, listen_port, statsdInfo, statsdTagInfo, statsdTagMetric, quiet);

    /* Start Session Manager */
    ServerSessionManager sessionManager(writer, keepalive);

    /* Periodic check to see if packets are received */
    setIntervalTimer(keepalive, handleAlarm);

    int fd = makeSocket (listen_host, listen_port);
    if (fd < 0) {
        err (1, "Failed to create socket");
    }
    while (1) {
        sessionManager.readNextPacket (fd);
    }
    return(0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4d8, %rsp            # imm = 0x4D8
movq %rsi, %rbx
movl %edi, %ebp
callq 0x3180
testl %eax, %eax
jne 0x373c
leaq 0x499e(%rip), %rdi      # 0x8004
callq 0x3260
testq %rax, %rax
je 0x3679
movq %rax, %r14
cmpl $0x0, 0x10(%rax)
jne 0x369e
movq 0x7970(%rip), %rdi      # 0xaff0
leaq 0x4a10(%rip), %rsi      # 0x8097
callq 0x3310
movq %rax, %rdi
callq 0x3170
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x3370
movl 0x14(%r14), %edi
callq 0x34c0
testl %eax, %eax
je 0x36ed
movq 0x793e(%rip), %r15      # 0xaff0
leaq 0x4952(%rip), %rsi      # 0x800b
movl $0x45, %edx
movq %r15, %rdi
callq 0x3340
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3300
movsbl %al, %esi
movq %r15, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31e0
movl 0x10(%r14), %edi
callq 0x34e0
testl %eax, %eax
je 0x373c
movq 0x78ef(%rip), %r14      # 0xaff0
leaq 0x4949(%rip), %rsi      # 0x8051
movl $0x45, %edx
movq %r14, %rdi
callq 0x3340
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3300
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31e0
movl $0x800, %edi            # imm = 0x800
callq 0x3320
movq %rax, %r14
leaq 0x178(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x4971(%rip), %rsi      # 0x80cd
leaq 0x497a(%rip), %rdx      # 0x80dd
leaq 0x168(%rsp), %rdi
callq 0x425a
movb $0x1, %r12b
leaq 0x168(%rsp), %rcx
movq %r14, %rdi
movl %ebp, %esi
movq %rbx, %rdx
callq 0x44a0
xorl %r12d, %r12d
movq %r14, %rdi
callq 0x4600
movq 0x168(%rsp), %rdi
cmpq %r15, %rdi
je 0x37a5
callq 0x32f0
leaq 0x350(%rsp), %rdi
callq 0x3200
leaq 0x360(%rsp), %rbx
leaq 0x491d(%rip), %rsi      # 0x80de
movl $0x72, %edx
movq %rbx, %rdi
callq 0x3340
movq 0x360(%rsp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3300
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31e0
movq %rax, %rbx
leaq 0x494d(%rip), %rsi      # 0x8151
movl $0x72, %edx
movq %rax, %rdi
callq 0x3340
movq %rbx, %rdi
callq 0x3170
movq %rax, %rbx
leaq 0x49a1(%rip), %rsi      # 0x81c4
movl $0x23, %edx
movq %rax, %rdi
callq 0x3340
movq %rbx, %rdi
callq 0x3170
movq %rax, %rbx
leaq 0x49a6(%rip), %rsi      # 0x81e8
movl $0x20, %edx
movq %rax, %rdi
callq 0x3340
movq %rbx, %rdi
callq 0x3170
movq %rax, %rbx
leaq 0x49a8(%rip), %rsi      # 0x8209
movl $0x48, %edx
movq %rax, %rdi
callq 0x3340
movq %rbx, %rdi
callq 0x3170
movq %rax, %rbx
leaq 0x49d2(%rip), %rsi      # 0x8252
movl $0x46, %edx
movq %rax, %rdi
callq 0x3340
movq %rbx, %rdi
callq 0x3170
movq %rax, %rbx
leaq 0x49fa(%rip), %rsi      # 0x8299
movl $0x28, %edx
movq %rax, %rdi
callq 0x3340
movq %rbx, %rdi
callq 0x3170
movq %rax, %rbx
leaq 0x4a04(%rip), %rsi      # 0x82c2
movl $0x32, %edx
movq %rax, %rdi
callq 0x3340
movq %rbx, %rdi
callq 0x3170
movq %rax, %rbx
leaq 0x4a18(%rip), %rsi      # 0x82f5
movl $0x31, %edx
movq %rax, %rdi
callq 0x3340
movq %rbx, %rdi
callq 0x3170
movq %rax, %rbx
leaq 0x4a2b(%rip), %rsi      # 0x8327
movl $0xb, %edx
movq %rax, %rdi
callq 0x3340
movq %rbx, %rdi
callq 0x3170
movq %rax, %rbx
leaq 0x4a18(%rip), %rsi      # 0x8333
movl $0x9, %edx
movq %rax, %rdi
callq 0x3340
movq %rbx, %rdi
callq 0x3170
callq 0x4608
movq %rax, %rbx
leaq 0x368(%rsp), %r14
leaq 0x288(%rsp), %rdi
movq %r14, %rsi
callq 0x3440
leaq 0x158(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x49da(%rip), %rsi      # 0x833d
leaq 0x49e9(%rip), %rdx      # 0x8353
leaq 0x148(%rsp), %rdi
callq 0x425a
leaq 0x288(%rsp), %rcx
leaq 0x148(%rsp), %r8
movq %rbx, %rdi
movl $0x6c, %esi
movl $0x1, %edx
callq 0x459a
leaq 0x28(%rsp), %rdi
leaq 0x2a8(%rsp), %rdx
movq %rax, %rsi
callq 0x3130
movq 0x148(%rsp), %rdi
cmpq %r15, %rdi
je 0x39c0
callq 0x32f0
leaq 0x298(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x39d6
callq 0x32f0
callq 0x4608
movq %rax, %rbx
leaq 0x268(%rsp), %rdi
movq %r14, %rsi
callq 0x3440
leaq 0x258(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x4952(%rip), %rsi      # 0x8354
leaq 0x4972(%rip), %rdx      # 0x837b
leaq 0x248(%rsp), %r15
movq %r15, %rdi
callq 0x425a
movq %r15, (%rsp)
leaq 0x268(%rsp), %r9
movq %rbx, %rdi
movl $0x70, %esi
movl $0x1, %edx
movl $0x400, %ecx            # imm = 0x400
movl $0x10000, %r8d          # imm = 0x10000
callq 0x4536
movl %eax, %ebx
movq 0x248(%rsp), %rdi
cmpq %r12, %rdi
je 0x3a56
callq 0x32f0
leaq 0x278(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3a6c
callq 0x32f0
callq 0x4608
movq %rax, %r15
leaq 0x228(%rsp), %rdi
movq %r14, %rsi
callq 0x3440
leaq 0x218(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x48e5(%rip), %rsi      # 0x837c
leaq 0x4907(%rip), %rdx      # 0x83a5
leaq 0x208(%rsp), %r12
movq %r12, %rdi
callq 0x425a
movq %r12, (%rsp)
leaq 0x228(%rsp), %r9
movq %r15, %rdi
movl $0x6b, %esi
movl $0x1, %edx
movl $0x1, %ecx
movl $0x3c, %r8d
callq 0x4536
movl %eax, %ebp
movq 0x208(%rsp), %rdi
cmpq %r13, %rdi
je 0x3aeb
callq 0x32f0
leaq 0x238(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3b01
callq 0x32f0
callq 0x4608
movq %rax, %r15
leaq 0x1e8(%rsp), %rdi
movq %r14, %rsi
callq 0x3440
leaq 0x138(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x484e(%rip), %rdx      # 0x837b
leaq 0x128(%rsp), %rdi
movq %rdx, %rsi
callq 0x425a
leaq 0x1e8(%rsp), %rcx
leaq 0x128(%rsp), %r8
movq %r15, %rdi
movl $0x72, %esi
xorl %edx, %edx
callq 0x459a
movq %rax, %r15
movq 0x128(%rsp), %rdi
cmpq %r12, %rdi
je 0x3b71
callq 0x32f0
leaq 0x1f8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3b87
callq 0x32f0
leaq 0x98(%rsp), %r13
movq %r13, -0x10(%r13)
testq %r15, %r15
jne 0x3bb4
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
addq %rsi, %rdx
leaq 0x88(%rsp), %rdi
callq 0x41c4
jmp 0x3bd2
movq %r15, %rdi
callq 0x3150
movq %r15, %rdx
addq %rax, %rdx
leaq 0x88(%rsp), %rdi
movq %r15, %rsi
callq 0x425a
callq 0x4608
movq %rax, %r15
leaq 0x1c8(%rsp), %rdi
movq %r14, %rsi
callq 0x3440
leaq 0x118(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x477d(%rip), %rdx      # 0x837b
leaq 0x108(%rsp), %rdi
movq %rdx, %rsi
callq 0x425a
leaq 0x1c8(%rsp), %rcx
leaq 0x108(%rsp), %r8
movq %r15, %rdi
movl $0x73, %esi
xorl %edx, %edx
callq 0x459a
movq %rax, %r15
movq 0x108(%rsp), %rdi
cmpq %r12, %rdi
je 0x3c42
callq 0x32f0
leaq 0x1d8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3c58
callq 0x32f0
callq 0x4608
movq %rax, %r12
leaq 0x1a8(%rsp), %rdi
movq %r14, %rsi
callq 0x3440
leaq 0x78(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x46fb(%rip), %rdx      # 0x837b
leaq 0x68(%rsp), %rdi
movq %rdx, %rsi
callq 0x425a
leaq 0x1a8(%rsp), %rcx
leaq 0x68(%rsp), %r8
movq %r12, %rdi
movl $0x74, %esi
xorl %edx, %edx
callq 0x459a
movq %rax, 0x20(%rsp)
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0x3cc2
callq 0x32f0
leaq 0x1b8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3cd8
callq 0x32f0
callq 0x4608
movq %rax, %r12
leaq 0x188(%rsp), %rdi
movq %r14, %rsi
callq 0x3440
leaq 0xf8(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x4678(%rip), %rdx      # 0x837b
leaq 0xe8(%rsp), %rdi
movq %rdx, %rsi
callq 0x425a
leaq 0x188(%rsp), %rcx
leaq 0xe8(%rsp), %r8
movq %r12, %rdi
movl $0x6d, %esi
xorl %edx, %edx
callq 0x459a
movq %rax, 0x18(%rsp)
movq 0xe8(%rsp), %rdi
cmpq %r14, %rdi
je 0x3d49
callq 0x32f0
leaq 0x198(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3d5f
callq 0x32f0
callq 0x4608
movq %rax, %rdi
callq 0x45e4
movl %eax, 0x14(%rsp)
movl $0x30, %edi
callq 0x3320
movq %rax, %r14
leaq 0x58(%rsp), %rax
movq %rax, -0x10(%rax)
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
addq %rsi, %rdx
leaq 0x48(%rsp), %rdi
callq 0x41c4
leaq 0xd8(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x88(%rsp), %rsi
movq 0x90(%rsp), %rdx
addq %rsi, %rdx
leaq 0xc8(%rsp), %rdi
callq 0x41c4
movl 0x14(%rsp), %eax
movl %eax, 0x8(%rsp)
movq 0x18(%rsp), %rax
movq %rax, (%rsp)
leaq 0x48(%rsp), %rsi
leaq 0xc8(%rsp), %rdx
movq %r14, %rdi
movl %ebx, %ecx
movq %r15, %r8
movq 0x20(%rsp), %r9
callq 0x63b6
movq 0xc8(%rsp), %rdi
cmpq %r12, %rdi
je 0x3e0c
callq 0x32f0
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x3e20
callq 0x32f0
leaq 0x2a8(%rsp), %rdi
movq %r14, %rsi
movl %ebp, %edx
callq 0x556a
leaq 0x1810(%rip), %rsi      # 0x5649
movl %ebp, %edi
callq 0x4450
leaq 0xb8(%rsp), %r14
movq %r14, -0x10(%r14)
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
addq %rsi, %rdx
leaq 0xa8(%rsp), %rdi
callq 0x41c4
leaq 0xa8(%rsp), %rdi
movl %ebx, %esi
callq 0x464d
movl %eax, %ebx
movq 0xa8(%rsp), %rdi
cmpq %r14, %rdi
je 0x3e89
callq 0x32f0
testl %ebx, %ebx
jns 0x3ea0
leaq 0x4512(%rip), %rsi      # 0x83a6
movl $0x1, %edi
xorl %eax, %eax
callq 0x32b0
leaq 0x2a8(%rsp), %r14
movq %r14, %rdi
movl %ebx, %esi
callq 0x5310
jmp 0x3ea8
jmp 0x3ecf
jmp 0x3ecf
movq %rax, %rbx
movq 0xa8(%rsp), %rdi
cmpq %r14, %rdi
je 0x3ed2
callq 0x32f0
jmp 0x3ed2
movq %rax, %rbx
leaq 0x2a8(%rsp), %rdi
callq 0x40e0
jmp 0x3fbb
jmp 0x3fb8
movq %rax, %rbx
movq 0xc8(%rsp), %rdi
cmpq %r12, %rdi
je 0x3f03
callq 0x32f0
jmp 0x3f03
movq %rax, %rbx
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x3f1c
callq 0x32f0
jmp 0x3f1c
movq %rax, %rbx
movq %r14, %rdi
jmp 0x3fa7
jmp 0x3fb8
jmp 0x3fb8
movq %rax, %rbx
movq 0xe8(%rsp), %rdi
cmpq %r14, %rdi
je 0x3f48
callq 0x32f0
jmp 0x3f48
movq %rax, %rbx
leaq 0x198(%rsp), %rax
jmp 0x3f9e
jmp 0x3fb8
movq %rax, %rbx
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0x3f70
callq 0x32f0
jmp 0x3f70
movq %rax, %rbx
leaq 0x1b8(%rsp), %rax
jmp 0x3f9e
jmp 0x3fb8
movq %rax, %rbx
movq 0x108(%rsp), %rdi
cmpq %r12, %rdi
je 0x3f96
callq 0x32f0
jmp 0x3f96
movq %rax, %rbx
leaq 0x1d8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3fbb
callq 0x32f0
jmp 0x3fbb
jmp 0x404b
jmp 0x404b
movq %rax, %rbx
movq 0x88(%rsp), %rdi
cmpq %r13, %rdi
jne 0x4044
jmp 0x404e
movq %rax, %rbx
movq 0x128(%rsp), %rdi
cmpq %r12, %rdi
je 0x3fe7
callq 0x32f0
jmp 0x3fe7
movq %rax, %rbx
leaq 0x1f8(%rsp), %rax
jmp 0x403b
jmp 0x404b
movq %rax, %rbx
movq 0x208(%rsp), %rdi
cmpq %r13, %rdi
je 0x400d
callq 0x32f0
jmp 0x400d
movq %rax, %rbx
leaq 0x238(%rsp), %rax
jmp 0x403b
jmp 0x404b
movq %rax, %rbx
movq 0x248(%rsp), %rdi
cmpq %r12, %rdi
je 0x4033
callq 0x32f0
jmp 0x4033
movq %rax, %rbx
leaq 0x278(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x404e
callq 0x32f0
jmp 0x404e
movq %rax, %rbx
leaq 0x38(%rsp), %rax
jmp 0x4079
jmp 0x4057
movq %rax, %rbx
movq 0x148(%rsp), %rdi
cmpq %r15, %rdi
je 0x4071
callq 0x32f0
jmp 0x4071
movq %rax, %rbx
leaq 0x298(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x408e
callq 0x32f0
jmp 0x408e
jmp 0x408b
movq %rax, %rbx
movq 0x6f23(%rip), %rsi      # 0xafb8
leaq 0x350(%rsp), %rdi
callq 0x3220
leaq 0x3d0(%rsp), %rdi
callq 0x3110
jmp 0x40d8
movq %rax, %rbx
movq 0x168(%rsp), %rdi
cmpq %r15, %rdi
je 0x40c6
callq 0x32f0
testb %r12b, %r12b
jne 0x40d0
jmp 0x40d8
movq %rax, %rbx
movq %r14, %rdi
callq 0x32f0
movq %rbx, %rdi
callq 0x34b0