// File: /workspace/github_cpp_makefile_star2_O3/davmac314[P]dinit/src/control.cc
// Function: control_conn_t::process_getallenv()
bool control_conn_t::process_getallenv()
{
    // 1 byte packet type
    // 1 byte reserved - must be 0

    constexpr int pkt_size = 2;
    if (rbuf.get_length() < pkt_size) {
        chklen = pkt_size;
        return true;
    }

    uint8_t reserved_byte = rbuf[1];
    if (reserved_byte != 0) {
        char badreqRep[] = { (char)cp_rply::BADREQ };
        if (!queue_packet(badreqRep, 1)) return false;
        bad_conn_close = true;
        return true;
    }

    // The reply looks like:
    // 1 byte - reply type
    // sizeof(size_t) - reply data size
    // n bytes - reply data (NAME=VALUE, separated by nul characters)

    std::vector<char> env_block;
    constexpr size_t env_block_hdr_size = sizeof(size_t) + 1;
    env_block.resize(env_block_hdr_size);

    rbuf.consume(pkt_size);
    auto env = main_env.build();
    for (const char *env_var : env.env_list) {
        if (env_var != nullptr) {
            env_block.insert(env_block.end(), env_var, env_var + strlen(env_var) + 1);
        }
    }

    env_block[0] = (char)cp_rply::ALLENV;
    size_t block_size = env_block.size() - env_block_hdr_size;
    memcpy(env_block.data() + 1, &block_size, sizeof(block_size));
    if (!queue_packet(std::move(env_block))) return false;
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
cmpl $0x1, 0x484(%rdi)
ja 0x2a2e3
movl $0x2, 0x7c(%rbx)
movb $0x1, %bpl
jmp 0x2a420
movl 0x480(%rbx), %eax
leal 0x1(%rax), %ecx
addl $0xfffffc01, %eax       # imm = 0xFFFFFC01
cmpl $0x400, %ecx            # imm = 0x400
cmovbl %ecx, %eax
cmpb $0x0, 0x80(%rbx,%rax)
je 0x2a32c
leaq 0x18(%rsp), %rsi
movb $0x34, (%rsi)
movq %rbx, %rdi
movl $0x1, %edx
callq 0x28036
movl %eax, %ebp
testb %al, %al
je 0x2a420
movb $0x1, 0x78(%rbx)
jmp 0x2a420
xorps %xmm0, %xmm0
movq %rsp, %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movl $0x9, %esi
callq 0x1c190
movl 0x480(%rbx), %eax
leal 0x2(%rax), %ecx
addl $0xfffffc02, %eax       # imm = 0xFFFFFC02
cmpl $0x400, %ecx            # imm = 0x400
cmovbl %ecx, %eax
movl %eax, 0x480(%rbx)
addl $-0x2, 0x484(%rbx)
leaq 0x1ea9e(%rip), %rsi     # 0x48e10
leaq 0x18(%rsp), %rdi
callq 0x1aaa6
movq 0x18(%rsp), %r13
movq 0x20(%rsp), %rbp
cmpq %rbp, %r13
je 0x2a3c2
movq %rsp, %r14
movq (%r13), %r15
testq %r15, %r15
je 0x2a3b9
movq 0x8(%rsp), %r12
movq %r15, %rdi
callq 0x8230
leaq (%r15,%rax), %rcx
incq %rcx
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x2d5c8
addq $0x8, %r13
cmpq %rbp, %r13
jne 0x2a38e
movq %rsp, %rsi
movq (%rsi), %rax
movb $0x4e, (%rax)
movq (%rsi), %rax
movq 0x8(%rsi), %rcx
subq %rax, %rcx
addq $-0x9, %rcx
movq %rcx, 0x1(%rax)
movq %rbx, %rdi
callq 0x2acb2
movl %eax, %ebp
leaq 0x30(%rsp), %rbx
movq %rbx, %rdi
callq 0x1e4ee
movq -0x18(%rbx), %rdi
testq %rdi, %rdi
je 0x2a40a
movq 0x28(%rsp), %rsi
subq %rdi, %rsi
callq 0x8620
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x2a420
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x8620
movl %ebp, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2a433
movq %rax, %rbx
jmp 0x2a445
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x1b6c4
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x2a45b
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x8620
movq %rbx, %rdi
callq 0x8ab0
nop