// File: /workspace/github_cpp_makefile_star2_O1/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), %r12
movq %r12, -0x10(%r12)
leaq 0x4970(%rip), %rsi      # 0x80cd
leaq 0x4979(%rip), %rdx      # 0x80dd
leaq 0x168(%rsp), %rdi
callq 0x4258
movb $0x1, %r15b
leaq 0x168(%rsp), %rcx
movq %r14, %rdi
movl %ebp, %esi
movq %rbx, %rdx
callq 0x44a0
xorl %r15d, %r15d
movq %r14, %rdi
callq 0x4600
movq 0x168(%rsp), %rdi
cmpq %r12, %rdi
je 0x37a6
callq 0x32f0
leaq 0x350(%rsp), %rdi
callq 0x3200
leaq 0x360(%rsp), %rbx
leaq 0x491c(%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 0x494c(%rip), %rsi      # 0x8151
movl $0x72, %edx
movq %rax, %rdi
callq 0x3340
movq %rbx, %rdi
callq 0x3170
movq %rax, %rbx
leaq 0x49a0(%rip), %rsi      # 0x81c4
movl $0x23, %edx
movq %rax, %rdi
callq 0x3340
movq %rbx, %rdi
callq 0x3170
movq %rax, %rbx
leaq 0x49a5(%rip), %rsi      # 0x81e8
movl $0x20, %edx
movq %rax, %rdi
callq 0x3340
movq %rbx, %rdi
callq 0x3170
movq %rax, %rbx
leaq 0x49a7(%rip), %rsi      # 0x8209
movl $0x48, %edx
movq %rax, %rdi
callq 0x3340
movq %rbx, %rdi
callq 0x3170
movq %rax, %rbx
leaq 0x49d1(%rip), %rsi      # 0x8252
movl $0x46, %edx
movq %rax, %rdi
callq 0x3340
movq %rbx, %rdi
callq 0x3170
movq %rax, %rbx
leaq 0x49f9(%rip), %rsi      # 0x8299
movl $0x28, %edx
movq %rax, %rdi
callq 0x3340
movq %rbx, %rdi
callq 0x3170
movq %rax, %rbx
leaq 0x4a03(%rip), %rsi      # 0x82c2
movl $0x32, %edx
movq %rax, %rdi
callq 0x3340
movq %rbx, %rdi
callq 0x3170
movq %rax, %rbx
leaq 0x4a17(%rip), %rsi      # 0x82f5
movl $0x31, %edx
movq %rax, %rdi
callq 0x3340
movq %rbx, %rdi
callq 0x3170
movq %rax, %rbx
leaq 0x4a2a(%rip), %rsi      # 0x8327
movl $0xb, %edx
movq %rax, %rdi
callq 0x3340
movq %rbx, %rdi
callq 0x3170
movq %rax, %rbx
leaq 0x4a17(%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 0x49d9(%rip), %rsi      # 0x833d
leaq 0x49e8(%rip), %rdx      # 0x8353
leaq 0x148(%rsp), %rdi
callq 0x4258
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 0x39c1
callq 0x32f0
leaq 0x298(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x39d7
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 0x4951(%rip), %rsi      # 0x8354
leaq 0x4971(%rip), %rdx      # 0x837b
leaq 0x248(%rsp), %r15
movq %r15, %rdi
callq 0x4258
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 0x3a57
callq 0x32f0
leaq 0x278(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3a6d
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 0x48e4(%rip), %rsi      # 0x837c
leaq 0x4906(%rip), %rdx      # 0x83a5
leaq 0x208(%rsp), %r12
movq %r12, %rdi
callq 0x4258
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 0x3aec
callq 0x32f0
leaq 0x238(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3b02
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 0x484d(%rip), %rdx      # 0x837b
leaq 0x128(%rsp), %rdi
movq %rdx, %rsi
callq 0x4258
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 0x3b72
callq 0x32f0
leaq 0x1f8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3b88
callq 0x32f0
leaq 0x98(%rsp), %r13
movq %r13, -0x10(%r13)
testq %r15, %r15
jne 0x3bb5
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
addq %rsi, %rdx
leaq 0x88(%rsp), %rdi
callq 0x41c8
jmp 0x3bd3
movq %r15, %rdi
callq 0x3150
movq %r15, %rdx
addq %rax, %rdx
leaq 0x88(%rsp), %rdi
movq %r15, %rsi
callq 0x4258
callq 0x4608
movq %rax, %r15
leaq 0x1c8(%rsp), %rdi
movq %r14, %rsi
callq 0x3440
leaq 0x118(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x477c(%rip), %rdx      # 0x837b
leaq 0x108(%rsp), %rdi
movq %rdx, %rsi
callq 0x4258
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 0x3c43
callq 0x32f0
leaq 0x1d8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3c59
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 0x46fa(%rip), %rdx      # 0x837b
leaq 0x68(%rsp), %rdi
movq %rdx, %rsi
callq 0x4258
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 0x3cc3
callq 0x32f0
leaq 0x1b8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3cd9
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 0x4677(%rip), %rdx      # 0x837b
leaq 0xe8(%rsp), %rdi
movq %rdx, %rsi
callq 0x4258
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 0x3d4a
callq 0x32f0
leaq 0x198(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3d60
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 0x41c8
leaq 0xd8(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x88(%rsp), %rsi
movq 0x90(%rsp), %rdx
addq %rsi, %rdx
leaq 0xc8(%rsp), %rdi
callq 0x41c8
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 0x63ae
movq 0xc8(%rsp), %rdi
cmpq %r12, %rdi
je 0x3e0d
callq 0x32f0
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x3e21
callq 0x32f0
leaq 0x2a8(%rsp), %rdi
movq %r14, %rsi
movl %ebp, %edx
callq 0x556c
leaq 0x1811(%rip), %rsi      # 0x564b
movl %ebp, %edi
callq 0x4448
leaq 0xb8(%rsp), %r14
movq %r14, -0x10(%r14)
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
addq %rsi, %rdx
leaq 0xa8(%rsp), %rdi
callq 0x41c8
leaq 0xa8(%rsp), %rdi
movl %ebx, %esi
callq 0x464d
movl %eax, %ebx
movq 0xa8(%rsp), %rdi
cmpq %r14, %rdi
je 0x3e8a
callq 0x32f0
testl %ebx, %ebx
jns 0x3ea1
leaq 0x4511(%rip), %rsi      # 0x83a6
movl $0x1, %edi
xorl %eax, %eax
callq 0x32b0
leaq 0x2a8(%rsp), %r14
movq %r14, %rdi
movl %ebx, %esi
callq 0x5312
jmp 0x3ea9
jmp 0x3ed0
jmp 0x3ed0
movq %rax, %rbx
movq 0xa8(%rsp), %rdi
cmpq %r14, %rdi
je 0x3ed3
callq 0x32f0
jmp 0x3ed3
movq %rax, %rbx
leaq 0x2a8(%rsp), %rdi
callq 0x40e4
jmp 0x3fbc
jmp 0x3fb9
movq %rax, %rbx
movq 0xc8(%rsp), %rdi
cmpq %r12, %rdi
je 0x3f04
callq 0x32f0
jmp 0x3f04
movq %rax, %rbx
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x3f1d
callq 0x32f0
jmp 0x3f1d
movq %rax, %rbx
movq %r14, %rdi
jmp 0x3fa8
jmp 0x3fb9
jmp 0x3fb9
movq %rax, %rbx
movq 0xe8(%rsp), %rdi
cmpq %r14, %rdi
je 0x3f49
callq 0x32f0
jmp 0x3f49
movq %rax, %rbx
leaq 0x198(%rsp), %rax
jmp 0x3f9f
jmp 0x3fb9
movq %rax, %rbx
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0x3f71
callq 0x32f0
jmp 0x3f71
movq %rax, %rbx
leaq 0x1b8(%rsp), %rax
jmp 0x3f9f
jmp 0x3fb9
movq %rax, %rbx
movq 0x108(%rsp), %rdi
cmpq %r12, %rdi
je 0x3f97
callq 0x32f0
jmp 0x3f97
movq %rax, %rbx
leaq 0x1d8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3fbc
callq 0x32f0
jmp 0x3fbc
jmp 0x404c
jmp 0x404c
movq %rax, %rbx
movq 0x88(%rsp), %rdi
cmpq %r13, %rdi
jne 0x4045
jmp 0x404f
movq %rax, %rbx
movq 0x128(%rsp), %rdi
cmpq %r12, %rdi
je 0x3fe8
callq 0x32f0
jmp 0x3fe8
movq %rax, %rbx
leaq 0x1f8(%rsp), %rax
jmp 0x403c
jmp 0x404c
movq %rax, %rbx
movq 0x208(%rsp), %rdi
cmpq %r13, %rdi
je 0x400e
callq 0x32f0
jmp 0x400e
movq %rax, %rbx
leaq 0x238(%rsp), %rax
jmp 0x403c
jmp 0x404c
movq %rax, %rbx
movq 0x248(%rsp), %rdi
cmpq %r12, %rdi
je 0x4034
callq 0x32f0
jmp 0x4034
movq %rax, %rbx
leaq 0x278(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x404f
callq 0x32f0
jmp 0x404f
movq %rax, %rbx
leaq 0x38(%rsp), %rax
jmp 0x407a
jmp 0x4058
movq %rax, %rbx
movq 0x148(%rsp), %rdi
cmpq %r15, %rdi
je 0x4072
callq 0x32f0
jmp 0x4072
movq %rax, %rbx
leaq 0x298(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x408f
callq 0x32f0
jmp 0x408f
jmp 0x408c
movq %rax, %rbx
movq 0x6f22(%rip), %rsi      # 0xafb8
leaq 0x350(%rsp), %rdi
callq 0x3220
leaq 0x3d0(%rsp), %rdi
callq 0x3110
jmp 0x40dc
movq %rax, %rbx
movq 0x168(%rsp), %rdi
cmpq %r12, %rdi
je 0x40cf
callq 0x32f0
jmp 0x40cf
movq %rax, %rbx
movb $0x1, %r15b
testb %r15b, %r15b
je 0x40dc
movq %r14, %rdi
callq 0x32f0
movq %rbx, %rdi
callq 0x34b0