// File: davmac314[P]dinit/src/includes/load-service.h
// Function: dinit_load::read_setting_value(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, dinit_load::setting_op_t, file_pos_ref, __gnu_cxx::__normal_iterator<char*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>&, __gnu_cxx::__normal_iterator<char*, 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>>>*, char)
inline void read_setting_value(std::string &setting_val, setting_op_t operation,
        file_pos_ref input_pos, string_iterator &i, string_iterator end,
        std::list<std::pair<unsigned,unsigned>> *part_positions = nullptr,
        char delimiter = ' ')
{
    using std::locale;
    using std::isspace;

    unsigned &line_num = input_pos.get_line_num_ref();

    i = skipwsln(i, end, line_num);

    if (operation == setting_op_t::PLUSASSIGN) {
        // Ensure that values are correctly delimited. This is usually only for debugging
        // niceness as for commands where this is mostly used the offsets actually delimit
        // the components, but e.g. for capabilities (comma-separated) it matters more.
        if (!setting_val.empty()) {
            setting_val += delimiter;
        }
    }
    else {
        setting_val.clear();
        if (part_positions != nullptr) {
            part_positions->clear();
        }
    }

    bool new_part = true;
    int part_start;

    while (i != end) {
        char c = *i;
        if (c == '\"') {
            if (new_part) {
                part_start = setting_val.length();
                new_part = false;
            }
            // quoted string
            ++i;
            while (i != end) {
                c = *i;
                if (c == '\"') break;
                else if (c == '\\') {
                    // A backslash escapes the following character.
                    c = *(++i);
                    setting_val += c;
                }
                else {
                    setting_val += c;
                }
                ++i;
            }
            if (i == end) {
                // String wasn't terminated
                throw service_description_exc(input_pos, "unterminated quoted string");
            }
        }
        else if (c == '\\') {
            if (new_part) {
                part_start = setting_val.length();
                new_part = false;
            }
            // A backslash escapes the next character
            setting_val += *(++i);
        }
        else if (isspace(c, locale::classic())) {
            if (!new_part && part_positions != nullptr) {
                part_positions->emplace_back(part_start, setting_val.length());
                new_part = true;
            }
            i = skipcomment(i, end, line_num);
            if (i == end) break;
            setting_val += ' ';  // collapse ws to a single space
            continue;
        }
        else if (c == '#') {
            // Possibly intended a comment; we require leading whitespace to reduce occurrence of accidental
            // comments in setting values.
            throw service_description_exc(input_pos, "hashmark (`#') comment must be separated from setting value by whitespace");
        }
        else {
            if (new_part) {
                part_start = setting_val.length();
                new_part = false;
            }
            setting_val += c;
        }
        ++i;
    }

    // Got to end:
    if (!new_part && part_positions != nullptr) {
        part_positions->emplace_back(part_start, setting_val.length());
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movb 0x18(%rbp), %al
movq 0x10(%rbp), %rax
movl %edx, -0x10(%rbp)
movq %rcx, -0x8(%rbp)
movq %r9, -0x18(%rbp)
movq %rdi, -0x20(%rbp)
movl %esi, -0x24(%rbp)
movq %r8, -0x30(%rbp)
leaq -0x10(%rbp), %rdi
callq 0x1abb0
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x38(%rbp), %rdx
movq -0x48(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x19660
movq %rax, -0x40(%rbp)
movq -0x30(%rbp), %rax
movq -0x40(%rbp), %rcx
movq %rcx, (%rax)
cmpl $0x2, -0x24(%rbp)
jne 0x1a4cc
movq -0x20(%rbp), %rdi
callq 0x56a0
testb $0x1, %al
jne 0x1a4ca
movb 0x18(%rbp), %al
movq -0x20(%rbp), %rdi
movsbl %al, %esi
callq 0x5290
jmp 0x1a4e7
movq -0x20(%rbp), %rdi
callq 0x5550
cmpq $0x0, 0x10(%rbp)
je 0x1a4e5
movq 0x10(%rbp), %rdi
callq 0x1abc0
jmp 0x1a4e7
movb $0x1, -0x51(%rbp)
movq -0x30(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x19700
testb $0x1, %al
jne 0x1a501
jmp 0x1a8e9
movq -0x30(%rbp), %rdi
callq 0x172b0
movb (%rax), %al
movb %al, -0x59(%rbp)
movsbl -0x59(%rbp), %eax
cmpl $0x22, %eax
jne 0x1a6a5
testb $0x1, -0x51(%rbp)
je 0x1a532
movq -0x20(%rbp), %rdi
callq 0x5620
movl %eax, -0x58(%rbp)
movb $0x0, -0x51(%rbp)
movq -0x30(%rbp), %rdi
callq 0x19740
movq -0x30(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x19700
testb $0x1, %al
jne 0x1a54e
jmp 0x1a5b3
movq -0x30(%rbp), %rdi
callq 0x172b0
movb (%rax), %al
movb %al, -0x59(%rbp)
movsbl -0x59(%rbp), %eax
cmpl $0x22, %eax
jne 0x1a567
jmp 0x1a5b3
movsbl -0x59(%rbp), %eax
cmpl $0x5c, %eax
jne 0x1a597
movq -0x30(%rbp), %rdi
callq 0x19740
movq %rax, %rdi
callq 0x172b0
movb (%rax), %al
movb %al, -0x59(%rbp)
movb -0x59(%rbp), %al
movq -0x20(%rbp), %rdi
movsbl %al, %esi
callq 0x5290
jmp 0x1a5a6
movb -0x59(%rbp), %al
movq -0x20(%rbp), %rdi
movsbl %al, %esi
callq 0x5290
jmp 0x1a5a8
movq -0x30(%rbp), %rdi
callq 0x19740
jmp 0x1a53b
movq -0x30(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x19620
testb $0x1, %al
jne 0x1a5c9
jmp 0x1a6a0
movb $0x1, -0x95(%rbp)
movl $0x70, %edi
callq 0x51c0
movq %rax, -0xf8(%rbp)
leaq -0x81(%rbp), %rdi
movq %rdi, -0xf0(%rbp)
callq 0x5700
movq -0xf0(%rbp), %rdx
leaq 0xa8d9(%rip), %rsi      # 0x24edb
leaq -0x80(%rbp), %rdi
callq 0x10f00
jmp 0x1a60d
movq -0xf8(%rbp), %rdi
leaq -0x10(%rbp), %rsi
leaq -0x80(%rbp), %rdx
callq 0x19500
jmp 0x1a623
movq -0xf8(%rbp), %rdi
movb $0x0, -0x95(%rbp)
leaq 0x176b8(%rip), %rsi     # 0x31cf0
leaq -0x10cf(%rip), %rdx     # 0x19570
callq 0x56b0
jmp 0x1a93d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0x1a678
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x5280
leaq -0x81(%rbp), %rdi
callq 0x5440
testb $0x1, -0x95(%rbp)
jne 0x1a68f
jmp 0x1a69b
movq -0xf8(%rbp), %rdi
callq 0x52f0
jmp 0x1a931
jmp 0x1a8db
movsbl -0x59(%rbp), %eax
cmpl $0x5c, %eax
jne 0x1a6e8
testb $0x1, -0x51(%rbp)
je 0x1a6c4
movq -0x20(%rbp), %rdi
callq 0x5620
movl %eax, -0x58(%rbp)
movb $0x0, -0x51(%rbp)
movq -0x30(%rbp), %rdi
callq 0x19740
movq %rax, %rdi
callq 0x172b0
movb (%rax), %al
movq -0x20(%rbp), %rdi
movsbl %al, %esi
callq 0x5290
jmp 0x1a8d9
movb -0x59(%rbp), %al
movb %al, -0xf9(%rbp)
callq 0x5570
movq %rax, %rsi
movb -0xf9(%rbp), %al
movsbl %al, %edi
callq 0x1a3a0
testb $0x1, %al
jne 0x1a710
jmp 0x1a7c3
testb $0x1, -0x51(%rbp)
jne 0x1a753
cmpq $0x0, 0x10(%rbp)
je 0x1a753
movq 0x10(%rbp), %rax
movq %rax, -0x108(%rbp)
movq -0x20(%rbp), %rdi
callq 0x5620
movq -0x108(%rbp), %rdi
movq %rax, -0xa0(%rbp)
leaq -0x58(%rbp), %rsi
leaq -0xa0(%rbp), %rdx
callq 0x1abf0
movb $0x1, -0x51(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xb0(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x38(%rbp), %rdx
movq -0xb0(%rbp), %rdi
movq -0xb8(%rbp), %rsi
callq 0x1ac40
movq %rax, -0xa8(%rbp)
movq -0x30(%rbp), %rax
movq -0xa8(%rbp), %rcx
movq %rcx, (%rax)
movq -0x30(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x19620
testb $0x1, %al
jne 0x1a7ab
jmp 0x1a7b0
jmp 0x1a8e9
movq -0x20(%rbp), %rdi
movl $0x20, %esi
callq 0x5290
jmp 0x1a4eb
movsbl -0x59(%rbp), %eax
cmpl $0x23, %eax
jne 0x1a8b0
movb $0x1, -0xda(%rbp)
movl $0x70, %edi
callq 0x51c0
movq %rax, -0x118(%rbp)
leaq -0xd9(%rbp), %rdi
movq %rdi, -0x110(%rbp)
callq 0x5700
movq -0x110(%rbp), %rdx
leaq 0xa6ed(%rip), %rsi      # 0x24ef6
leaq -0xd8(%rbp), %rdi
callq 0x10f00
jmp 0x1a817
movq -0x118(%rbp), %rdi
leaq -0x10(%rbp), %rsi
leaq -0xd8(%rbp), %rdx
callq 0x19500
jmp 0x1a830
movq -0x118(%rbp), %rdi
movb $0x0, -0xda(%rbp)
leaq 0x174ab(%rip), %rsi     # 0x31cf0
leaq -0x12dc(%rip), %rdx     # 0x19570
callq 0x56b0
jmp 0x1a93d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0x1a888
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x5280
leaq -0xd9(%rbp), %rdi
callq 0x5440
testb $0x1, -0xda(%rbp)
jne 0x1a89f
jmp 0x1a8ab
movq -0x118(%rbp), %rdi
callq 0x52f0
jmp 0x1a931
testb $0x1, -0x51(%rbp)
je 0x1a8c6
movq -0x20(%rbp), %rdi
callq 0x5620
movl %eax, -0x58(%rbp)
movb $0x0, -0x51(%rbp)
movb -0x59(%rbp), %al
movq -0x20(%rbp), %rdi
movsbl %al, %esi
callq 0x5290
jmp 0x1a8d7
jmp 0x1a8d9
jmp 0x1a8db
movq -0x30(%rbp), %rdi
callq 0x19740
jmp 0x1a4eb
testb $0x1, -0x51(%rbp)
jne 0x1a928
cmpq $0x0, 0x10(%rbp)
je 0x1a928
movq 0x10(%rbp), %rax
movq %rax, -0x120(%rbp)
movq -0x20(%rbp), %rdi
callq 0x5620
movq -0x120(%rbp), %rdi
movq %rax, -0xe8(%rbp)
leaq -0x58(%rbp), %rsi
leaq -0xe8(%rbp), %rdx
callq 0x1abf0
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
movq -0x90(%rbp), %rdi
callq 0x56f0
nopl (%rax)