// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/control.cc
// Function: control_conn_t::process_setenv()
bool control_conn_t::process_setenv()
{
    using std::string;

    string envVar;
    typename string::size_type eq;

    constexpr int pkt_size = 4;
    char badreqRep[] = { (char)cp_rply::BADREQ };
    char okRep[] = { (char)cp_rply::ACK };

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

    envvar_len_t envvar_len;
    rbuf.extract(&envvar_len, 1, sizeof(envvar_len));
    if (envvar_len <= 0 || envvar_len > (1024 - 3)) {
        goto badreq;
    }
    chklen = envvar_len + 1 + sizeof(envvar_len); // packet type + (2 byte) length + envvar

    if (rbuf.get_length() < chklen) {
        // packet not complete yet; read more
        return true;
    }

    envVar = rbuf.extract_string(3, envvar_len);

    eq = envVar.find('=');
    if (eq == envVar.npos) {
        // Unset the env var
        main_env.undefine_var(std::move(envVar), true);
    }
    else if (eq) {
        // Regular set
        main_env.set_var(std::move(envVar), true);
    }
    else {
        // At the beginning of the string
        goto badreq;
    }

    // Success response
    if (!queue_packet(okRep, 1)) return false;

    // Clear the packet from the buffer
    rbuf.consume(chklen);
    chklen = 0;
    return true;

badreq:
    // Queue error response / mark connection bad
    if (!queue_packet(badreqRep, 1)) return false;
    bad_conn_close = true;
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x50, %rsp
movq %rdi, %rbx
leaq 0x20(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movb $0x34, 0xd(%rsp)
movb $0x32, 0xc(%rsp)
cmpl $0x3, 0x484(%rdi)
ja 0x24c40
movl $0x4, 0x7c(%rbx)
jmp 0x24c89
leaq 0x80(%rbx), %r14
leaq 0xe(%rsp), %r15
pushq $0x1
popq %rdx
pushq $0x2
popq %rcx
movq %r14, %rdi
movq %r15, %rsi
callq 0x25e18
movzwl (%r15), %ecx
leal -0x3fe(%rcx), %eax
cmpw $0xfc03, %ax            # imm = 0xFC03
jae 0x24c91
leaq 0xd(%rsp), %rsi
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x234ec
testb %al, %al
je 0x24d3a
movb $0x1, 0x78(%rbx)
movb $0x1, %bpl
jmp 0x24d3c
leal 0x3(%rcx), %eax
movl %eax, 0x7c(%rbx)
movb $0x1, %bpl
cmpl %eax, 0x484(%rbx)
jb 0x24d3c
leaq 0x30(%rsp), %rdi
pushq $0x3
popq %rdx
movq %r14, %rsi
callq 0x25e94
leaq 0x10(%rsp), %r15
leaq 0x30(%rsp), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x8730
movq %r12, %rdi
callq 0x8b98
pushq $0x3d
popq %rsi
movq %r15, %rdi
xorl %edx, %edx
callq 0x87e0
testq %rax, %rax
je 0x24c6d
cmpq $-0x1, %rax
jne 0x24d01
leaq 0x2311e(%rip), %rdi     # 0x47e10
leaq 0x10(%rsp), %rsi
pushq $0x1
popq %rdx
callq 0x262ce
jmp 0x24d15
leaq 0x23108(%rip), %rdi     # 0x47e10
leaq 0x10(%rsp), %rsi
pushq $0x1
popq %rdx
callq 0x16b26
leaq 0xc(%rsp), %rsi
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x234ec
testb %al, %al
je 0x24d3a
movl 0x7c(%rbx), %esi
movq %r14, %rdi
callq 0x25df2
andl $0x0, 0x7c(%rbx)
jmp 0x24d3c
xorl %ebp, %ebp
leaq 0x10(%rsp), %rdi
callq 0x8b98
movl %ebp, %eax
addq $0x50, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
jmp 0x24d57
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x8b98
movq %rbx, %rdi
callq 0x8a90