// File: /workspace/github_cpp_makefile_star2_O3/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 %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %rbx
leaq 0x18(%rsp), %r13
movq %r13, -0x10(%r13)
movq $0x0, -0x8(%r13)
movb $0x0, (%r13)
movb $0x34, 0x5(%rsp)
movb $0x32, 0x4(%rsp)
movl 0x484(%rdi), %ebp
cmpl $0x3, %ebp
ja 0x2a0d7
movl $0x4, 0x7c(%rbx)
movb $0x1, %r15b
jmp 0x2a284
leaq 0x80(%rbx), %r14
movl 0x480(%rbx), %r15d
leal 0x1(%r15), %eax
movl $0xfffffc01, %ecx       # imm = 0xFFFFFC01
addl %ecx, %r15d
cmpl $0x400, %eax            # imm = 0x400
cmovbl %eax, %r15d
addl %r15d, %ecx
cmpl $0xfffffbfe, %ecx       # imm = 0xFFFFFBFE
ja 0x2a145
movl $0x400, %r13d           # imm = 0x400
subl %r15d, %r13d
movl %r15d, %esi
addq %r14, %rsi
leaq 0x6(%rsp), %r12
movq %r12, %rdi
movq %r13, %rdx
callq 0x84d0
leaq (%rsp,%r13), %rdi
addq $0x6, %rdi
leaq 0x18(%rsp), %r13
addl $0xfffffc02, %r15d      # imm = 0xFFFFFC02
movq %r14, %rsi
movq %r15, %rdx
callq 0x84d0
jmp 0x2a14b
movl %r15d, %r12d
addq %r14, %r12
movzwl (%r12), %ecx
leal -0x3fe(%rcx), %eax
movzwl %ax, %eax
cmpl $0xfc03, %eax           # imm = 0xFC03
jae 0x2a186
leaq 0x5(%rsp), %rsi
movq %rbx, %rdi
movl $0x1, %edx
callq 0x28036
testb %al, %al
je 0x2a26a
movb $0x1, 0x78(%rbx)
movb $0x1, %r15b
jmp 0x2a26d
leal 0x3(%rcx), %eax
movl %eax, 0x7c(%rbx)
movb $0x1, %r15b
cmpl %eax, %ebp
jb 0x2a26d
leaq 0x28(%rsp), %rdi
movq %r14, %rsi
movl $0x3, %edx
callq 0x2b760
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %r14
movq %r14, %rsi
callq 0x8740
movq (%r14), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x2a1d5
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x8620
leaq 0x8(%rsp), %rdi
movl $0x3d, %esi
xorl %edx, %edx
callq 0x87e0
testq %rax, %rax
je 0x2a160
cmpq $-0x1, %rax
jne 0x2a20d
leaq 0x1ec14(%rip), %rdi     # 0x48e10
leaq 0x8(%rsp), %rsi
movl $0x1, %edx
callq 0x2bbbe
jmp 0x2a223
leaq 0x1ebfc(%rip), %rdi     # 0x48e10
leaq 0x8(%rsp), %rsi
movl $0x1, %edx
callq 0x1af98
leaq 0x4(%rsp), %rsi
movq %rbx, %rdi
movl $0x1, %edx
callq 0x28036
testb %al, %al
je 0x2a26a
movl 0x7c(%rbx), %eax
movl 0x480(%rbx), %ecx
leal (%rcx,%rax), %edx
cmpl $0x400, %edx            # imm = 0x400
leal -0x400(%rcx,%rax), %ecx
cmovbl %edx, %ecx
movl %ecx, 0x480(%rbx)
subl %eax, 0x484(%rbx)
movl $0x0, 0x7c(%rbx)
jmp 0x2a26d
xorl %r15d, %r15d
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x2a284
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x8620
movl %r15d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2a298
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x2a2b2
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x8620
movq %rbx, %rdi
callq 0x8ab0