// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %r9, 0x10(%rsp)
movq %r8, %r12
movq %rdx, %rbp
movq %rsi, %r13
movq %rdi, %rbx
movl 0xb8(%rsp), %eax
movl %ecx, 0x8(%rdi)
movl %eax, 0x28(%rdi)
movq (%rdx), %rdi
leaq 0xc(%rsp), %rsi
callq 0x3230
testl %eax, %eax
je 0x641f
leaq 0xc(%rsp), %rdi
movl $0x4, %esi
movl $0x2, %edx
callq 0x33b0
testq %rax, %rax
je 0x641f
movq %rax, %r14
movq (%rax), %rdi
callq 0x3150
movq %rax, %r15
movq %r14, %rbp
jmp 0x6423
movq 0x8(%rbp), %r15
leal 0x1(%r15), %eax
cltq
testq %rax, %rax
movq $-0x1, %rdi
cmovnsq %rax, %rdi
callq 0x3030
movq %rax, %r14
movq %rax, (%rbx)
movq (%rbp), %rsi
movslq %r15d, %r15
movq %rax, %rdi
movq %r15, %rdx
callq 0x3190
movb $0x0, (%r14,%r15)
movq 0x10(%rsp), %rbp
movzbl (%r14), %eax
cmpl $0x2e, %eax
je 0x646d
testl %eax, %eax
jne 0x6471
jmp 0x6476
movb $0x5f, (%r14)
incq %r14
jmp 0x645e
movq %r12, %rax
orq %rbp, %rax
je 0x6643
leaq 0x68(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%r13), %rsi
movq 0x8(%r13), %rdx
addq %rsi, %rdx
leaq 0x58(%rsp), %r14
movq %r14, %rdi
callq 0x41c4
movq %r14, %rdi
xorl %esi, %esi
callq 0x464d
movl %eax, 0xc(%rbx)
movq 0x58(%rsp), %rdi
cmpq %r15, %rdi
je 0x64bf
callq 0x32f0
testq %r12, %r12
je 0x6584
movq %r12, %rdi
callq 0x3150
movq %rax, %r14
shlq $0x20, %rax
movabsq $0x100000000, %rcx      # imm = 0x100000000
addq %rcx, %rax
sarq $0x20, %rax
movq $-0x1, %rdi
cmovnsq %rax, %rdi
callq 0x3030
movq %rax, %r13
movslq %r14d, %r14
movq %rax, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x3190
movb $0x0, (%r13,%r14)
movq %r13, %rdi
movl $0x3a, %esi
callq 0x3120
testq %rax, %rax
je 0x6536
movb $0x0, (%rax)
incq %rax
movq %rax, %rdi
callq 0x3430
movl %eax, %ebp
jmp 0x653b
movl $0x1fbd, %ebp           # imm = 0x1FBD
leaq 0x48(%rsp), %r15
movq %r15, -0x10(%r15)
movq %r13, %rdi
callq 0x3150
movq %r13, %rdx
addq %rax, %rdx
leaq 0x38(%rsp), %r14
movq %r14, %rdi
movq %r13, %rsi
callq 0x425a
movq %r14, %rdi
movl %ebp, %esi
callq 0x4795
movq %rax, 0x10(%rbx)
movq 0x38(%rsp), %rdi
cmpq %r15, %rdi
movq 0x10(%rsp), %rbp
je 0x6584
callq 0x32f0
testq %rbp, %rbp
je 0x6643
movq %rbp, %rdi
callq 0x3150
movq %rax, %r14
shlq $0x20, %rax
movabsq $0x100000000, %rcx      # imm = 0x100000000
addq %rcx, %rax
sarq $0x20, %rax
movq $-0x1, %rdi
cmovnsq %rax, %rdi
callq 0x3030
movq %rax, %r12
movslq %r14d, %r14
movq %rax, %rdi
movq %rbp, %rsi
movq %r14, %rdx
callq 0x3190
movb $0x0, (%r12,%r14)
movq %r12, %rdi
movl $0x3a, %esi
callq 0x3120
testq %rax, %rax
je 0x65fa
movb $0x0, (%rax)
incq %rax
movq %rax, %rdi
callq 0x3430
movl %eax, %ebp
jmp 0x65ff
movl $0x1fbd, %ebp           # imm = 0x1FBD
leaq 0x28(%rsp), %r15
movq %r15, -0x10(%r15)
movq %r12, %rdi
callq 0x3150
movq %r12, %rdx
addq %rax, %rdx
leaq 0x18(%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x425a
movq %r14, %rdi
movl %ebp, %esi
callq 0x4795
movq %rax, 0x18(%rbx)
movq 0x18(%rsp), %rdi
cmpq %r15, %rdi
je 0x6643
callq 0x32f0
movq 0xb0(%rsp), %r12
testq %r12, %r12
je 0x669f
movq %r12, %rdi
callq 0x3150
movq %rax, %r14
shlq $0x20, %rax
movabsq $0x100000000, %rcx      # imm = 0x100000000
addq %rcx, %rax
sarq $0x20, %rax
movq $-0x1, %rdi
cmovnsq %rax, %rdi
callq 0x3030
movq %rax, %r15
movq %rax, 0x20(%rbx)
movslq %r14d, %rbx
movq %rax, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x3190
movb $0x0, (%r15,%rbx)
jmp 0x66aa
leaq 0x4bea(%rip), %rax      # 0xb290
movq %rax, 0x20(%rbx)
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x18(%rsp), %rdi
jmp 0x66d5
movq %rax, %rbx
movq 0x38(%rsp), %rdi
jmp 0x66d5
movq %rax, %rbx
movq 0x58(%rsp), %rdi
cmpq %r15, %rdi
je 0x66df
callq 0x32f0
movq %rbx, %rdi
callq 0x34b0
nop