// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/includes/dinit-env.h
// Function: environment::build(dinit_unordered_set<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, hash_sv, dinit_equal_to> const&) const
env_map build(const env_names &exclude) const
    {
        env_map mapping;

        if (keep_parent_env) {
            // import all from parent, excluding our own undefines + the exclude set
            if (bp_sys::environ != nullptr) {
                unsigned pos = 0;
                for (char **env = bp_sys::environ; *env != nullptr; ++env) {
                    // find '='
                    char *var_ch;
                    for (var_ch = *env; *var_ch != '='; ++var_ch) {
                        if (*var_ch == '\0') break;
                    }
                    // if this variable doesn't contain '=', ignore it
                    if (*var_ch == '\0') continue;
                    string_view name_view {*env, (size_t)(var_ch - *env)};

                    if (undefine.contains(name_view) || exclude.contains(name_view)) {
                        goto next_env_var;
                    }

                    mapping.env_list.push_back(*env);
                    mapping.var_map.insert({name_view, pos});
                    ++pos;

                    next_env_var: ;
                }
            }
        }
        else {
            // import specific items from parent
            for (const std::string &import_name : import_from_parent) {
                // POSIX allows that getenv return its result in a static, per-thread buffer. Since this is
                // ridiculous, we'll assume that all implementations do the sane thing of simply returning
                // a pointer to the value part of the NAME=VALUE string in the actual environment array:
                const char *value = getenv(import_name.c_str());
                if (value == nullptr) continue;
                // go back through the name and the '=' to the beginning of NAME=VALUE:
                const char *name_and_val = value - (import_name.length() + 1);
                mapping.var_map.insert({import_name, mapping.env_list.size()});
                mapping.env_list.push_back(name_and_val);
            }
        }

        // add our own (excluding exclude set)
        for (const std::string &set_var : set_vars) {
            size_t eq_pos = set_var.find('=');
            string_view set_var_name = string_view(set_var.data(), eq_pos);

            if (!exclude.contains(set_var_name)) {
                auto iter = mapping.var_map.find(set_var_name);
                if (iter != mapping.var_map.end()) {
                    unsigned pos = iter->second;
                    mapping.env_list[pos] = set_var.c_str();
                }
                else {
                    mapping.var_map[set_var_name] = mapping.env_list.size();
                    mapping.env_list.push_back(set_var.c_str());
                }
            }
        }
        mapping.env_list.push_back(nullptr);

        return mapping;
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdx, 0x50(%rsp)
movq %rsi, %r14
movq %rdi, %rbx
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
leaq 0x18(%rdi), %rax
movq %rax, 0x8(%rsp)
leaq 0x48(%rdi), %rax
movq %rax, 0x18(%rdi)
movq $0x1, 0x20(%rdi)
movups %xmm0, 0x28(%rdi)
movl $0x3f800000, 0x38(%rdi) # imm = 0x3F800000
movups %xmm0, 0x40(%rdi)
cmpb $0x1, (%rsi)
movq %rdi, (%rsp)
jne 0xe25f
movq 0x15dd6(%rip), %rax     # 0x23fa0
movq (%rax), %r13
testq %r13, %r13
je 0xe2e4
leaq 0x38(%r14), %rbp
xorl %r15d, %r15d
leaq 0x18(%rsp), %r12
movq (%r13), %rax
testq %rax, %rax
je 0xe2e4
xorl %ecx, %ecx
movzbl (%rax,%rcx), %edx
testl %edx, %edx
je 0xe259
cmpl $0x3d, %edx
je 0xe203
incq %rcx
jmp 0xe1f1
movq %rax, 0x18(%rsp)
movq %rcx, 0x20(%rsp)
movq %rbp, %rdi
movq %r12, %rsi
callq 0xe3f8
testb %al, %al
jne 0xe259
movq 0x50(%rsp), %rdi
movq %r12, %rsi
callq 0xe3f8
testb %al, %al
jne 0xe259
movq %rbx, %rdi
movq %r13, %rsi
callq 0xd1cc
movups 0x18(%rsp), %xmm0
movaps %xmm0, 0x30(%rsp)
movl %r15d, 0x40(%rsp)
movq 0x8(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0xe658
incl %r15d
addq $0x8, %r13
jmp 0xe1e2
leaq 0x8(%r14), %rsi
leaq 0x30(%rsp), %r12
movq %r12, %rdi
callq 0xea34
leaq 0x10(%rsp), %r13
movq 0x38(%rsp), %r15
movq 0x40(%rsp), %rax
notq %rax
orq %r15, %rax
je 0xe2e4
movq 0x10(%r15), %rbp
movq %rbp, %rdi
callq 0x4470
testq %rax, %rax
je 0xe2da
movq 0x18(%r15), %rcx
movq %rbp, 0x18(%rsp)
movq %rcx, 0x20(%rsp)
notq %rcx
addq %rcx, %rax
movq %rax, 0x10(%rsp)
movq 0x8(%rbx), %rax
subq (%rbx), %rax
shrq $0x3, %rax
movl %eax, 0x28(%rsp)
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0xe658
movq %rbx, %rdi
movq %r13, %rsi
callq 0xd1cc
movq %r12, %rdi
callq 0xe424
jmp 0xe275
addq $0x68, %r14
leaq 0x30(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
callq 0xea86
pushq $0x3d
popq %rbp
leaq 0x18(%rsp), %r12
movq 0x38(%rsp), %r15
movq 0x40(%rsp), %rax
notq %rax
orq %r15, %rax
je 0xe3b5
movq %r15, %r14
addq $0x10, %r15
movq %r15, %rdi
movl %ebp, %esi
xorl %edx, %edx
callq 0x44c0
movq 0x10(%r14), %rcx
movq %rcx, 0x18(%rsp)
movq %rax, 0x20(%rsp)
movq 0x50(%rsp), %rdi
movq %r12, %rsi
callq 0xe3f8
testb %al, %al
jne 0xe3a8
movq 0x8(%rsp), %rdi
movq %r12, %rsi
callq 0xead8
testq %rax, %rax
je 0xe36d
movl 0x18(%rax), %eax
movq (%r15), %rcx
movq (%rsp), %rbx
movq (%rbx), %rdx
movq %rcx, (%rdx,%rax,8)
jmp 0xe3a8
movq (%rsp), %rax
movq (%rax), %rbx
movq 0x8(%rax), %r14
movq 0x8(%rsp), %rdi
movq %r12, %rsi
callq 0xeb08
subq %rbx, %r14
shrq $0x3, %r14
movl %r14d, (%rax)
movq (%r15), %rax
movq %rax, 0x10(%rsp)
movq (%rsp), %rbx
movq %rbx, %rdi
leaq 0x10(%rsp), %rsi
callq 0xebe0
movq %r13, %rdi
callq 0xe482
jmp 0xe300
leaq 0x30(%rsp), %rsi
andq $0x0, (%rsi)
movq %rbx, %rdi
callq 0xebe0
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xe3e4
jmp 0xe3e4
jmp 0xe3e4
jmp 0xe3e4
jmp 0xe3e4
jmp 0xe3e4
movq %rax, %r14
movq (%rsp), %rdi
callq 0xcd72
movq %r14, %rdi
callq 0x4620