// File: /workspace/github_cpp_makefile_star2_O1/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 $0x68, %rsp
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
leaq 0x18(%rdi), %rax
movq %rax, 0x48(%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, 0x20(%rsp)
jne 0x1307d
movq 0x1302a(%rip), %rax     # 0x25fa8
movq (%rax), %r13
testq %r13, %r13
je 0x13196
movq (%r13), %rax
testq %rax, %rax
je 0x13196
leaq 0x38(%r15), %rbp
movl $0x0, 0x44(%rsp)
movq %rsp, %r12
movq %r15, 0x60(%rsp)
movq %rax, %rcx
movzbl (%rcx), %edx
testl %edx, %edx
je 0x13067
cmpl $0x3d, %edx
je 0x12fc6
incq %rcx
incq %rax
jmp 0x12fae
movq (%r13), %rcx
subq %rcx, %rax
movq %rcx, 0x28(%rsp)
movq %rax, 0x30(%rsp)
movq %r12, %rdi
movq %rbp, %rsi
leaq 0x28(%rsp), %rdx
callq 0x13336
cmpq $-0x1, 0x10(%rsp)
jne 0x13067
cmpq $0x0, 0x8(%rsp)
jne 0x13067
movq %r12, %rdi
movq %r14, %rsi
leaq 0x28(%rsp), %rdx
callq 0x13336
cmpq $-0x1, 0x10(%rsp)
jne 0x13067
cmpq $0x0, 0x8(%rsp)
jne 0x13067
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x1302f
movq (%r13), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%rbx)
jmp 0x1303a
movq %rbx, %rdi
movq %r13, %rdx
callq 0x121c0
movups 0x28(%rsp), %xmm0
movaps %xmm0, (%rsp)
movl 0x44(%rsp), %r15d
movl %r15d, 0x10(%rsp)
movq 0x48(%rsp), %rdi
movq %r12, %rsi
callq 0x1347c
incl %r15d
movl %r15d, 0x44(%rsp)
movq 0x60(%rsp), %r15
movq 0x8(%r13), %rax
addq $0x8, %r13
testq %rax, %rax
jne 0x12fab
jmp 0x13196
leaq 0x8(%r15), %rsi
movq %rsp, %r12
movq %r12, %rdi
callq 0x13840
movq 0x8(%r12), %rbp
movq 0x10(%r12), %rax
notq %rax
orq %rbp, %rax
je 0x13196
movabsq $-0x5555555555555555, %r12 # imm = 0xAAAAAAAAAAAAAAAB
leaq 0x28(%rsp), %r13
movq 0x10(%rbp), %rdi
callq 0x4470
testq %rax, %rax
je 0x13121
movq 0x18(%rbp), %rcx
movq %rcx, %rdx
notq %rdx
addq %rdx, %rax
movq %rax, 0x50(%rsp)
movq 0x8(%rbx), %rax
subq (%rbx), %rax
shrq $0x3, %rax
movq 0x10(%rbp), %rdx
movq %rdx, 0x28(%rsp)
movq %rcx, 0x30(%rsp)
movl %eax, 0x38(%rsp)
movq 0x48(%rsp), %rdi
movq %r13, %rsi
callq 0x1347c
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x13114
movq 0x50(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%rbx)
jmp 0x13121
movq %rbx, %rdi
leaq 0x50(%rsp), %rdx
callq 0x121c0
movq (%rsp), %rdx
movq 0x8(%rsp), %rax
movq (%rax), %rdi
movq %rdi, 0x8(%rsp)
movq 0x10(%rsp), %rax
movq (%rdx), %rsi
leaq (%rax,%rax,2), %rcx
leaq (%rsi,%rcx,8), %rcx
cmpq %rcx, %rdi
jne 0x13180
movq 0x8(%rdx), %rdx
subq %rsi, %rdx
sarq $0x3, %rdx
imulq %r12, %rdx
incq %rax
cmpq %rdx, %rax
jae 0x1316d
movq 0x18(%rcx), %rsi
addq $0x18, %rcx
cmpq %rsi, %rcx
je 0x13156
jmp 0x13176
movq $-0x1, %rax
xorl %esi, %esi
movq %rsi, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movq 0x8(%rsp), %rbp
movq 0x10(%rsp), %rax
notq %rax
orq %rbp, %rax
jne 0x130b1
addq $0x68, %r15
leaq 0x28(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x138c8
movq 0x8(%r12), %r15
movq 0x10(%r12), %rax
notq %rax
orq %r15, %rax
je 0x132ec
movq %rsp, %r12
leaq 0x50(%rsp), %rbx
leaq 0x10(%r15), %rbp
movq %rbp, %rdi
movl $0x3d, %esi
xorl %edx, %edx
callq 0x44b0
movq 0x10(%r15), %rcx
movq %rcx, 0x50(%rsp)
movq %rax, 0x58(%rsp)
movq %r12, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x13336
cmpq $-0x1, 0x10(%rsp)
jne 0x1326c
cmpq $0x0, 0x8(%rsp)
jne 0x1326c
movq 0x48(%rsp), %rdi
movq %rbx, %r13
movq %rbx, %rsi
callq 0x13950
testq %rax, %rax
je 0x13231
movl 0x18(%rax), %eax
movq (%rbp), %rcx
movq 0x20(%rsp), %rdx
movq (%rdx), %rdx
movq %rcx, (%rdx,%rax,8)
jmp 0x13269
movq 0x20(%rsp), %rax
movq (%rax), %rbx
movq 0x8(%rax), %r15
movq 0x48(%rsp), %rdi
movq %r13, %rsi
callq 0x139fc
subq %rbx, %r15
shrq $0x3, %r15
movl %r15d, (%rax)
movq (%rbp), %rax
movq %rax, (%rsp)
movq 0x20(%rsp), %rdi
movq %r12, %rsi
callq 0x13b0e
movq %r13, %rbx
movq 0x28(%rsp), %rdx
movq 0x30(%rsp), %rax
movq (%rax), %rdi
movq %rdi, 0x30(%rsp)
movq 0x38(%rsp), %rax
movq (%rdx), %rsi
leaq (%rax,%rax,2), %rcx
leaq (%rsi,%rcx,8), %rcx
cmpq %rcx, %rdi
jne 0x132d6
movq 0x8(%rdx), %rdx
subq %rsi, %rdx
sarq $0x3, %rdx
movabsq $-0x5555555555555555, %rsi # imm = 0xAAAAAAAAAAAAAAAB
imulq %rsi, %rdx
incq %rax
cmpq %rdx, %rax
jae 0x132c3
movq 0x18(%rcx), %rsi
addq $0x18, %rcx
cmpq %rsi, %rcx
je 0x132ac
jmp 0x132cc
movq $-0x1, %rax
xorl %esi, %esi
movq %rsi, 0x30(%rsp)
movq %rax, 0x38(%rsp)
movq 0x30(%rsp), %r15
movq 0x38(%rsp), %rax
notq %rax
orq %r15, %rax
jne 0x131c8
movq %rsp, %rsi
movq $0x0, (%rsi)
movq 0x20(%rsp), %rbx
movq %rbx, %rdi
callq 0x13b0e
movq %rbx, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x13321
jmp 0x13321
jmp 0x13321
jmp 0x13321
jmp 0x13321
jmp 0x13321
movq %rax, %r14
movq 0x20(%rsp), %rdi
callq 0x11c9c
movq %r14, %rdi
callq 0x4630