// File: /workspace/github_cpp_makefile_star2_O2/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 $0x2c8, %rsp            # imm = 0x2C8
movq %r9, %r15
movq %r8, %r12
movl %ecx, %ebx
movq %rdx, %rbp
movl %esi, %r13d
movq %rdi, %rsi
leaq 0xc0(%rsp), %r14
pushq $0x8
popq %rdx
movq %r14, %rdi
callq 0x8af0
movq (%r14), %rax
movq -0x18(%rax), %rax
testb $0x5, 0xe0(%rsp,%rax)
je 0x2b247
testb %bl, %bl
je 0x2b6cd
pushq $0x20
popq %rdi
callq 0x82c0
movq %rax, %r14
callq 0x8040
movl (%rax), %ebx
callq 0x82e0
movq %r14, %rdi
movl %ebx, %esi
movq %rax, %rdx
callq 0xc338
movq 0x19cf0(%rip), %rsi     # 0x44f28
movq 0x19d21(%rip), %rdx     # 0x44f60
movq %r14, %rdi
callq 0x8a80
leaq (%rsp,%rax), %rdi
addq $0xc0, %rdi
pushq $0x1
popq %rsi
callq 0x8170
movl %r13d, 0x4(%rsp)
movq %r12, 0x40(%rsp)
movq %r15, 0x90(%rsp)
callq 0x8830
movq %rax, 0x10(%rsp)
leaq 0x80(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq $0x0, 0x8(%rsp)
movq %rbp, 0x18(%rsp)
leaq 0xc0(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x80d0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2b6c3
movq 0x8(%rsp), %rax
incl %eax
movq %rax, 0x8(%rsp)
movq 0x70(%rsp), %r14
movq 0x78(%rsp), %rax
leaq (%r14,%rax), %rbx
leaq -0x2(%rax), %r12
movq %r14, %r13
notq %r13
movq %rax, 0xa8(%rsp)
addq %rax, %r13
xorl %r15d, %r15d
movq %r14, 0xa0(%rsp)
cmpq %rbx, %r14
je 0x2b298
movsbl (%r14), %edi
movq 0x10(%rsp), %rsi
callq 0x1ae5e
testb %al, %al
je 0x2b31c
incq %r14
decq %r12
addq $-0x2, %r13
decq %r15
jmp 0x2b2f6
cmpq %rbx, %r14
je 0x2b298
movzbl (%r14), %eax
cmpl $0x21, %eax
je 0x2b39d
cmpl $0x23, %eax
je 0x2b298
movq %r14, %rbp
cmpl $0x3d, %eax
jne 0x2b35d
cmpb $0x0, 0x4(%rsp)
movq 0x18(%rsp), %rbp
je 0x2b298
movq 0x8(%rsp), %rdi
callq *0x40(%rsp)
jmp 0x2b298
movq %r13, %r12
movq %rbp, 0x48(%rsp)
incq %rbp
cmpq %rbx, %rbp
je 0x2b4f9
movb (%rbp), %al
cmpb $0x3d, %al
je 0x2b4fc
movsbl %al, %edi
movq 0x10(%rsp), %rsi
callq 0x1ae5e
leaq -0x1(%r12), %r13
movq %r15, %rcx
decq %r15
testb %al, %al
je 0x2b35d
jmp 0x2b4ff
incq %r14
movq %r14, %r15
movl 0x4(%rsp), %r13d
testq %r12, %r12
je 0x2b3c7
incq %r15
movsbl (%r15), %edi
movq 0x10(%rsp), %rsi
callq 0x1ae5e
decq %r12
testb %al, %al
je 0x2b3a8
jmp 0x2b3ca
movq %rbx, %r15
movq %r15, %rax
subq %r14, %rax
movq %r14, 0xb0(%rsp)
movq %rax, 0xb8(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
andq $0x0, 0x60(%rsp)
cmpq %rbx, %r15
je 0x2b45d
movq %r15, %r14
negq %r14
movsbl (%r15), %edi
movq 0x10(%rsp), %rsi
callq 0x1ae5e
testb %al, %al
je 0x2b418
incq %r15
decq %r14
cmpq %rbx, %r15
jne 0x2b3f9
jmp 0x2b45d
negq %r14
xorl %r13d, %r13d
leaq (%r15,%r13), %r12
cmpq %rbx, %r12
je 0x2b43a
movsbl (%r12), %edi
callq 0x8060
testl %eax, %eax
jne 0x2b43a
incq %r13
jmp 0x2b41e
movq %r14, 0x20(%rsp)
movq %r13, 0x28(%rsp)
leaq 0x50(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x2b7fa
movq %r12, %r15
movl 0x4(%rsp), %r13d
jmp 0x2b3ee
leaq 0xb0(%rsp), %r14
movq %r14, %rdi
leaq 0x54b4(%rip), %rsi      # 0x30923
callq 0x1d242
testb %al, %al
je 0x2b48f
movq %rbp, %rdi
callq 0x2b76a
leaq 0x50(%rsp), %rdi
callq 0x2bba8
jmp 0x2b298
movq %r14, %rdi
leaq 0x5490(%rip), %rsi      # 0x30929
callq 0x1d242
testb %al, %al
movq 0x90(%rsp), %rbx
leaq 0x30(%rsp), %r15
je 0x2b5ac
movq 0x50(%rsp), %rbx
movq 0x58(%rsp), %r14
leaq 0x20(%rsp), %r12
cmpq %r14, %rbx
je 0x2b480
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
movq %r15, 0x20(%rsp)
movq %r12, %rdi
callq 0xcd00
movq %rbp, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x262ce
movq %r12, %rdi
callq 0x8b98
addq $0x10, %rbx
jmp 0x2b4c2
movq %rbx, %rbp
movq %r15, %rcx
movq %rbp, 0x98(%rsp)
addq %rbp, %r12
pushq $0x1
popq %r15
movq %r15, %r13
subq 0xa8(%rsp), %r13
movq %rcx, %rbp
cmpq %rbp, %r13
je 0x2b58e
movq 0x48(%rsp), %rax
movsbl (%rax,%r15), %edi
movq 0x10(%rsp), %rsi
callq 0x1ae5e
testb %al, %al
je 0x2b544
incq %r15
decq %r12
decq %rbp
jmp 0x2b51c
cmpq %rbp, %r13
je 0x2b58e
movq 0x48(%rsp), %rax
cmpb $0x3d, (%rax,%r15)
jne 0x2b58e
cmpq $0x1, %r15
jne 0x2b61c
cmpq 0x70(%rsp), %r14
jne 0x2b61c
leaq 0x70(%rsp), %rbx
movq %rbx, %rdi
callq 0x8b60
movq 0x18(%rsp), %rbp
movq %rbp, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x16b26
jmp 0x2b298
cmpb $0x0, 0x4(%rsp)
movq 0x18(%rsp), %rbp
je 0x2b298
movq 0x8(%rsp), %rdi
callq *0x40(%rsp)
jmp 0x2b298
movq %r14, %rdi
leaq 0x5379(%rip), %rsi      # 0x3092f
callq 0x1d242
testb %al, %al
je 0x2b607
movq 0x50(%rsp), %rbx
movq 0x58(%rsp), %r14
leaq 0x20(%rsp), %r12
cmpq %r14, %rbx
je 0x2b480
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
movq %r15, 0x20(%rsp)
movq %r12, %rdi
callq 0xcd00
movq %rbp, %rdi
movq %r12, %rsi
callq 0x2b790
movq %r12, %rdi
callq 0x8b98
addq $0x10, %rbx
jmp 0x2b5ce
testb %r13b, %r13b
je 0x2b480
movq 0x8(%rsp), %rdi
callq *%rbx
jmp 0x2b480
leaq 0x30(%rsp), %rax
movq %rax, 0x20(%rsp)
andq $0x0, 0x28(%rsp)
movb $0x0, 0x30(%rsp)
leaq 0x20(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x8990
movq 0x18(%rsp), %r12
leaq 0x50(%rsp), %r15
movq 0x98(%rsp), %rcx
subq %r14, %rcx
subq 0x70(%rsp), %r14
movq %r15, %rdi
leaq 0x70(%rsp), %rsi
movq %r14, %rdx
callq 0x8630
movq %r13, %rdi
movq %r15, %rsi
callq 0x8730
movq %r15, %rdi
callq 0x8b98
movq %r13, %rdi
pushq $0x1
popq %rsi
pushq $0x3d
popq %rdx
callq 0x8660
movq 0xa0(%rsp), %rsi
subq %rbp, %rsi
addq $0x2, %rsi
movq %r13, %rdi
movq %rbx, %rdx
callq 0x2b7e4
movq %r12, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x16b26
movq %r13, %rdi
callq 0x8b98
movq %r12, %rbp
jmp 0x2b298
leaq 0x70(%rsp), %rdi
callq 0x8b98
leaq 0xc0(%rsp), %rdi
callq 0x8110
addq $0x2c8, %rsp            # imm = 0x2C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2b738
jmp 0x2b6f2
jmp 0x2b747
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x8b98
jmp 0x2b74a
movq %rax, %rbx
movq %r14, %rdi
callq 0x8440
jmp 0x2b754
jmp 0x2b714
jmp 0x2b747
jmp 0x2b747
movq %rax, %rbx
jmp 0x2b754
jmp 0x2b738
jmp 0x2b71f
jmp 0x2b738
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x8b98
jmp 0x2b73b
jmp 0x2b738
jmp 0x2b747
jmp 0x2b747
jmp 0x2b747
jmp 0x2b747
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x2bba8
jmp 0x2b74a
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x8b98
leaq 0xc0(%rsp), %rdi
callq 0x8110
movq %rbx, %rdi
callq 0x8a90
nop