// File: davmac314[P]dinit/src/includes/load-service.h
// Function: dinit_load::parse_uid_param(file_pos_ref, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, char const*, unsigned int*)
inline uid_t parse_uid_param(file_pos_ref input_pos, const std::string &param,
        const std::string &service_name, const char *setting_name, gid_t *group_p)
{
    const char * uid_err_msg = "specified user 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 a signed or unsigned type, but regardless
        // is is probably safe to assume that valid values are positive. We'll also assert
        // that the value range fits within "unsigned long long" since it seems unlikely
        // that would ever not be the case.
        static_assert((uintmax_t)std::numeric_limits<uid_t>::max()
                <= (uintmax_t)std::numeric_limits<unsigned long long>::max(), "uid_t is too large");
        unsigned long long v = std::stoull(param, &ind, 0);
        if (v > static_cast<unsigned long long>(std::numeric_limits<uid_t>::max())
                || ind != param.length()) {
            throw service_description_exc(service_name, std::string(setting_name) + ": " + uid_err_msg, input_pos);
        }
        return v;
    }
    catch (std::out_of_range &exc) {
        throw service_description_exc(service_name, uid_err_msg, input_pos);
    }
    catch (std::invalid_argument &exc) {
        // Ok, so it doesn't look like a number: proceed...
    }

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

    if (group_p) {
        *group_p = pwent->pw_gid;
    }

    return pwent->pw_uid;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x270, %rsp            # imm = 0x270
