// File: /workspace/github_cpp_makefile_star2_O1/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r8, %r15
movq %rcx, %r12
movq %rsi, %r14
movq %rdi, %rbx
movq (%rdx), %r13
movl $0x1, %esi
cmpq $0xa, %r13
jb 0x1b351
movl $0x4, %esi
movabsq $0x346dc5d63886594b, %rdi # imm = 0x346DC5D63886594B
movq %r13, %rcx
cmpq $0x63, %rcx
jbe 0x1b34a
cmpq $0x3e7, %rcx            # imm = 0x3E7
jbe 0x1b34f
cmpq $0x2710, %rcx           # imm = 0x2710
jb 0x1b351
movq %rcx, %rax
mulq %rdi
shrq $0xb, %rdx
addl $0x4, %esi
cmpq $0x1869f, %rcx          # imm = 0x1869F
movq %rdx, %rcx
ja 0x1b314
addl $-0x3, %esi
jmp 0x1b351
addl $-0x2, %esi
jmp 0x1b351
decl %esi
movl %esi, %esi
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x8(%rsp), %rbp
movq %rbp, %rdi
xorl %edx, %edx
callq 0xb1d50
movq (%rbp), %rdi
movl 0x8(%rbp), %esi
movq %r13, %rdx
callq 0x26fa8
movq 0x8(%rbp), %rax
movq 0x8(%r14), %rcx
leaq (%rax,%rcx), %r13
addq $0x17, %r13
movq %r13, (%rbx)
movl (%r12), %eax
movl (%r15), %ecx
cmpl %ecx, %eax
je 0x1b3b6
leaq 0x28(%rsp), %rdi
movl %eax, (%rdi)
movl %ecx, 0x4(%rdi)
leaq 0x1122af(%rip), %rsi    # 0x12d658
movq %rdi, %rdx
callq 0x2712e
cltq
movq %rax, (%rbx)
movq (%rbx), %r15
movq %r15, %rax
subq %r13, %rax
cmpq $0x29, %rax
ja 0x1b3d2
movq %r15, %rdi
callq 0x36880
movq %rax, %rbx
jmp 0x1b3f6
addq $-0x2a, %r15
movq %r15, (%rbx)
movq %r15, %rdi
callq 0x36880
movq %rax, %rbx
leaq 0x110715(%rip), %rsi    # 0x12bb00
movq %rax, %rdi
movq %r15, %rdx
callq 0x16880
movb $0x3b, 0x14(%rbx)
leaq 0x15(%rbx), %rsi
leaq 0x8(%rsp), %rdi
movq 0x8(%rdi), %rdx
xorl %ecx, %ecx
callq 0xb3ca0
movq 0x10(%rsp), %r15
movb $0x3b, 0x15(%r15,%rbx)
leaq (%rbx,%r15), %rsi
addq $0x16, %rsi
movq 0x8(%r14), %rdx
movq %r14, %rdi
xorl %ecx, %ecx
callq 0xb3ca0
addq $0x16, %r15
addq 0x8(%r14), %r15
movb $0x3b, (%rbx,%r15)
callq 0x40070
movq %rax, %r15
movq %rax, %r14
negq %r14
cmovsq %rax, %r14
movl $0x1, %r12d
cmpq $0xa, %r14
jb 0x1b4ae
movl $0x4, %r12d
movabsq $0x346dc5d63886594b, %rsi # imm = 0x346DC5D63886594B
movq %r14, %rcx
cmpq $0x63, %rcx
jbe 0x1b4a5
cmpq $0x3e7, %rcx            # imm = 0x3E7
jbe 0x1b4ab
cmpq $0x2710, %rcx           # imm = 0x2710
jb 0x1b4ae
movq %rcx, %rax
mulq %rsi
shrq $0xb, %rdx
addl $0x4, %r12d
cmpq $0x1869f, %rcx          # imm = 0x1869F
movq %rdx, %rcx
ja 0x1b46d
addl $-0x3, %r12d
jmp 0x1b4ae
addl $-0x2, %r12d
jmp 0x1b4ae
decl %r12d
shrq $0x3f, %r15
leal (%r15,%r12), %esi
leaq 0x38(%rsp), %rbp
movq %rbp, -0x10(%rbp)
leaq 0x28(%rsp), %rdi
movl $0x2d, %edx
callq 0xb1d50
leaq 0x28(%rsp), %r13
addq (%r13), %r15
movq %r15, %rdi
movl %r12d, %esi
movq %r14, %rdx
callq 0x27023
leaq 0xc990c(%rip), %rcx     # 0xe4df8
movl $0xa, %esi
movl $0x1, %r8d
movq %r13, %rdi
xorl %edx, %edx
callq 0xb33e0
leaq 0x28(%rsp), %rdi
movq 0x8(%rdi), %rdx
movq %rbx, %rsi
xorl %ecx, %ecx
callq 0xb3ca0
movq 0x28(%rsp), %rdi
cmpq %rbp, %rdi
je 0x1b52b
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x35060
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x1b547
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x35060
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1b579
jmp 0x1b579
movq %rax, %rbx
movq 0x28(%rsp), %rdi
cmpq %rbp, %rdi
je 0x1b57c
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x35060
jmp 0x1b57c
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x1b598
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x35060
movq %rbx, %rdi
callq 0xe0cd0