// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/includes/load-service.h
// Function: void dinit_load::value_var_subst<load_service(std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, service_record*, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, service_record*>>>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::vector<dir_entry, std::allocator<dir_entry>> const&)::$_0>(char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, std::__cxx11::list<std::pair<unsigned int, unsigned int>, std::allocator<std::pair<unsigned int, unsigned int>>>&, load_service(std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, service_record*, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, service_record*>>>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::vector<dir_entry, std::allocator<dir_entry>> const&)::$_0 const&, char const*)
static void value_var_subst(const char *setting_name, std::string &line,
        std::list<std::pair<unsigned,unsigned>> &offsets, const T &var_resolve, const char *argval)
{
    auto dindx = line.find('$');
    if (dindx == string::npos) {
        return;
    }

    if (line.length() > (size_t)std::numeric_limits<int>::max()) {
        // (avoid potential for overflow later)
        throw std::length_error("string too long");
    }

    auto i = offsets.begin();
    unsigned xpos = 0; // position to copy from in original line
    std::string r_line;
    int offadj = 0;

    while (i != offsets.end()) {

        i->first += offadj; // don't adjust end yet

        // inhibit_collapse is set if we process anything which may be empty but shouldn't collapse
        // to "no argument"
        bool inhibit_collapse = false;
        bool do_collapse = false;

        while (i->second > dindx) {
            r_line.append(line, xpos, dindx - xpos); // copy unmatched part
            if (line[dindx + 1] == '$') {
                // double dollar, collapse to single
                r_line += '$';
                xpos = dindx + 2;
                --offadj;
            }
            else {
                // variable
                auto token_end = std::next(line.begin(), i->second);
                auto spos = dindx + 1;
                bool wsplit = line[spos] == '/';
                if (wsplit) ++spos;
                bool brace = line[spos] == '{';
                if (brace) ++spos;
                auto j = std::next(line.begin(), spos);
                // may be a service argument
                bool is_arg = false;
                // read environment variable name
                string name = read_config_name(j, token_end, true, &is_arg);
                if (name.empty()) {
                    throw service_description_exc(setting_name, "invalid/missing variable name after '$'");
                }
                else if (is_arg && name != "1") {
                    // only one arg is supported
                    throw service_description_exc(setting_name, "only one service argument may be present");
                }
                char altmode = '\0';
                bool colon = false;
                auto altbeg = j, altend = j;
                if (brace) {
                    /* ${foo+val}, ${foo-val}, ${foo:+val}, ${foo:-val} */
                    if (*j == ':') {
                        colon = true;
                        ++j;
                        if (*j != '+' && *j != '-') {
                            throw service_description_exc(setting_name, "invalid syntax in variable substitution");
                        }
                    }
                    if (*j == '+' || *j == '-') {
                        altmode = *j;
                        altbeg = ++j;
                        while (j != token_end && *j != '}') {
                            ++j;
                        }
                        altend = j;
                    }
                    if (*j != '}') {
                        throw service_description_exc(setting_name, "unmatched '{' in variable substitution");
                    }
                    ++j;
                }
                size_t line_len_before = r_line.size();
                string_view resolved_vw;
                auto *resolved = is_arg ? argval : var_resolve(name);
                if (resolved) {
                    resolved_vw = resolved;
                }
                /* apply shell-like substitutions */
                if (altmode == '-') {
                    if (!resolved || (colon && !*resolved)) {
                        resolved_vw = {line.c_str() + (altbeg - line.begin()), (size_t)(altend - altbeg)};
                    }
                }
                else if (altmode == '+') {
                    if (resolved && (!colon || *resolved)) {
                        resolved_vw = {line.c_str() + (altbeg - line.begin()), (size_t)(altend - altbeg)};
                    }
                }
                else if (is_arg && !argval) {
                    // $1 and ${1} is special in that it must be set or it is an error
                    // however, we want the more complex syntaxes for conditional substitution
                    throw service_description_exc(setting_name, "missing value in argument substitution");
                }

                xpos = j - line.begin();
                int name_len = xpos - dindx;
                offadj -= name_len;

                if (!wsplit) {
                    inhibit_collapse = true;
                    do_collapse = false;
                    if (!resolved_vw.empty()) {
                        r_line.append(resolved_vw.data(), resolved_vw.length());
                    }
                }
                else {
                    // Must perform word splitting. Find first whitespace:
                    auto r_vw_beg = resolved_vw.data();
                    auto r_vw_end = r_vw_beg + resolved_vw.length();
                    const char *wsp = findws(r_vw_beg, r_vw_end);

                    // If we have whitespace, append up to that whitespace and then split:
                    while (wsp != r_vw_end) {
                        if (wsp != r_vw_beg) {
                            r_line.append(r_vw_beg, wsp - r_vw_beg);
                        }

                        auto orig_i_second = i->second;

                        size_t line_len_after = r_line.size();
                        if (i->first == line_len_after && !inhibit_collapse) {
                            // whitespace at the start of the word; just trim it
                            goto next_section;
                        }

                        // Break here:
                        i->second = r_line.length();

                        r_line += ' ';
                        ++line_len_after;

                        if (line_len_after > (size_t)std::numeric_limits<int>::max()) {
                            // (avoid potential overflow)
                            throw service_description_exc(setting_name, "value too long (after substitution)");
                        }

                        // Create new argument from split:
                        i = offsets.insert(std::next(i), {r_line.length(), orig_i_second});
                        offadj += (int)line_len_after - (int)line_len_before;
                        line_len_before = r_line.size();

                        // Find the next break, if any:
                        next_section:
                        r_vw_beg = skipws(wsp, r_vw_end);
                        wsp = findws(r_vw_beg, r_vw_end);
                        inhibit_collapse = false;
                    }

                    if (r_vw_beg != r_vw_end) {
                        r_line.append(r_vw_beg, r_vw_end - r_vw_beg);
                    }

                    do_collapse = !inhibit_collapse;
                }

                size_t line_len_after = r_line.size();

                if (line_len_after > (size_t)std::numeric_limits<int>::max()) {
                    // (avoid potential overflow)
                    throw service_description_exc(setting_name, "value too long (after substitution)");
                }

                offadj += (int)line_len_after - (int)line_len_before;
            }

            dindx = line.find('$', xpos);
        }

        i->second += offadj;

        if (do_collapse && i->first == i->second) {
            i = offsets.erase(i);
        }
        else {
            ++i;
        }

        while (i != offsets.end() && i->second < dindx) {
            i->first += offadj;
            i->second += offadj;
            ++i;
        }
    }

    r_line.append(line, xpos); // copy final unmatched part
    line = std::move(r_line);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %r8, 0x90(%rsp)
movq %rcx, 0x60(%rsp)
movq %rdx, 0x20(%rsp)
movq %rsi, %r14
movq %rdi, 0x10(%rsp)
pushq $0x24
popq %rsi
movq %r14, %rdi
xorl %edx, %edx
callq 0x44c0
cmpq $-0x1, %rax
je 0x91d2
movq %rax, %rbx
movq %r14, 0x58(%rsp)
movq 0x8(%r14), %rax
shrq $0x1f, %rax
jne 0x93fe
movq 0x20(%rsp), %rax
movq (%rax), %r15
leaq 0x80(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
xorl %r13d, %r13d
xorl %r14d, %r14d
cmpq 0x20(%rsp), %r15
je 0x91a2
addl %r13d, 0x10(%r15)
xorl %ebp, %ebp
movl $0x0, 0xc(%rsp)
movl 0x14(%r15), %eax
cmpq %rax, %rbx
jae 0x9157
movl %r14d, %edx
movq %rbx, %rcx
subq %rdx, %rcx
leaq 0x70(%rsp), %rdi
movq 0x58(%rsp), %r14
movq %r14, %rsi
callq 0x4520
movq (%r14), %rax
movb 0x1(%rax,%rbx), %r12b
cmpb $0x24, %r12b
jne 0x8daf
leaq 0x70(%rsp), %rdi
pushq $0x24
popq %rsi
callq 0x4330
addl $0x2, %ebx
decl %r13d
jmp 0x913d
leaq 0x1(%rbx), %rcx
movl 0x14(%r15), %r14d
addq %rax, %r14
leaq 0x2(%rbx), %rdx
cmpb $0x2f, %r12b
cmovneq %rcx, %rdx
leaq (%rax,%rdx), %rcx
movb (%rax,%rdx), %bpl
xorl %eax, %eax
cmpb $0x7b, %bpl
sete %al
addq %rcx, %rax
movq %rax, 0x18(%rsp)
movb $0x0, 0x6(%rsp)
leaq 0x98(%rsp), %rdi
leaq 0x18(%rsp), %rsi
movq %r14, %rdx
pushq $0x1
popq %rcx
leaq 0x6(%rsp), %r8
callq 0x11e81
cmpq $0x0, 0xa0(%rsp)
je 0x9232
cmpb $0x1, 0x6(%rsp)
jne 0x8e33
leaq 0x98(%rsp), %rdi
leaq 0xf804(%rip), %rsi      # 0x1862a
callq 0x1266d
testb %al, %al
jne 0x931c
movb %r12b, 0x7(%rsp)
movl $0x0, 0x8(%rsp)
movq 0x18(%rsp), %r12
cmpb $0x7b, %bpl
movq %r13, 0x28(%rsp)
jne 0x8ebc
movb (%r12), %cl
movq %r12, %rax
cmpb $0x3a, %cl
sete %bpl
jne 0x8e7e
leaq 0x1(%r12), %rax
movq %rax, 0x18(%rsp)
movzbl 0x1(%r12), %ecx
cmpl $0x2b, %ecx
je 0x8e7e
cmpl $0x2d, %ecx
jne 0x93b5
cmpb $0x2d, %cl
je 0x8e8b
movzbl %cl, %edx
cmpl $0x2b, %edx
jne 0x8ec5
movq %rax, %r12
incq %rax
movq %rax, %rsi
movq %rsi, %rdi
movq %rsi, 0x18(%rsp)
movb (%rsi), %dl
incq %rsi
incq %r12
cmpq %r14, %rdi
je 0x8eae
cmpb $0x7d, %dl
jne 0x8e94
movsbl %cl, %edi
movq %rax, %rcx
decq %rsi
movq %rsi, %rax
jmp 0x8ecc
movq %r12, 0x68(%rsp)
xorl %ebp, %ebp
jmp 0x8ee6
movl %ecx, %edx
movq %r12, %rcx
xorl %edi, %edi
cmpb $0x7d, %dl
jne 0x92ce
movl %edi, 0x8(%rsp)
movq %rcx, 0x68(%rsp)
incq %rax
movq %rax, 0x18(%rsp)
movq 0x78(%rsp), %r13
cmpb $0x0, 0x6(%rsp)
movq 0x90(%rsp), %r14
jne 0x8f65
cmpb $0x0, 0x1b8e7(%rip)     # 0x247e8
jne 0x8f4c
movq 0x60(%rsp), %rax
movq (%rax), %rax
cmpb $0x0, (%rax)
jne 0x8f4c
movq 0x1b0d1(%rip), %rdi     # 0x23fe8
leaq 0xf072(%rip), %rsi      # 0x17f90
callq 0x4380
movq %rax, %rdi
leaq 0xefce(%rip), %rsi      # 0x17efb
callq 0x4380
movq %rax, %rdi
leaq 0xe62d(%rip), %rsi      # 0x17569
callq 0x4380
movq 0x60(%rsp), %rax
movq (%rax), %rax
movb $0x1, (%rax)
movq 0x60(%rsp), %rax
movq 0x8(%rax), %rsi
leaq 0x98(%rsp), %rdi
callq 0x1271c
movq %rax, %r14
movl %ebp, 0x54(%rsp)
testq %r14, %r14
je 0x8f7b
movq %r14, %rdi
callq 0x4180
movq %rax, %rbp
jmp 0x8f7d
xorl %ebp, %ebp
movl 0x8(%rsp), %eax
cmpl $0x2b, %eax
je 0x8f9f
cmpl $0x2d, %eax
jne 0x8fbe
testq %r14, %r14
je 0x8fb1
cmpb $0x0, 0x54(%rsp)
je 0x8fd8
cmpb $0x0, (%r14)
jne 0x8fd8
jmp 0x8fb1
testq %r14, %r14
je 0x8fd5
cmpb $0x0, 0x54(%rsp)
je 0x8fb1
cmpb $0x0, (%r14)
je 0x8fd8
movq 0x68(%rsp), %r14
subq %r14, %r12
movq %r12, %rbp
jmp 0x8fd8
cmpq $0x0, 0x90(%rsp)
jne 0x8fd8
cmpb $0x0, 0x6(%rsp)
je 0x8fd8
jmp 0x936a
xorl %r14d, %r14d
movl 0x18(%rsp), %ecx
movq 0x58(%rsp), %rax
subl (%rax), %ecx
movl %ecx, 0x8(%rsp)
subl %ecx, %ebx
movq 0x28(%rsp), %rax
addl %ebx, %eax
movq %rax, 0x28(%rsp)
cmpb $0x2f, 0x7(%rsp)
jne 0x90c6
addq %r14, %rbp
movq %r14, %rdi
movq %rbp, %rsi
callq 0x12677
cmpq %rbp, %rax
je 0x90e9
movq %rax, %rbx
movq %rax, %rdx
subq %r14, %rdx
je 0x902f
leaq 0x70(%rsp), %rdi
movq %r14, %rsi
callq 0x4080
movl 0x10(%r15), %eax
movl 0x14(%r15), %r12d
movq 0x78(%rsp), %r14
cmpq %rax, %r14
jne 0x9048
testb $0x1, 0xc(%rsp)
je 0x90ab
movl %r14d, 0x14(%r15)
leaq 0x70(%rsp), %rdi
pushq $0x20
popq %rsi
callq 0x4330
incq %r14
testq $-0x80000000, %r14      # imm = 0x80000000
jne 0x91e4
movq %r15, %rdi
pushq $0x1
popq %rsi
callq 0x126b3
movl 0x78(%rsp), %ecx
movl %ecx, 0x30(%rsp)
movl %r12d, 0x34(%rsp)
movq 0x20(%rsp), %rdi
movq %rax, %rsi
leaq 0x30(%rsp), %rdx
callq 0x127a0
movq %rax, %r15
movq 0x28(%rsp), %rax
subl %r13d, %eax
addl %r14d, %eax
movq %rax, 0x28(%rsp)
movq 0x78(%rsp), %r13
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x126d1
movq %rax, %r14
movl $0x0, 0xc(%rsp)
jmp 0x9003
movb $0x1, %al
movl %eax, 0xc(%rsp)
testq %rbp, %rbp
je 0x910b
leaq 0x70(%rsp), %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x4080
movl 0x8(%rsp), %ebx
xorl %ebp, %ebp
jmp 0x9111
cmpq %rbp, %r14
je 0x9101
subq %r14, %rbp
leaq 0x70(%rsp), %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x4080
movl 0xc(%rsp), %ebp
xorb $0x1, %bpl
jmp 0x910d
xorl %ebp, %ebp
movl 0x8(%rsp), %ebx
movq 0x78(%rsp), %rax
testq $-0x80000000, %rax      # imm = 0x80000000
jne 0x9280
movq 0x28(%rsp), %rcx
subl %r13d, %ecx
movq %rcx, %r13
addl %eax, %r13d
leaq 0x98(%rsp), %rdi
callq 0x41a0
movl %ebx, %r14d
movl %ebx, %edx
movq 0x58(%rsp), %rdi
pushq $0x24
popq %rsi
callq 0x44c0
movq %rax, %rbx
jmp 0x8d61
addl %r13d, %eax
movl %eax, 0x14(%r15)
testb $0x1, %bpl
je 0x919d
cmpl %eax, 0x10(%r15)
jne 0x919d
movq 0x20(%rsp), %rdi
movq %r15, %rsi
callq 0x1270e
movq %rax, %r15
cmpq 0x20(%rsp), %r15
je 0x8d48
movl 0x14(%r15), %eax
cmpq %rax, %rbx
jbe 0x8d48
addl %r13d, 0x10(%r15)
addl %r13d, %eax
movl %eax, 0x14(%r15)
movq (%r15), %r15
jmp 0x917a
movl %r14d, %edx
leaq 0x70(%rsp), %rdi
pushq $-0x1
popq %rcx
movq 0x58(%rsp), %r14
movq %r14, %rsi
callq 0x4520
leaq 0x70(%rsp), %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4480
movq %rbx, %rdi
callq 0x41a0
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x70
popq %rdi
callq 0x41d0
movq %rax, %r14
leaq 0xece1(%rip), %rsi      # 0x17ed7
leaq 0x30(%rsp), %rdi
leaq 0x5(%rsp), %rdx
callq 0xb9ce
leaq 0x30(%rsp), %rdx
movq %r14, %rdi
movq 0x10(%rsp), %rsi
callq 0x12638
leaq 0x1a9e2(%rip), %rsi     # 0x23c00
leaq 0x8bb7(%rip), %rdx      # 0x11ddc
movq %r14, %rdi
callq 0x4610
jmp 0x93fe
pushq $0x70
popq %rdi
callq 0x41d0
movq %rax, %r14
leaq 0xebcc(%rip), %rsi      # 0x17e10
leaq 0x30(%rsp), %rdi
leaq 0x5(%rsp), %rdx
callq 0xb9ce
leaq 0x30(%rsp), %rdx
movq %r14, %rdi
movq 0x10(%rsp), %rsi
callq 0x12638
leaq 0x1a994(%rip), %rsi     # 0x23c00
leaq 0x8b69(%rip), %rdx      # 0x11ddc
movq %r14, %rdi
callq 0x4610
jmp 0x93fe
pushq $0x70
popq %rdi
callq 0x41d0
movq %rax, %r14
leaq 0xec45(%rip), %rsi      # 0x17ed7
leaq 0x30(%rsp), %rdi
leaq 0x5(%rsp), %rdx
callq 0xb9ce
leaq 0x30(%rsp), %rdx
movq %r14, %rdi
movq 0x10(%rsp), %rsi
callq 0x12638
leaq 0x1a946(%rip), %rsi     # 0x23c00
leaq 0x8b1b(%rip), %rdx      # 0x11ddc
movq %r14, %rdi
callq 0x4610
jmp 0x93fe
pushq $0x70
popq %rdi
callq 0x41d0
movq %rax, %r14
leaq 0xeba9(%rip), %rsi      # 0x17e89
leaq 0x30(%rsp), %rdi
leaq 0x5(%rsp), %rdx
callq 0xb9ce
leaq 0x30(%rsp), %rdx
movq %r14, %rdi
movq 0x10(%rsp), %rsi
callq 0x12638
leaq 0x1a8f8(%rip), %rsi     # 0x23c00
leaq 0x8acd(%rip), %rdx      # 0x11ddc
movq %r14, %rdi
callq 0x4610
jmp 0x93fe
pushq $0x70
popq %rdi
callq 0x41d0
movq %rax, %r14
leaq 0xeb0a(%rip), %rsi      # 0x17e38
leaq 0x30(%rsp), %rdi
leaq 0x5(%rsp), %rdx
callq 0xb9ce
leaq 0x30(%rsp), %rdx
movq %r14, %rdi
movq 0x10(%rsp), %rsi
callq 0x12638
leaq 0x1a8aa(%rip), %rsi     # 0x23c00
leaq 0x8a7f(%rip), %rdx      # 0x11ddc
movq %r14, %rdi
callq 0x4610
jmp 0x93fe
pushq $0x70
popq %rdi
callq 0x41d0
movq %rax, %r14
leaq 0xeb34(%rip), %rsi      # 0x17eb0
leaq 0x30(%rsp), %rdi
leaq 0x5(%rsp), %rdx
callq 0xb9ce
leaq 0x30(%rsp), %rdx
movq %r14, %rdi
movq 0x10(%rsp), %rsi
callq 0x12638
leaq 0x1a85c(%rip), %rsi     # 0x23c00
leaq 0x8a31(%rip), %rdx      # 0x11ddc
movq %r14, %rdi
callq 0x4610
jmp 0x93fe
pushq $0x70
popq %rdi
callq 0x41d0
movq %rax, %r14
leaq 0xea9a(%rip), %rsi      # 0x17e61
leaq 0x30(%rsp), %rdi
leaq 0x5(%rsp), %rdx
callq 0xb9ce
leaq 0x30(%rsp), %rdx
movq %r14, %rdi
movq 0x10(%rsp), %rsi
callq 0x12638
leaq 0x1a811(%rip), %rsi     # 0x23c00
leaq 0x89e6(%rip), %rdx      # 0x11ddc
movq %r14, %rdi
callq 0x4610
pushq $0x10
popq %rdi
callq 0x41d0
movq %rax, %r14
leaq 0xe9f0(%rip), %rsi      # 0x17e00
movq %rax, %rdi
callq 0x4420
movq 0x1ab89(%rip), %rsi     # 0x23fa8
movq 0x1ab32(%rip), %rdx     # 0x23f58
movq %r14, %rdi
callq 0x4610
movq %rax, %rbx
movq %r14, %rdi
callq 0x42d0
jmp 0x949c
jmp 0x945b
jmp 0x9460
jmp 0x946f
jmp 0x9460
jmp 0x946f
jmp 0x9460
jmp 0x946f
jmp 0x9460
jmp 0x946f
jmp 0x9482
jmp 0x9482
jmp 0x9460
jmp 0x946f
jmp 0x9460
jmp 0x946f
jmp 0x9482
movq %rax, %rbx
jmp 0x9492
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x41a0
jmp 0x9485
movq %rax, %rbx
movq %r14, %rdi
callq 0x42d0
jmp 0x9485
jmp 0x9482
jmp 0x9482
jmp 0x9482
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x41a0
leaq 0x70(%rsp), %rdi
callq 0x41a0
movq %rbx, %rdi
callq 0x4620