// File: /workspace/github_cpp_makefile_star2_O2/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, 0x8(%rsp)
movq %r8, %r13
movq %rdx, %rbp
movq %rsi, 0x10(%rsp)
movq %rdi, %rbx
movl 0xb8(%rsp), %eax
movl %ecx, 0x8(%rdi)
movl %eax, 0x28(%rdi)
movq (%rdx), %rdi
leaq 0x4(%rsp), %rsi
callq 0x2200
pushq $-0x1
popq %r14
testl %eax, %eax
je 0x4c54
leaq 0x4(%rsp), %rdi
pushq $0x4
popq %rsi
pushq $0x2
popq %rdx
callq 0x2380
testq %rax, %rax
je 0x4c54
movq (%rax), %rbp
movq %rbp, %rdi
callq 0x2140
movq %rax, %r15
movq %rax, %rdi
shlq $0x20, %rdi
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %rdi
sarq $0x20, %rdi
cmovsq %r14, %rdi
callq 0x2030
movq %rax, %r12
movq %rax, (%rbx)
movslq %r15d, %r15
movq %rax, %rdi
movq %rbp, %rsi
jmp 0x4c89
movq 0x8(%rbp), %r15
movq %r15, %rdi
shlq $0x20, %rdi
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %rdi
sarq $0x20, %rdi
cmovsq %r14, %rdi
callq 0x2030
movq %rax, %r12
movq %rax, (%rbx)
movq (%rbp), %rsi
movslq %r15d, %r15
movq %rax, %rdi
movq %r15, %rdx
callq 0x2190
movq %r12, %rax
addq %r15, %rax
movb $0x0, (%rax)
movq 0x8(%rsp), %rcx
movzbl (%r12), %eax
cmpl $0x2e, %eax
je 0x4caf
testl %eax, %eax
jne 0x4cb4
jmp 0x4cb9
movb $0x5f, (%r12)
incq %r12
jmp 0x4c9f
movq %r13, %rax
orq %rcx, %rax
je 0x4e35
leaq 0x58(%rsp), %r15
movq %r15, %rdi
movq 0x10(%rsp), %rsi
callq 0x2390
movq %r15, %rdi
xorl %esi, %esi
callq 0x31fd
movl %eax, 0xc(%rbx)
leaq 0x58(%rsp), %rdi
callq 0x2160
testq %r13, %r13
je 0x4d8f
movq %r13, %rdi
callq 0x2140
movq %rax, %r15
movq %rax, %rdi
shlq $0x20, %rdi
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %rdi
sarq $0x20, %rdi
cmovsq %r14, %rdi
callq 0x2030
movq %rax, %r12
movslq %r15d, %r15
movq %rax, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x2190
movb $0x0, (%r12,%r15)
pushq $0x3a
popq %rsi
movq %r12, %rdi
callq 0x2110
testq %rax, %rax
je 0x4d5e
movb $0x0, (%rax)
incq %rax
movq %rax, %rdi
callq 0x2400
movl %eax, %ebp
jmp 0x4d63
movl $0x1fbd, %ebp           # imm = 0x1FBD
leaq 0x38(%rsp), %rdi
leaq 0x3(%rsp), %rdx
movq %r12, %rsi
callq 0x2120
leaq 0x38(%rsp), %rdi
movl %ebp, %esi
callq 0x32fa
movq %rax, 0x10(%rbx)
leaq 0x38(%rsp), %rdi
callq 0x2160
movq 0x8(%rsp), %r13
testq %r13, %r13
je 0x4e35
movq %r13, %rdi
callq 0x2140
movq %rax, %r15
movq %rax, %rdi
shlq $0x20, %rdi
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %rdi
sarq $0x20, %rdi
cmovsq %r14, %rdi
callq 0x2030
movq %rax, %r12
movslq %r15d, %r15
movq %rax, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x2190
movb $0x0, (%r12,%r15)
pushq $0x3a
popq %rsi
movq %r12, %rdi
callq 0x2110
testq %rax, %rax
je 0x4e04
movb $0x0, (%rax)
incq %rax
movq %rax, %rdi
callq 0x2400
movl %eax, %ebp
jmp 0x4e09
movl $0x1fbd, %ebp           # imm = 0x1FBD
leaq 0x18(%rsp), %rdi
leaq 0x3(%rsp), %rdx
movq %r12, %rsi
callq 0x2120
leaq 0x18(%rsp), %rdi
movl %ebp, %esi
callq 0x32fa
movq %rax, 0x18(%rbx)
leaq 0x18(%rsp), %rdi
callq 0x2160
movq 0xb0(%rsp), %r12
testq %r12, %r12
je 0x4e8d
movq %r12, %rdi
callq 0x2140
movq %rax, %r15
shlq $0x20, %rax
movabsq $0x100000000, %rcx      # imm = 0x100000000
addq %rcx, %rax
sarq $0x20, %rax
cmovnsq %rax, %r14
movq %r14, %rdi
callq 0x2030
movq %rax, %r14
movq %rax, 0x20(%rbx)
movslq %r15d, %rbx
movq %rax, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x2190
movb $0x0, (%r14,%rbx)
jmp 0x4e98
leaq 0x53dc(%rip), %rax      # 0xa270
movq %rax, 0x20(%rbx)
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
jmp 0x4eca
jmp 0x4ebd
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
jmp 0x4eca
movq %rax, %rbx
jmp 0x4ecf
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x2160
movq %rbx, %rdi
callq 0x2470
nop