// File: /workspace/github_cpp_makefile_star2_O1/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 0x2a415
movl $0x2, 0x7c(%rbx)
movb $0x1, %bpl
jmp 0x2a552
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 0x2a45e
leaq 0x18(%rsp), %rsi
movb $0x34, (%rsi)
movq %rbx, %rdi
movl $0x1, %edx
callq 0x27fd2
movl %eax, %ebp
testb %al, %al
je 0x2a552
movb $0x1, 0x78(%rbx)
jmp 0x2a552
xorps %xmm0, %xmm0
movq %rsp, %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movl $0x9, %esi
callq 0x1c132
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 0x1e96c(%rip), %rsi     # 0x48e10
leaq 0x18(%rsp), %rdi
callq 0x1ab0c
movq 0x18(%rsp), %r13
movq 0x20(%rsp), %rbp
cmpq %rbp, %r13
je 0x2a4f4
movq %rsp, %r14
movq (%r13), %r15
testq %r15, %r15
je 0x2a4eb
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 0x2d810
addq $0x8, %r13
cmpq %rbp, %r13
jne 0x2a4c0
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 0x2ada4
movl %eax, %ebp
leaq 0x30(%rsp), %rbx
movq %rbx, %rdi
callq 0x1e478
movq -0x18(%rbx), %rdi
testq %rdi, %rdi
je 0x2a53c
movq 0x28(%rsp), %rsi
subq %rdi, %rsi
callq 0x8620
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x2a552
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 0x2a565
movq %rax, %rbx
jmp 0x2a577
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x1b630
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x2a58d
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x8620
movq %rbx, %rdi
callq 0x8ab0
nop