// File: davmac314[P]dinit/src/includes/load-service.h
// Function: dinit_load::parse_gid_param(file_pos_ref, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, string_view, char const*)
inline gid_t parse_gid_param(file_pos_ref input_pos, const std::string &param,
        ::string_view service_name, const char *setting_name)
{
    const char * gid_err_msg = "specified group id contains invalid numeric characters or is "
            "outside allowed range.";

    // Could be a name or a numeric id. But we should assume numeric first, just in case
    // a user manages to give themselves a username that parses as a number.
    std::size_t ind = 0;
    try {
        // POSIX does not specify whether uid_t is an signed or unsigned, but regardless
        // is is probably safe to assume that valid values are positive. We'll also assume
        // that the value range fits with "unsigned long long" since it seems unlikely
        // that would ever not be the case.
        static_assert((uintmax_t)std::numeric_limits<gid_t>::max()
                <= (uintmax_t)std::numeric_limits<unsigned long long>::max(), "gid_t is too large");
        unsigned long long v = std::stoull(param, &ind, 0);
        if (v > static_cast<unsigned long long>(std::numeric_limits<gid_t>::max())
                || ind != param.length()) {
            throw service_description_exc(service_name, std::string(setting_name) + ": " + gid_err_msg,
                    input_pos);
        }
        return v;
    }
    catch (std::out_of_range &exc) {
        throw service_description_exc(service_name, std::string(setting_name) + ": " + gid_err_msg,
                input_pos);
    }
    catch (std::invalid_argument &exc) {
        // Ok, so it doesn't look like a number: proceed...
    }

    errno = 0;
    struct group * grent = getgrnam(param.c_str());
    if (grent == nullptr) {
        // Maybe an error, maybe just no entry.
        if (errno == 0) {
            throw service_description_exc(service_name, std::string(setting_name) + ": specified group \""
                    + param + "\" does not exist in system database.", input_pos);
        }
        else {
            throw service_description_exc(service_name, std::string("error accessing group database: ")
                    + strerror(errno), input_pos);
        }
    }

    return grent->gr_gid;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x310, %rsp            # imm = 0x310
movl %edi, -0x18(%rbp)
movq %rsi, -0x10(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x20(%rbp)
movq %rdx, -0x30(%rbp)
movq %r9, -0x38(%rbp)
leaq 0x9661(%rip), %rax      # 0x3a56a
movq %rax, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x30(%rbp), %rdi
leaq -0x48(%rbp), %rsi
xorl %edx, %edx
callq 0x331b0
movq %rax, -0x2a0(%rbp)
jmp 0x30f2d
movq -0x2a0(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x2a8(%rbp)
callq 0x31ad0
movl %eax, %ecx
movq -0x2a8(%rbp), %rax
movl %ecx, %ecx
cmpq %rcx, %rax
ja 0x30f7f
movq -0x48(%rbp), %rax
movq %rax, -0x2b0(%rbp)
movq -0x30(%rbp), %rdi
callq 0x5770
movq %rax, %rcx
movq -0x2b0(%rbp), %rax
cmpq %rcx, %rax
je 0x31231
movb $0x1, -0xe2(%rbp)
movl $0x70, %edi
callq 0x5220
movq %rax, -0x2b8(%rbp)
leaq -0x80(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x151c0
jmp 0x30fa6
movq -0x38(%rbp), %rax
movq %rax, -0x2c8(%rbp)
leaq -0xe1(%rbp), %rdi
movq %rdi, -0x2c0(%rbp)
callq 0x5880
movq -0x2c8(%rbp), %rsi
movq -0x2c0(%rbp), %rdx
leaq -0xe0(%rbp), %rdi
callq 0x13710
jmp 0x30fe0
leaq 0x8778(%rip), %rdx      # 0x3975f
leaq -0xc0(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x16640
jmp 0x30ffc
movq -0x40(%rbp), %rdx
leaq -0xa0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x16640
jmp 0x31015
movq -0x2b8(%rbp), %rdi
leaq -0x80(%rbp), %rsi
leaq -0xa0(%rbp), %rdx
leaq -0x18(%rbp), %rcx
callq 0x2e2d0
jmp 0x31032
movq -0x2b8(%rbp), %rdi
movb $0x0, -0xe2(%rbp)
leaq 0x1fba9(%rip), %rsi     # 0x50bf0
leaq -0x32fe(%rip), %rdx     # 0x2dd50
callq 0x5840
jmp 0x3163f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x310ff
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x310e6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x310d1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x310c5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x310b9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x5320
leaq -0xc0(%rbp), %rdi
callq 0x5320
leaq -0xe0(%rbp), %rdi
callq 0x5320
leaq -0xe1(%rbp), %rdi
callq 0x5520
leaq -0x80(%rbp), %rdi
callq 0x5320
testb $0x1, -0xe2(%rbp)
jne 0x310f1
jmp 0x310fd
movq -0x2b8(%rbp), %rdi
callq 0x53a0
jmp 0x310ff
movl -0x5c(%rbp), %eax
movl %eax, -0x2cc(%rbp)
movl $0x2, %ecx
cmpl %ecx, %eax
jne 0x31204
movq -0x58(%rbp), %rdi
callq 0x51a0
movq %rax, -0xf8(%rbp)
movb $0x1, -0x17a(%rbp)
movl $0x70, %edi
callq 0x5220
movq %rax, -0x2d8(%rbp)
leaq -0x118(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x151c0
jmp 0x3114f
movq -0x38(%rbp), %rax
movq %rax, -0x2e8(%rbp)
leaq -0x179(%rbp), %rdi
movq %rdi, -0x2e0(%rbp)
callq 0x5880
movq -0x2e8(%rbp), %rsi
movq -0x2e0(%rbp), %rdx
leaq -0x178(%rbp), %rdi
callq 0x13710
jmp 0x31189
leaq 0x85cf(%rip), %rdx      # 0x3975f
leaq -0x158(%rbp), %rdi
leaq -0x178(%rbp), %rsi
callq 0x16640
jmp 0x311a5
movq -0x40(%rbp), %rdx
leaq -0x138(%rbp), %rdi
leaq -0x158(%rbp), %rsi
callq 0x16640
jmp 0x311be
movq -0x2d8(%rbp), %rdi
leaq -0x118(%rbp), %rsi
leaq -0x138(%rbp), %rdx
leaq -0x18(%rbp), %rcx
callq 0x2e2d0
jmp 0x311de
movq -0x2d8(%rbp), %rdi
movb $0x0, -0x17a(%rbp)
leaq 0x1f9fd(%rip), %rsi     # 0x50bf0
leaq -0x34aa(%rip), %rdx     # 0x2dd50
callq 0x5840
jmp 0x3163f
movl -0x2cc(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x3162e
movq -0x58(%rbp), %rdi
callq 0x51a0
movq %rax, -0xf0(%rbp)
callq 0x5810
jmp 0x312e0
movq -0x50(%rbp), %rax
movl %eax, -0x4(%rbp)
jmp 0x31622
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x312bd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x312a5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x31299
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x3128d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x138(%rbp), %rdi
callq 0x5320
leaq -0x158(%rbp), %rdi
callq 0x5320
leaq -0x178(%rbp), %rdi
callq 0x5320
leaq -0x179(%rbp), %rdi
callq 0x5520
leaq -0x118(%rbp), %rdi
callq 0x5320
testb $0x1, -0x17a(%rbp)
jne 0x312c8
jmp 0x312d4
movq -0x2d8(%rbp), %rdi
callq 0x53a0
callq 0x5810
jmp 0x312db
jmp 0x3162e
callq 0x5070
movl $0x0, (%rax)
movq -0x30(%rbp), %rdi
callq 0x51b0
movq %rax, %rdi
callq 0x5470
movq %rax, -0x188(%rbp)
cmpq $0x0, -0x188(%rbp)
jne 0x31615
callq 0x5070
cmpl $0x0, (%rax)
jne 0x314d3
movb $0x1, -0x22a(%rbp)
movl $0x70, %edi
callq 0x5220
movq %rax, -0x2f0(%rbp)
leaq -0x1a8(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x151c0
jmp 0x31349
movq -0x38(%rbp), %rax
movq %rax, -0x300(%rbp)
leaq -0x229(%rbp), %rdi
movq %rdi, -0x2f8(%rbp)
callq 0x5880
movq -0x300(%rbp), %rsi
movq -0x2f8(%rbp), %rdx
leaq -0x228(%rbp), %rdi
callq 0x13710
jmp 0x31383
leaq 0x9234(%rip), %rdx      # 0x3a5be
leaq -0x208(%rbp), %rdi
leaq -0x228(%rbp), %rsi
callq 0x16640
jmp 0x3139f
movq -0x30(%rbp), %rdx
leaq -0x1e8(%rbp), %rdi
leaq -0x208(%rbp), %rsi
callq 0x16dd0
jmp 0x313b8
leaq 0x917f(%rip), %rdx      # 0x3a53e
leaq -0x1c8(%rbp), %rdi
leaq -0x1e8(%rbp), %rsi
callq 0x16640
jmp 0x313d4
movq -0x2f0(%rbp), %rdi
leaq -0x1a8(%rbp), %rsi
leaq -0x1c8(%rbp), %rdx
leaq -0x18(%rbp), %rcx
callq 0x2e2d0
jmp 0x313f4
movq -0x2f0(%rbp), %rdi
movb $0x0, -0x22a(%rbp)
leaq 0x1f7e7(%rip), %rsi     # 0x50bf0
leaq -0x36c0(%rip), %rdx     # 0x2dd50
callq 0x5840
jmp 0x3163f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x314b7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x3149f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x31493
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x31487
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x3147b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x1c8(%rbp), %rdi
callq 0x5320
leaq -0x1e8(%rbp), %rdi
callq 0x5320
leaq -0x208(%rbp), %rdi
callq 0x5320
leaq -0x228(%rbp), %rdi
callq 0x5320
leaq -0x229(%rbp), %rdi
callq 0x5520
leaq -0x1a8(%rbp), %rdi
callq 0x5320
testb $0x1, -0x22a(%rbp)
jne 0x314c2
jmp 0x314ce
movq -0x2f0(%rbp), %rdi
callq 0x53a0
jmp 0x3162e
movb $0x1, -0x292(%rbp)
movl $0x70, %edi
callq 0x5220
movq %rax, -0x308(%rbp)
leaq -0x250(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x151c0
jmp 0x314fd
leaq -0x291(%rbp), %rdi
movq %rdi, -0x310(%rbp)
callq 0x5880
movq -0x310(%rbp), %rdx
leaq 0x90b4(%rip), %rsi      # 0x3a5d2
leaq -0x290(%rbp), %rdi
callq 0x13710
jmp 0x3152c
callq 0x5070
movl (%rax), %edi
callq 0x5160
movq %rax, %rdx
leaq -0x270(%rbp), %rdi
leaq -0x290(%rbp), %rsi
callq 0x16640
jmp 0x31550
movq -0x308(%rbp), %rdi
leaq -0x250(%rbp), %rsi
leaq -0x270(%rbp), %rdx
leaq -0x18(%rbp), %rcx
callq 0x2e2d0
jmp 0x31570
movq -0x308(%rbp), %rdi
movb $0x0, -0x292(%rbp)
leaq 0x1f66b(%rip), %rsi     # 0x50bf0
leaq -0x383c(%rip), %rdx     # 0x2dd50
callq 0x5840
jmp 0x3163f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x315fc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x315e4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x315d8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x270(%rbp), %rdi
callq 0x5320
leaq -0x290(%rbp), %rdi
callq 0x5320
leaq -0x291(%rbp), %rdi
callq 0x5520
leaq -0x250(%rbp), %rdi
callq 0x5320
testb $0x1, -0x292(%rbp)
jne 0x31607
jmp 0x31613
movq -0x308(%rbp), %rdi
callq 0x53a0
jmp 0x3162e
movq -0x188(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x310, %rsp            # imm = 0x310
popq %rbp
retq
movq -0x58(%rbp), %rdi
callq 0x5870
movq %rax, %rdi
callq 0x138d0
nop