movl %edi, -0x18(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
leaq 0x9c4f(%rip), %rax      # 0x3a4d8
movq %rax, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x20(%rbp), %rdi
leaq -0x48(%rbp), %rsi
xorl %edx, %edx
callq 0x331b0
movq %rax, -0x1e0(%rbp)
jmp 0x308ad
movq -0x1e0(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x1e8(%rbp)
callq 0x31ad0
movl %eax, %ecx
movq -0x1e8(%rbp), %rax
movl %ecx, %ecx
cmpq %rcx, %rax
ja 0x308ff
movq -0x48(%rbp), %rax
movq %rax, -0x1f0(%rbp)
movq -0x20(%rbp), %rdi
callq 0x5770
movq %rax, %rcx
movq -0x1f0(%rbp), %rax
cmpq %rcx, %rax
je 0x30b4e
movb $0x1, -0xc2(%rbp)
movl $0x70, %edi
callq 0x5220
movq %rax, -0x210(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x208(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x200(%rbp)
leaq -0xc1(%rbp), %rdi
movq %rdi, -0x1f8(%rbp)
callq 0x5880
movq -0x200(%rbp), %rsi
movq -0x1f8(%rbp), %rdx
leaq -0xc0(%rbp), %rdi
callq 0x13710
jmp 0x3095c
leaq 0x8dfc(%rip), %rdx      # 0x3975f
leaq -0xa0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x16640
jmp 0x30978
movq -0x40(%rbp), %rdx
leaq -0x80(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x16640
jmp 0x3098e
movq -0x208(%rbp), %rsi
movq -0x210(%rbp), %rdi
leaq -0x80(%rbp), %rdx
leaq -0x18(%rbp), %rcx
callq 0x2e2d0
jmp 0x309ab
movq -0x210(%rbp), %rdi
movb $0x0, -0xc2(%rbp)
leaq 0x20230(%rip), %rsi     # 0x50bf0
leaq -0x2c77(%rip), %rdx     # 0x2dd50
callq 0x5840
jmp 0x30ee0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x30a5b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x30a36
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x30a2a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x30a1e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x5320
leaq -0xa0(%rbp), %rdi
callq 0x5320
leaq -0xc0(%rbp), %rdi
callq 0x5320
leaq -0xc1(%rbp), %rdi
callq 0x5520
testb $0x1, -0xc2(%rbp)
jne 0x30a4d
jmp 0x30a59
movq -0x210(%rbp), %rdi
callq 0x53a0
jmp 0x30a5b
movl -0x5c(%rbp), %eax
movl %eax, -0x214(%rbp)
movl $0x2, %ecx
cmpl %ecx, %eax
jne 0x30b24
movq -0x58(%rbp), %rdi
callq 0x51a0
movq %rax, -0xd8(%rbp)
movb $0x1, -0xfa(%rbp)
movl $0x70, %edi
callq 0x5220
movq %rax, -0x238(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x230(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x228(%rbp)
leaq -0xf9(%rbp), %rdi
movq %rdi, -0x220(%rbp)
callq 0x5880
movq -0x228(%rbp), %rsi
movq -0x220(%rbp), %rdx
leaq -0xf8(%rbp), %rdi
callq 0x13710
jmp 0x30ade
movq -0x230(%rbp), %rsi
movq -0x238(%rbp), %rdi
leaq -0xf8(%rbp), %rdx
leaq -0x18(%rbp), %rcx
callq 0x2e2d0
jmp 0x30afe
movq -0x238(%rbp), %rdi
movb $0x0, -0xfa(%rbp)
leaq 0x200dd(%rip), %rsi     # 0x50bf0
leaq -0x2dca(%rip), %rdx     # 0x2dd50
callq 0x5840
jmp 0x30ee0
movl -0x214(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x30ecf
movq -0x58(%rbp), %rdi
callq 0x51a0
movq %rax, -0xd0(%rbp)
callq 0x5810
jmp 0x30baf
movq -0x50(%rbp), %rax
movl %eax, -0x4(%rbp)
jmp 0x30ec3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x30b80
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x5320
leaq -0xf9(%rbp), %rdi
callq 0x5520
testb $0x1, -0xfa(%rbp)
jne 0x30b97
jmp 0x30ba3
movq -0x238(%rbp), %rdi
callq 0x53a0
callq 0x5810
jmp 0x30baa
jmp 0x30ecf
callq 0x5070
movl $0x0, (%rax)
movq -0x20(%rbp), %rdi
callq 0x51b0
movq %rax, %rdi
callq 0x53e0
movq %rax, -0x108(%rbp)
cmpq $0x0, -0x108(%rbp)
jne 0x30e9f
callq 0x5070
cmpl $0x0, (%rax)
jne 0x30d7e
movb $0x1, -0x18a(%rbp)
movl $0x70, %edi
callq 0x5220
movq %rax, -0x258(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x250(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x248(%rbp)
leaq -0x189(%rbp), %rdi
movq %rdi, -0x240(%rbp)
callq 0x5880
movq -0x248(%rbp), %rsi
movq -0x240(%rbp), %rdx
leaq -0x188(%rbp), %rdi
callq 0x13710
jmp 0x30c4b
leaq 0x98d9(%rip), %rdx      # 0x3a52b
leaq -0x168(%rbp), %rdi
leaq -0x188(%rbp), %rsi
callq 0x16640
jmp 0x30c67
movq -0x20(%rbp), %rdx
leaq -0x148(%rbp), %rdi
leaq -0x168(%rbp), %rsi
callq 0x16dd0
jmp 0x30c80
leaq 0x98b7(%rip), %rdx      # 0x3a53e
leaq -0x128(%rbp), %rdi
leaq -0x148(%rbp), %rsi
callq 0x16640
jmp 0x30c9c
movq -0x250(%rbp), %rsi
movq -0x258(%rbp), %rdi
leaq -0x128(%rbp), %rdx
leaq -0x18(%rbp), %rcx
callq 0x2e2d0
jmp 0x30cbc
movq -0x258(%rbp), %rdi
movb $0x0, -0x18a(%rbp)
leaq 0x1ff1f(%rip), %rsi     # 0x50bf0
leaq -0x2f88(%rip), %rdx     # 0x2dd50
callq 0x5840
jmp 0x30ee0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x30d56
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x30d4a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x30d3e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x30d32
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x5320
leaq -0x148(%rbp), %rdi
callq 0x5320
leaq -0x168(%rbp), %rdi
callq 0x5320
leaq -0x188(%rbp), %rdi
callq 0x5320
leaq -0x189(%rbp), %rdi
callq 0x5520
testb $0x1, -0x18a(%rbp)
jne 0x30d6d
jmp 0x30d79
movq -0x258(%rbp), %rdi
callq 0x53a0
jmp 0x30ecf
movb $0x1, -0x1d2(%rbp)
movl $0x70, %edi
callq 0x5220
movq %rax, -0x270(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x268(%rbp)
leaq -0x1d1(%rbp), %rdi
movq %rdi, -0x260(%rbp)
callq 0x5880
movq -0x260(%rbp), %rdx
leaq 0x8d5a(%rip), %rsi      # 0x39b1c
leaq -0x1d0(%rbp), %rdi
callq 0x13710
jmp 0x30dd0
callq 0x5070
movl (%rax), %edi
callq 0x5160
movq %rax, %rdx
leaq -0x1b0(%rbp), %rdi
leaq -0x1d0(%rbp), %rsi
callq 0x16640
jmp 0x30df4
movq -0x268(%rbp), %rsi
movq -0x270(%rbp), %rdi
leaq -0x1b0(%rbp), %rdx
leaq -0x18(%rbp), %rcx
callq 0x2e2d0
jmp 0x30e14
movq -0x270(%rbp), %rdi
movb $0x0, -0x1d2(%rbp)
leaq 0x1fdc7(%rip), %rsi     # 0x50bf0
leaq -0x30e0(%rip), %rdx     # 0x2dd50
callq 0x5840
jmp 0x30ee0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x30e7a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x30e6e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0x5320
leaq -0x1d0(%rbp), %rdi
callq 0x5320
leaq -0x1d1(%rbp), %rdi
callq 0x5520
testb $0x1, -0x1d2(%rbp)
jne 0x30e91
jmp 0x30e9d
movq -0x270(%rbp), %rdi
callq 0x53a0
jmp 0x30ecf
cmpq $0x0, -0x38(%rbp)
je 0x30eb6
movq -0x108(%rbp), %rax
movl 0x14(%rax), %ecx
movq -0x38(%rbp), %rax
movl %ecx, (%rax)
movq -0x108(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x270, %rsp            # imm = 0x270
popq %rbp
retq
movq -0x58(%rbp), %rdi
callq 0x5870
movq %rax, %rdi
callq 0x138d0