// File: /workspace/github_cpp_makefile_star2_O2/greenpau[P]mnpa/main.cpp
// Function: gen_pkt_payload(unsigned long&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, unsigned long long&, unsigned int&, unsigned int&)
const char * gen_pkt_payload(size_t& pkt_content_size, std::string& pkt_tag, unsigned long long& pi, unsigned int& psl, unsigned int& psh) {
    size_t ptr_pos = 0;
    char * pkt_content = nullptr;
    // pre-populated fields: 65 chars
    //  * headers:   42 chars, i.e. Ethernet (14 bytes), IP (20 bytes) and UDP (8 bytes)
    //  * timestamp: 20 chars
    //  * separators: 3 chars
    //  * id:         x chars
    //  * tag:        y chars
    std::string pkt_id = std::to_string(pi);
    size_t pkt_header_size = 23 + pkt_id.size() + pkt_tag.size();
    pkt_content_size = pkt_header_size;
    // randomize a packet size
    if (psl != psh) {
        std::uniform_int_distribution<> distr(psl, psh);
        pkt_content_size = distr(eng);
    }
    //printf("pkt_content_size: %zu\n", pkt_content_size);
    //printf("pkt_header_size: %zu\n", pkt_header_size);
    if ((pkt_content_size - pkt_header_size) < 42)  {
        //printf("new pkt_content_size (for header packets only): %zu\n", pkt_content_size);
        pkt_content = new char[pkt_content_size];
    } else {
        pkt_content_size -= 42;
        pkt_content = new char[pkt_content_size];
        memcpy(pkt_content, rand_pkt_payload, pkt_content_size);
        //printf("new pkt_content_size: %zu\n", pkt_content_size);
    }
    // setting the pointer's position to 20, because taking ns timestamp closer to the end of
    // this function improves accuracy of measurements.
    ptr_pos = 20;
    pkt_content[ptr_pos] = ';';
    ptr_pos++;
    pkt_id.copy(pkt_content+ptr_pos, pkt_id.size(), 0);
    ptr_pos += pkt_id.size();
    pkt_content[ptr_pos] = ';';
    ptr_pos++;
    pkt_tag.copy(pkt_content+ptr_pos, pkt_tag.size(), 0);
    ptr_pos += pkt_tag.size();
    pkt_content[ptr_pos] = ';';
    ptr_pos++;
    std::string nts = std::to_string(duration_cast<nanoseconds>(high_resolution_clock::now().time_since_epoch()).count());
    nts.insert(10,".");
    nts.copy(pkt_content, nts.size(), 0);
    return pkt_content;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x40, %rsp
movq %r8, %r15
movq %rcx, %r12
movq %rsi, %rbx
movq %rdi, %r14
movq (%rdx), %rsi
leaq 0x20(%rsp), %r13
movq %r13, %rdi
callq 0x1dece
movq 0x8(%r13), %rax
movq 0x8(%rbx), %rcx
leaq (%rax,%rcx), %r13
addq $0x17, %r13
movq %r13, (%r14)
movl (%r12), %eax
movl (%r15), %ecx
movq %r13, %r15
cmpl %ecx, %eax
je 0x19656
movq %rsp, %rdi
movl %eax, (%rdi)
movl %ecx, 0x4(%rdi)
leaq 0x10c00d(%rip), %rsi    # 0x125658
callq 0x1dcf4
movslq %eax, %r15
movq %r15, (%r14)
movq %r15, %rax
subq %r13, %rax
cmpq $0x29, %rax
ja 0x1966f
movq %r15, %rdi
callq 0x2c690
movq %rax, %r14
jmp 0x19693
addq $-0x2a, %r15
movq %r15, (%r14)
movq %r15, %rdi
callq 0x2c690
movq %rax, %r14
leaq 0x10a478(%rip), %rsi    # 0x123b00
movq %rax, %rdi
movq %r15, %rdx
callq 0x15870
movb $0x3b, 0x14(%r14)
leaq 0x15(%r14), %rsi
leaq 0x20(%rsp), %rdi
movq 0x8(%rdi), %rdx
xorl %ecx, %ecx
callq 0xa8fe0
movq 0x28(%rsp), %r15
movb $0x3b, 0x15(%r15,%r14)
leaq (%r14,%r15), %rsi
addq $0x16, %rsi
movq 0x8(%rbx), %rdx
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0xa8fe0
addq $0x16, %r15
addq 0x8(%rbx), %r15
movb $0x3b, (%r14,%r15)
callq 0x35420
movq %rsp, %rdi
movq %rax, %rsi
callq 0x1df10
leaq 0xc1707(%rip), %rdx     # 0xdadf8
movq %rsp, %rdi
pushq $0xa
popq %rsi
callq 0xa8890
movq %rsp, %rdi
movq 0x8(%rdi), %rdx
movq %r14, %rsi
xorl %ecx, %ecx
callq 0xa8fe0
movq %rsp, %rdi
callq 0xa7730
leaq 0x20(%rsp), %rdi
callq 0xa7730
movq %r14, %rax
addq $0x40, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
jmp 0x19741
jmp 0x19741
movq %rax, %rbx
movq %rsp, %rdi
callq 0xa7730
jmp 0x19744
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0xa7730
movq %rbx, %rdi
callq 0xd6ab0