// File: /workspace/github_cpp_makefile_star2_O1/davmac314[P]dinit/src/includes/dinit-env.h
// Function: void read_env_file_inline<void (int), void (int)>(char const*, bool, environment&, bool, void (&)(int), void (&)(int))
inline void read_env_file_inline(const char *env_file_path, bool log_warnings, environment &env,
        bool throw_on_open_failure, LOG_INV_SETTING &log_inv_setting, LOG_BAD_COMMAND &log_bad_cmd)
{
    std::ifstream env_file(env_file_path);
    if (!env_file) {
        if (throw_on_open_failure) {
            throw std::system_error(errno, std::generic_category());
        }
        return;
    }

    env_file.exceptions(std::ios::badbit);

    auto &clocale = std::locale::classic();
    std::string line;
    int linenum = 0;

    while (std::getline(env_file, line)) {
        linenum++;
        auto lpos = line.begin();
        auto lend = line.end();
        while (lpos != lend && std::isspace(*lpos, clocale)) {
            ++lpos;
        }

        if (lpos == lend) continue; // empty line

        if (*lpos == '#') {
            continue;
        }
        if (*lpos == '=') {
            if (log_warnings) {
                log_inv_setting(linenum);
            }
            continue;
        }

        // "!COMMAND" form.
        if (*lpos == '!') {
            ++lpos; // lpos = first char of command
            auto epos = lpos;
            do {
                ++epos;
            } while(epos != lend && !std::isspace(*epos, clocale));

            const char *lpos_p = line.data() + (lpos - line.begin());
            string_view cmd {lpos_p, (size_t)(epos - lpos)};

            std::vector<string_view> cmd_args;
            while (epos != lend) {
                // skip whitespace
                while (std::isspace(*epos, clocale)) {
                    ++epos;
                    if (epos == lend) goto process_cmd; // no more args
                }
                // all non-ws is argument until next ws
                const char *arg_begin = line.c_str() + (epos - line.begin());
                auto arg_begin_i = epos;
                while (epos != lend && !std::isspace(*epos)) {
                    ++epos;
                }
                cmd_args.push_back(string_view {arg_begin, (size_t)(epos - arg_begin_i)});
            }

            process_cmd:

            if (cmd == "clear") {
                env.clear_no_inherit();
            }
            else if (cmd == "unset") {
                for (string_view arg : cmd_args) {
                    env.undefine_var(std::string(arg.data(), arg.length()));
                }
            }
            else if (cmd == "import") {
                for (string_view arg : cmd_args) {
                    env.import_parent_var(std::string(arg.data(), arg.length()));
                }
            }
            else if (log_warnings) {
                log_bad_cmd(linenum);
            }

            continue;
        }

        // ENV=VALUE form.
        auto name_begin = lpos++;
        // skip until '=' or whitespace:
        while (lpos != lend && *lpos != '=' && !std::isspace(*lpos, clocale)) ++lpos;
        auto name_end = lpos;
        //  skip whitespace:
        while (lpos != lend && std::isspace(*lpos, clocale)) ++lpos;
        if (lpos == lend || *lpos != '=') {
            if (log_warnings) {
                log_inv_setting(linenum);
            }
            continue;
        }

        ++lpos;
        auto val_begin = lpos;
        auto val_end = lend;

        if (val_begin != (name_end + 1) || name_begin != line.begin()) {
            // there are spaces that we need to eliminate
            std::string name_and_val;
            name_and_val.reserve((name_end - name_begin) + 1 + (val_end - val_begin));
            name_and_val = line.substr(name_begin - line.begin(), name_end - name_begin);
            name_and_val.append(1, '=');
            name_and_val.append(val_begin, val_end);
            env.set_var(std::move(name_and_val));
        }
        else {
            line.shrink_to_fit();
            env.set_var(std::move(line));
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x298, %rsp            # imm = 0x298
movq %r9, %r14
movq %r8, %r13
movl %ecx, %ebx
movq %rdx, %r15
movl %esi, %ebp
movq %rdi, %rsi
leaq 0x90(%rsp), %r12
movq %r12, %rdi
movl $0x8, %edx
callq 0x8b00
movq (%r12), %rax
movq -0x18(%rax), %rax
movl 0xb0(%rsp,%rax), %esi
testb $0x5, %sil
je 0x30ba4
testb %bl, %bl
je 0x31117
movl $0x20, %edi
callq 0x82c0
movq %rax, %r14
callq 0x8050
movl (%rax), %ebx
callq 0x82e0
movq %r14, %rdi
movl %ebx, %esi
movq %rax, %rdx
callq 0xcdde
movq 0x1539b(%rip), %rsi     # 0x45f30
movq 0x153cc(%rip), %rdx     # 0x45f68
movq %r14, %rdi
callq 0x8aa0
movq %r13, 0x80(%rsp)
movl %ebp, 0x2c(%rsp)
leaq (%rsp,%rax), %rdi
addq $0x90, %rdi
movl $0x1, 0x1c(%rdi)
callq 0x8a90
movq %r15, 0x78(%rsp)
movq %r14, 0x88(%rsp)
callq 0x8840
movq %rax, %rbp
leaq 0x40(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
xorl %r15d, %r15d
leaq 0x50(%rsp), %r13
movq %rbp, (%rsp)
movq 0x90(%rsp), %rax
movq -0x18(%rax), %rdi
leaq 0x90(%rsp), %rbx
addq %rbx, %rdi
movl $0xa, %esi
callq 0x85d0
leaq 0x30(%rsp), %rsi
movsbl %al, %edx
movq %rbx, %rdi
callq 0x8b10
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x310fb
movq 0x30(%rsp), %r14
movq 0x38(%rsp), %rbx
leaq (%r14,%rbx), %r12
testq %rbx, %rbx
je 0x30c80
movq %r15, %r13
movzbl (%r14), %r15d
movq %rbp, %rdi
callq 0x8220
movq 0x30(%rax), %rax
testb $0x20, 0x1(%rax,%r15,2)
je 0x30c78
incq %r14
decq %rbx
jne 0x30c55
movq %r12, %r14
movq %r13, %r15
leaq 0x50(%rsp), %r13
incl %r15d
cmpq %r12, %r14
je 0x30bfc
movzbl (%r14), %eax
cmpl $0x21, %eax
je 0x30d48
cmpl $0x23, %eax
je 0x30bfc
movq %r15, 0x70(%rsp)
movq %r14, %r15
cmpl $0x3d, %eax
jne 0x30cd2
cmpb $0x0, 0x2c(%rsp)
movq (%rsp), %rbp
movq 0x70(%rsp), %r15
je 0x30bfc
movl %r15d, %edi
callq *0x80(%rsp)
jmp 0x30bfc
movq %r15, %rbp
incq %r15
cmpq %r12, %r15
je 0x30cfb
movzbl (%r15), %ebx
cmpq $0x3d, %rbx
je 0x30cfb
movq (%rsp), %rdi
callq 0x8220
movq 0x30(%rax), %rax
testb $0x20, 0x1(%rax,%rbx,2)
je 0x30cd2
leaq 0x1(%rbp), %rax
cmpq %r12, %rax
je 0x30fb4
movl $0x1, %ebx
movzbl (%rbp,%rbx), %r13d
movq (%rsp), %rdi
callq 0x8220
movq 0x30(%rax), %rax
testb $0x20, 0x1(%rax,%r13,2)
je 0x30d37
leaq (%rbx,%rbp), %rax
incq %rax
incq %rbx
cmpq %r12, %rax
jne 0x30d0d
leaq (%rbx,%rbp), %rax
incq %rbx
leaq 0x50(%rsp), %r13
jmp 0x30fb9
movq %r15, %r13
leaq 0x2(%r14), %rbx
xorl %eax, %eax
movq %rax, %r15
addq %rbx, %rax
cmpq %r12, %rax
je 0x30d77
movzbl (%rax), %ebp
movq (%rsp), %rdi
callq 0x8220
movq 0x30(%rax), %rcx
leaq 0x1(%r15), %rax
testb $0x20, 0x1(%rcx,%rbp,2)
je 0x30d51
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movq $0x0, 0x60(%rsp)
leaq (%r14,%r15), %rbp
addq $0x2, %rbp
cmpq %r12, %rbp
je 0x30e1d
movzbl (%rbp), %ebx
movq (%rsp), %rdi
callq 0x8220
movq 0x30(%rax), %rax
testb $0x20, 0x1(%rax,%rbx,2)
jne 0x30e15
movq %rbp, %rbx
cmpq %r12, %rbp
je 0x30dd0
movq %rbp, %rbx
movsbl (%rbx), %edi
callq 0x8070
testl %eax, %eax
jne 0x30dd0
incq %rbx
cmpq %r12, %rbx
jne 0x30dbc
movq %rbx, %rax
subq %rbp, %rax
movq %rbp, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movq 0x58(%rsp), %rsi
cmpq 0x60(%rsp), %rsi
je 0x30dfc
movups 0x8(%rsp), %xmm0
movups %xmm0, (%rsi)
addq $0x10, 0x58(%rsp)
jmp 0x30e0b
leaq 0x50(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x3127c
movq %rbx, %rbp
cmpq %r12, %rbx
jne 0x30d99
jmp 0x30e1d
incq %rbp
jmp 0x30d90
movb $0x63, %cl
movl $0x1, %eax
movq 0x78(%rsp), %r12
movq (%rsp), %rbp
cmpb (%r14,%rax), %cl
jne 0x30e5c
leaq 0x5b09(%rip), %rcx      # 0x36943
movb (%rax,%rcx), %cl
incq %rax
cmpq $0x6, %rax
jne 0x30e2d
cmpq $0x4, %r15
jne 0x30e5c
movq %r12, %rdi
callq 0x31202
movq %r13, %r15
jmp 0x30f93
movb $0x75, %cl
movl $0x1, %eax
cmpb (%r14,%rax), %cl
jne 0x30ef4
leaq 0x5ad5(%rip), %rcx      # 0x36949
movb (%rax,%rcx), %cl
incq %rax
cmpq $0x6, %rax
jne 0x30e63
cmpq $0x4, %r15
jne 0x30ef4
movq 0x50(%rsp), %rbx
movq 0x58(%rsp), %r14
cmpq %r14, %rbx
movq %r13, %r15
je 0x30f93
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
leaq 0x18(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x8(%rsp), %r13
movq %r13, %rdi
callq 0xd750
movq %r12, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x2bd1e
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x30ee6
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x8620
addq $0x10, %rbx
cmpq %r14, %rbx
jne 0x30e9c
jmp 0x30f93
movb $0x69, %cl
movl $0x1, %eax
cmpb (%r14,%rax), %cl
jne 0x30f7f
leaq 0x5a47(%rip), %rcx      # 0x3694f
movb (%rax,%rcx), %cl
incq %rax
cmpq $0x7, %rax
jne 0x30efb
cmpq $0x5, %r15
jne 0x30f7f
movq 0x50(%rsp), %rbx
movq 0x58(%rsp), %r14
cmpq %r14, %rbx
movq %r13, %r15
je 0x30f93
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
leaq 0x18(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x8(%rsp), %r13
movq %r13, %rdi
callq 0xd750
movq %r12, %rdi
movq %r13, %rsi
callq 0x31228
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x30f74
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x8620
addq $0x10, %rbx
cmpq %r14, %rbx
jne 0x30f2c
jmp 0x30f93
cmpb $0x0, 0x2c(%rsp)
movq %r13, %r15
je 0x30f93
movl %r15d, %edi
callq *0x88(%rsp)
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x30faa
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x8620
leaq 0x50(%rsp), %r13
jmp 0x30bfc
movl $0x2, %ebx
cmpq %r12, %rax
je 0x30ffa
cmpb $0x3d, (%rax)
jne 0x30ffa
cmpq $0x2, %rbx
jne 0x3101d
cmpq 0x30(%rsp), %r14
jne 0x3101d
leaq 0x30(%rsp), %rbx
movq %rbx, %rdi
callq 0x8370
movq (%rsp), %rbp
movq 0x70(%rsp), %r15
movq 0x78(%rsp), %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x1afe0
jmp 0x30bfc
cmpb $0x0, 0x2c(%rsp)
movq (%rsp), %rbp
movq 0x70(%rsp), %r15
je 0x30bfc
movl %r15d, %edi
callq *0x80(%rsp)
jmp 0x30bfc
addq %rbx, %rbp
leaq 0x18(%rsp), %rax
movq %rax, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
movb $0x0, 0x18(%rsp)
subq %r14, %r15
subq %rbp, %r12
leaq (%r15,%r12), %rsi
incq %rsi
leaq 0x8(%rsp), %rdi
callq 0x89b0
subq 0x30(%rsp), %r14
movq %r13, %rdi
leaq 0x30(%rsp), %rsi
movq %r14, %rdx
movq %r15, %rcx
callq 0x8640
leaq 0x8(%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x8740
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x31093
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x8620
movq 0x10(%rsp), %rsi
movl $0x1, %ecx
movq %rbx, %rdi
xorl %edx, %edx
movl $0x3d, %r8d
callq 0x8b20
movq 0x10(%rsp), %rsi
movq %rbx, %rdi
xorl %edx, %edx
movq %rbp, %rcx
movq %r12, %r8
callq 0x86b0
movq 0x78(%rsp), %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x1afe0
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x310ed
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x8620
movq (%rsp), %rbp
movq 0x70(%rsp), %r15
jmp 0x30bfc
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x31117
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x8620
leaq 0x90(%rsp), %rdi
callq 0x8120
addq $0x298, %rsp            # imm = 0x298
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x31165
jmp 0x311ce
movq %rax, %rdi
callq 0xb8be
movq %rax, %rbx
movq %r14, %rdi
callq 0x8440
jmp 0x311ed
jmp 0x3115b
jmp 0x311b2
jmp 0x311ce
movq %rax, %rbx
jmp 0x311ed
jmp 0x311ce
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x311d1
movq 0x18(%rsp), %rsi
incq %rsi
jmp 0x311c7
jmp 0x311b2
jmp 0x31185
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x311b5
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x8620
jmp 0x311b5
jmp 0x311b2
jmp 0x311b2
jmp 0x311ce
jmp 0x311ce
jmp 0x311ce
jmp 0x311ce
movq %rax, %rbx
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x311d1
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x8620
jmp 0x311d1
movq %rax, %rbx
leaq 0x40(%rsp), %rax
movq 0x30(%rsp), %rdi
cmpq %rax, %rdi
je 0x311ed
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x8620
leaq 0x90(%rsp), %rdi
callq 0x8120
movq %rbx, %rdi
callq 0x8ab0