// File: /workspace/github_cpp_makefile_star2_O1/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), %r12
movq %r12, -0x10(%r12)
movq $0x0, -0x8(%r12)
movb $0x0, (%r12)
movb $0x34, 0x5(%rsp)
movb $0x32, 0x4(%rsp)
cmpl $0x3, 0x484(%rdi)
ja 0x2a200
movl $0x4, 0x7c(%rbx)
jmp 0x2a2ad
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 0x2a26d
movq %r12, %rbp
movl $0x400, %r12d           # imm = 0x400
subl %r15d, %r12d
movl %r15d, %esi
addq %r14, %rsi
leaq 0x6(%rsp), %r13
movq %r13, %rdi
movq %r12, %rdx
callq 0x84d0
addq %r13, %r12
addl $0xfffffc02, %r15d      # imm = 0xFFFFFC02
movq %r12, %rdi
movq %rbp, %r12
movq %r14, %rsi
movq %r15, %rdx
callq 0x84d0
jmp 0x2a27a
movl %r15d, %eax
movzwl (%r14,%rax), %eax
movw %ax, 0x6(%rsp)
movzwl 0x6(%rsp), %ecx
leal -0x3fe(%rcx), %eax
movzwl %ax, %eax
cmpl $0xfc03, %eax           # imm = 0xFC03
jae 0x2a2b5
leaq 0x5(%rsp), %rsi
movq %rbx, %rdi
movl $0x1, %edx
callq 0x27fd2
testb %al, %al
je 0x2a39d
movb $0x1, 0x78(%rbx)
movb $0x1, %bpl
jmp 0x2a39f
leal 0x3(%rcx), %eax
movl %eax, 0x7c(%rbx)
movb $0x1, %bpl
cmpl %eax, 0x484(%rbx)
jb 0x2a39f
leaq 0x28(%rsp), %rdi
movq %r14, %rsi
movl $0x3, %edx
callq 0x2b8c0
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %r14
movq %r14, %rsi
callq 0x8740
movq (%r14), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x2a308
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x8620
leaq 0x8(%rsp), %rdi
movl $0x3d, %esi
xorl %edx, %edx
callq 0x87e0
testq %rax, %rax
je 0x2a28f
cmpq $-0x1, %rax
jne 0x2a340
leaq 0x1eae1(%rip), %rdi     # 0x48e10
leaq 0x8(%rsp), %rsi
movl $0x1, %edx
callq 0x2bd1e
jmp 0x2a356
leaq 0x1eac9(%rip), %rdi     # 0x48e10
leaq 0x8(%rsp), %rsi
movl $0x1, %edx
callq 0x1afe0
leaq 0x4(%rsp), %rsi
movq %rbx, %rdi
movl $0x1, %edx
callq 0x27fd2
testb %al, %al
je 0x2a39d
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 0x2a39f
xorl %ebp, %ebp
movq 0x8(%rsp), %rdi
cmpq %r12, %rdi
je 0x2a3b6
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x8620
movl %ebp, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2a3c9
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r12, %rdi
je 0x2a3e3
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x8620
movq %rbx, %rdi
callq 0x8ab0
nop