// File: /workspace/github_cpp_makefile_star2_O3/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, 0x40(%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 0x1327e
movq 0x12e20(%rip), %rax     # 0x25fa8
movq (%rax), %r13
testq %r13, %r13
je 0x13399
movq (%r13), %rax
testq %rax, %rax
je 0x13399
leaq 0x38(%r15), %rbp
movq $0x0, 0x48(%rsp)
movq %rsp, %r12
movq %r15, 0x60(%rsp)
xorl %ecx, %ecx
movzbl (%rax,%rcx), %edx
testl %edx, %edx
je 0x13268
cmpl $0x3d, %edx
je 0x131ce
incq %rcx
jmp 0x131b8
movq %rax, 0x28(%rsp)
movq %rcx, 0x30(%rsp)
movq %r12, %rdi
movq %rbp, %rsi
leaq 0x28(%rsp), %rdx
callq 0x13538
cmpq $-0x1, 0x10(%rsp)
jne 0x13268
cmpq $0x0, 0x8(%rsp)
jne 0x13268
movq %r12, %rdi
movq %r14, %rsi
leaq 0x28(%rsp), %rdx
callq 0x13538
cmpq $-0x1, 0x10(%rsp)
jne 0x13268
cmpq $0x0, 0x8(%rsp)
jne 0x13268
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x13230
movq (%r13), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%rbx)
jmp 0x1323b
movq %rbx, %rdi
movq %r13, %rdx
callq 0x1249e
movups 0x28(%rsp), %xmm0
movaps %xmm0, (%rsp)
movq 0x48(%rsp), %r15
movl %r15d, 0x10(%rsp)
movq 0x40(%rsp), %rdi
movq %r12, %rsi
callq 0x1367e
incl %r15d
movq %r15, 0x48(%rsp)
movq 0x60(%rsp), %r15
movq 0x8(%r13), %rax
addq $0x8, %r13
testq %rax, %rax
jne 0x131b6
jmp 0x13399
leaq 0x8(%r15), %rsi
movq %rsp, %r12
movq %r12, %rdi
callq 0x13a38
movq 0x8(%r12), %r13
movq 0x10(%r12), %rbp
movq %rbp, %rax
notq %rax
orq %r13, %rax
je 0x13399
movq 0x10(%r13), %r12
movq %r12, %rdi
callq 0x4470
testq %rax, %rax
je 0x1331e
movq 0x18(%r13), %rcx
movq %r12, 0x28(%rsp)
movq %rcx, 0x30(%rsp)
notq %rcx
addq %rcx, %rax
movq %rax, 0x50(%rsp)
movq 0x8(%rbx), %rax
subq (%rbx), %rax
shrq $0x3, %rax
movl %eax, 0x38(%rsp)
movq 0x40(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x1367e
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x13307
movq 0x50(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%rbx)
jmp 0x13314
movq %rbx, %rdi
leaq 0x50(%rsp), %rdx
callq 0x1249e
movq 0x8(%rsp), %r13
movq 0x10(%rsp), %rbp
movq (%r13), %r13
movq %r13, 0x8(%rsp)
movq (%rsp), %rcx
movq (%rcx), %rdx
leaq (,%rbp,2), %rax
addq %rbp, %rax
leaq (%rdx,%rax,8), %rax
cmpq %rax, %r13
jne 0x13386
movq 0x8(%rcx), %rcx
subq %rdx, %rcx
sarq $0x3, %rcx
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdx, %rcx
incq %rbp
cmpq %rcx, %rbp
jae 0x13372
movq 0x18(%rax), %r13
addq $0x18, %rax
cmpq %r13, %rax
je 0x1335b
jmp 0x1337c
movq $-0x1, %rbp
xorl %r13d, %r13d
movq %r13, 0x8(%rsp)
movq %rbp, 0x10(%rsp)
cmpq $-0x1, %rbp
jne 0x132a6
testq %r13, %r13
jne 0x132a6
addq $0x68, %r15
leaq 0x28(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x13a9e
movq 0x8(%r12), %r15
movq 0x10(%r12), %rax
notq %rax
orq %r15, %rax
je 0x134ed
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 0x13538
cmpq $-0x1, 0x10(%rsp)
jne 0x1346f
cmpq $0x0, 0x8(%rsp)
jne 0x1346f
movq 0x40(%rsp), %rdi
movq %rbx, %r13
movq %rbx, %rsi
callq 0x13b04
testq %rax, %rax
je 0x13434
movl 0x18(%rax), %eax
movq (%rbp), %rcx
movq 0x20(%rsp), %rdx
movq (%rdx), %rdx
movq %rcx, (%rdx,%rax,8)
jmp 0x1346c
movq 0x20(%rsp), %rax
movq (%rax), %rbx
movq 0x8(%rax), %r15
movq 0x40(%rsp), %rdi
movq %r13, %rsi
callq 0x13bb0
subq %rbx, %r15
shrq $0x3, %r15
movl %r15d, (%rax)
movq (%rbp), %rax
movq %rax, (%rsp)
movq 0x20(%rsp), %rdi
movq %r12, %rsi
callq 0x13cba
movq %r13, %rbx
movq 0x28(%rsp), %rdx
movq 0x30(%rsp), %rax
movq (%rax), %r15
movq %r15, 0x30(%rsp)
movq 0x38(%rsp), %rax
movq (%rdx), %rsi
leaq (%rax,%rax,2), %rcx
leaq (%rsi,%rcx,8), %rcx
cmpq %rcx, %r15
jne 0x134da
movq 0x8(%rdx), %rdx
subq %rsi, %rdx
sarq $0x3, %rdx
movabsq $-0x5555555555555555, %rsi # imm = 0xAAAAAAAAAAAAAAAB
imulq %rsi, %rdx
incq %rax
cmpq %rdx, %rax
jae 0x134c6
movq 0x18(%rcx), %r15
addq $0x18, %rcx
cmpq %r15, %rcx
je 0x134af
jmp 0x134d0
movq $-0x1, %rax
xorl %r15d, %r15d
movq %r15, 0x30(%rsp)
movq %rax, 0x38(%rsp)
cmpq $-0x1, %rax
jne 0x133cb
testq %r15, %r15
jne 0x133cb
movq %rsp, %rsi
movq $0x0, (%rsi)
movq 0x20(%rsp), %rbx
movq %rbx, %rdi
callq 0x13cba
movq %rbx, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x13522
jmp 0x13522
jmp 0x13522
jmp 0x13522
jmp 0x13522
jmp 0x13522
movq %rax, %r14
movq 0x20(%rsp), %rdi
callq 0x11f74
movq %r14, %rdi
callq 0x4630
nop