// File: yahoo[P]UDPing/src/statswriter.cc
// Function: StatsWriter::StatsWriter(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int, char*, char*, char*, int)
StatsWriter::StatsWriter (string listen_hostname, string receive_hostname, int listen_port, char* statsdInfo, char* statsdTagInfo, char* statsdTagMetric, int quiet) {
    this->listen_port = listen_port;
    this->quiet = quiet;

    struct in_addr receive_addr;
    struct hostent* ent = NULL;
    if (inet_aton(receive_hostname.c_str(), &receive_addr)) {
        ent = gethostbyaddr(&receive_addr, sizeof(struct in_addr), AF_INET);
    }
    if (ent) {
        int n = strlen(ent->h_name);
        this->receive_hostname = new char[n + 1];
        strncpy(this->receive_hostname, ent->h_name, n);
        this->receive_hostname[n] = 0;
    } else {
        int n = receive_hostname.length();
        this->receive_hostname = new char[n + 1];
        strncpy(this->receive_hostname, receive_hostname.c_str(), n);
        this->receive_hostname[n] = 0;
    }

    char* c = this->receive_hostname;
    while (*c) {
        if (*c == '.') {
            *c = '_';
        }
        c++;
    }

    if (statsdInfo != NULL || statsdTagInfo != NULL) {
        this->fd = makeSocket(listen_hostname, 0);
    }

    if (statsdInfo != NULL) {
        int sdPort = 8125;
        int n = strlen(statsdInfo);
        char* sdInfo = new char[n + 1];
        strncpy(sdInfo, statsdInfo, n);
        sdInfo[n] = 0;
        char* portPointer = strchr(sdInfo, ':');
        if (portPointer) {
            *portPointer = 0;
            sdPort = atoi(portPointer + 1);
        }
        this->statsd_sa = getSockAddr(sdInfo, sdPort);
    }

    if (statsdTagInfo != NULL) {
        int sdPort = 8125;
        int n = strlen(statsdTagInfo);
        char* sdInfo = new char[n + 1];
        strncpy(sdInfo, statsdTagInfo, n);
        sdInfo[n] = 0;
        char* portPointer = strchr(sdInfo, ':');
        if (portPointer) {
            *portPointer = 0;
            sdPort = atoi(portPointer + 1);
        }
        this->tags_sa = getSockAddr(sdInfo, sdPort);
    }

    if (statsdTagMetric == NULL) {
        this->tags_metric = DEFAULT_METRIC_NAME;
    } else {
        int n = strlen(statsdTagMetric);
        this->tags_metric = new char[n + 1];
        strncpy(this->tags_metric, statsdTagMetric, n);
        this->tags_metric[n] = 0;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movq %rdx, -0x110(%rbp)
movq %rsi, -0x118(%rbp)
movq %rdi, %rax
movq -0x110(%rbp), %rdi
movl 0x18(%rbp), %edx
movq 0x10(%rbp), %rdx
movq %rax, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdi, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x108(%rbp)
movl -0x1c(%rbp), %ecx
movl %ecx, 0x8(%rax)
movl 0x18(%rbp), %ecx
movl %ecx, 0x28(%rax)
movq $0x0, -0x40(%rbp)
callq 0x2150
movq %rax, %rdi
leaq -0x34(%rbp), %rsi
callq 0x2210
cmpl $0x0, %eax
je 0x8efd
leaq -0x34(%rbp), %rdi
movl $0x4, %esi
movl $0x2, %edx
callq 0x23d0
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x8f64
movq -0x40(%rbp), %rax
movq (%rax), %rdi
callq 0x2170
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdi
movq $-0x1, %rax
cmpq $0x0, %rdi
cmovlq %rax, %rdi
callq 0x2030
movq %rax, %rcx
movq -0x108(%rbp), %rax
movq %rcx, (%rax)
movq (%rax), %rdi
movq -0x40(%rbp), %rax
movq (%rax), %rsi
movslq -0x44(%rbp), %rdx
callq 0x21a0
movq -0x108(%rbp), %rax
movq (%rax), %rax
movslq -0x44(%rbp), %rcx
movb $0x0, (%rax,%rcx)
jmp 0x8fd8
movq -0x110(%rbp), %rdi
callq 0x2430
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdi
movq $-0x1, %rax
cmpq $0x0, %rdi
cmovlq %rax, %rdi
callq 0x2030
movq -0x110(%rbp), %rdi
movq %rax, %rcx
movq -0x108(%rbp), %rax
movq %rcx, (%rax)
movq (%rax), %rax
movq %rax, -0x120(%rbp)
callq 0x2150
movq -0x120(%rbp), %rdi
movq %rax, %rsi
movslq -0x48(%rbp), %rdx
callq 0x21a0
movq -0x108(%rbp), %rax
movq (%rax), %rax
movslq -0x48(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x108(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpb $0x0, (%rax)
je 0x9010
movq -0x50(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2e, %eax
jne 0x9002
movq -0x50(%rbp), %rax
movb $0x5f, (%rax)
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x8fe6
cmpq $0x0, -0x28(%rbp)
jne 0x901e
cmpq $0x0, -0x30(%rbp)
je 0x9080
movq -0x118(%rbp), %rsi
leaq -0x70(%rbp), %rdi
movq %rdi, -0x130(%rbp)
callq 0x2160
movq -0x130(%rbp), %rdi
xorl %esi, %esi
callq 0x42e0
movl %eax, -0x124(%rbp)
jmp 0x904b
movq -0x108(%rbp), %rax
movl -0x124(%rbp), %ecx
movl %ecx, 0xc(%rax)
leaq -0x70(%rbp), %rdi
callq 0x21e0
jmp 0x9080
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x21e0
jmp 0x93e4
cmpq $0x0, -0x28(%rbp)
je 0x91e8
movl $0x1fbd, -0x80(%rbp)    # imm = 0x1FBD
movq -0x28(%rbp), %rdi
callq 0x2170
movl %eax, -0x84(%rbp)
movl -0x84(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdi
movq $-0x1, %rax
cmpq $0x0, %rdi
cmovlq %rax, %rdi
callq 0x2030
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rdi
movq -0x28(%rbp), %rsi
movslq -0x84(%rbp), %rdx
callq 0x21a0
movq -0x90(%rbp), %rax
movslq -0x84(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x90(%rbp), %rdi
movl $0x3a, %esi
callq 0x2130
movq %rax, -0x98(%rbp)
cmpq $0x0, -0x98(%rbp)
je 0x9130
movq -0x98(%rbp), %rax
movb $0x0, (%rax)
movq -0x98(%rbp), %rdi
addq $0x1, %rdi
callq 0x2450
movl %eax, -0x80(%rbp)
movq -0x90(%rbp), %rax
movq %rax, -0x140(%rbp)
leaq -0xb9(%rbp), %rdi
movq %rdi, -0x138(%rbp)
callq 0x24c0
movq -0x140(%rbp), %rsi
movq -0x138(%rbp), %rdx
leaq -0xb8(%rbp), %rdi
callq 0x23e0
jmp 0x916d
movl -0x80(%rbp), %esi
leaq -0xb8(%rbp), %rdi
callq 0x4480
movq %rax, -0x148(%rbp)
jmp 0x9185
movq -0x108(%rbp), %rax
movq -0x148(%rbp), %rcx
movq %rcx, 0x10(%rax)
leaq -0xb8(%rbp), %rdi
callq 0x21e0
leaq -0xb9(%rbp), %rdi
callq 0x2350
jmp 0x91e8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x91d7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x21e0
leaq -0xb9(%rbp), %rdi
callq 0x2350
jmp 0x93e4
cmpq $0x0, -0x30(%rbp)
je 0x9359
movl $0x1fbd, -0xc0(%rbp)    # imm = 0x1FBD
movq -0x30(%rbp), %rdi
callq 0x2170
movl %eax, -0xc4(%rbp)
movl -0xc4(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdi
movq $-0x1, %rax
cmpq $0x0, %rdi
cmovlq %rax, %rdi
callq 0x2030
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rdi
movq -0x30(%rbp), %rsi
movslq -0xc4(%rbp), %rdx
callq 0x21a0
movq -0xd0(%rbp), %rax
movslq -0xc4(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0xd0(%rbp), %rdi
movl $0x3a, %esi
callq 0x2130
movq %rax, -0xd8(%rbp)
cmpq $0x0, -0xd8(%rbp)
je 0x929e
movq -0xd8(%rbp), %rax
movb $0x0, (%rax)
movq -0xd8(%rbp), %rdi
addq $0x1, %rdi
callq 0x2450
movl %eax, -0xc0(%rbp)
movq -0xd0(%rbp), %rax
movq %rax, -0x158(%rbp)
leaq -0xf9(%rbp), %rdi
movq %rdi, -0x150(%rbp)
callq 0x24c0
movq -0x158(%rbp), %rsi
movq -0x150(%rbp), %rdx
leaq -0xf8(%rbp), %rdi
callq 0x23e0
jmp 0x92db
movl -0xc0(%rbp), %esi
leaq -0xf8(%rbp), %rdi
callq 0x4480
movq %rax, -0x160(%rbp)
jmp 0x92f6
movq -0x108(%rbp), %rax
movq -0x160(%rbp), %rcx
movq %rcx, 0x18(%rax)
leaq -0xf8(%rbp), %rdi
callq 0x21e0
leaq -0xf9(%rbp), %rdi
callq 0x2350
jmp 0x9359
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x9348
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x21e0
leaq -0xf9(%rbp), %rdi
callq 0x2350
jmp 0x93e4
cmpq $0x0, 0x10(%rbp)
jne 0x9374
movq -0x108(%rbp), %rax
leaq 0x6f32(%rip), %rcx      # 0x102a0
movq %rcx, 0x20(%rax)
jmp 0x93db
movq 0x10(%rbp), %rdi
callq 0x2170
movl %eax, -0x100(%rbp)
movl -0x100(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdi
movq $-0x1, %rax
cmpq $0x0, %rdi
cmovlq %rax, %rdi
callq 0x2030
movq %rax, %rcx
movq -0x108(%rbp), %rax
movq %rcx, 0x20(%rax)
movq 0x20(%rax), %rdi
movq 0x10(%rbp), %rsi
movslq -0x100(%rbp), %rdx
callq 0x21a0
movq -0x108(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x100(%rbp), %rcx
movb $0x0, (%rax,%rcx)
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
movq -0x78(%rbp), %rdi
callq 0x24b0
nopl (%rax)