// File: davmac314[P]dinit/src/includes/load-service.h
// Function: dinit_load::fill_environment_userinfo(unsigned int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, environment&)
inline void fill_environment_userinfo(uid_t uid, const std::string &service_name, environment &env)
{
    if (uid == (uid_t)-1) {
        uid = geteuid();
    }

    char buf[std::numeric_limits<unsigned long long>::digits10 + 1];
    snprintf(buf, sizeof(buf), "%llu", (unsigned long long)uid);

    errno = 0;
    struct passwd *pwent = getpwuid(uid);

    if (!pwent) {
        if (!errno) {
            throw service_load_exc(service_name, std::string("user id '") + buf + "' does not exist in system database");
        } else {
            throw service_load_exc(service_name, std::string("error accessing user database: ") + strerror(errno));
        }
    }

    std::string enval;

    // USER
    enval = "USER=";
    enval += pwent->pw_name;
    env.set_var(std::move(enval));
    // LOGNAME
    enval = "LOGNAME=";
    enval += pwent->pw_name;
    env.set_var(std::move(enval));
    // HOME
    enval = "HOME=";
    enval += pwent->pw_dir;
    env.set_var(std::move(enval));
    // SHELL
    enval = "SHELL=";
    enval += pwent->pw_shell;
    env.set_var(std::move(enval));
    // UID (non-standard, but useful)
    enval = "UID=";
    snprintf(buf, sizeof(buf), "%llu", (unsigned long long)pwent->pw_uid);
    enval += buf;
    env.set_var(std::move(enval));
    // GID (non-standard, but useful)
    enval = "GID=";
    snprintf(buf, sizeof(buf), "%llu", (unsigned long long)pwent->pw_gid);
    enval += buf;
    env.set_var(std::move(enval));
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
cmpl $-0x1, -0x4(%rbp)
jne 0x15dc4
callq 0x52c0
movl %eax, -0x4(%rbp)
leaq -0x30(%rbp), %rdi
movl -0x4(%rbp), %eax
movl %eax, %ecx
movl $0x14, %esi
leaq 0x23d10(%rip), %rdx     # 0x39ae9
movb $0x0, %al
callq 0x57d0
callq 0x5070
movl $0x0, (%rax)
movl -0x4(%rbp), %edi
callq 0x55b0
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x16093
callq 0x5070
cmpl $0x0, (%rax)
jne 0x15f61
movb $0x1, -0xad(%rbp)
movl $0x40, %edi
callq 0x5220
movq %rax, -0x130(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x128(%rbp)
leaq -0x99(%rbp), %rdi
movq %rdi, -0x120(%rbp)
callq 0x5880
movq -0x120(%rbp), %rdx
leaq 0x23c9a(%rip), %rsi     # 0x39aee
leaq -0x98(%rbp), %rdi
callq 0x13710
jmp 0x15e62
leaq -0x78(%rbp), %rdi
leaq -0x98(%rbp), %rsi
leaq -0x30(%rbp), %rdx
callq 0x16640
jmp 0x15e78
leaq 0x23c79(%rip), %rdx     # 0x39af8
leaq -0x58(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x16640
jmp 0x15e8e
movq -0x128(%rbp), %rsi
movq -0x130(%rbp), %rdi
leaq -0x58(%rbp), %rdx
callq 0x15d30
jmp 0x15ea7
movq -0x130(%rbp), %rdi
movb $0x0, -0xad(%rbp)
leaq 0x3acc4(%rip), %rsi     # 0x50b80
leaq -0x153(%rip), %rdx      # 0x15d70
callq 0x5840
jmp 0x162a9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
jmp 0x15f39
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
jmp 0x15f2d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
jmp 0x15f24
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x5320
leaq -0x78(%rbp), %rdi
callq 0x5320
leaq -0x98(%rbp), %rdi
callq 0x5320
leaq -0x99(%rbp), %rdi
callq 0x5520
testb $0x1, -0xad(%rbp)
jne 0x15f50
jmp 0x15f5c
movq -0x130(%rbp), %rdi
callq 0x53a0
jmp 0x1629d
movb $0x1, -0xf2(%rbp)
movl $0x40, %edi
callq 0x5220
movq %rax, -0x148(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x140(%rbp)
leaq -0xf1(%rbp), %rdi
movq %rdi, -0x138(%rbp)
callq 0x5880
movq -0x138(%rbp), %rdx
leaq 0x23b77(%rip), %rsi     # 0x39b1c
leaq -0xf0(%rbp), %rdi
callq 0x13710
jmp 0x15fb3
callq 0x5070
movl (%rax), %edi
callq 0x5160
movq %rax, %rdx
leaq -0xd0(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x16640
jmp 0x15fd7
movq -0x140(%rbp), %rsi
movq -0x148(%rbp), %rdi
leaq -0xd0(%rbp), %rdx
callq 0x15d30
jmp 0x15ff3
movq -0x148(%rbp), %rdi
movb $0x0, -0xf2(%rbp)
leaq 0x3ab78(%rip), %rsi     # 0x50b80
leaq -0x29f(%rip), %rdx      # 0x15d70
callq 0x5840
jmp 0x162a9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
jmp 0x1606b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
jmp 0x1605f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x5320
leaq -0xf0(%rbp), %rdi
callq 0x5320
leaq -0xf1(%rbp), %rdi
callq 0x5520
testb $0x1, -0xf2(%rbp)
jne 0x16082
jmp 0x1608e
movq -0x148(%rbp), %rdi
callq 0x53a0
jmp 0x1629d
leaq -0x118(%rbp), %rdi
movq %rdi, -0x150(%rbp)
callq 0x5700
movq -0x150(%rbp), %rdi
leaq 0x23a88(%rip), %rsi     # 0x39b3c
callq 0x56d0
jmp 0x160bb
movq -0x38(%rbp), %rax
movq (%rax), %rsi
leaq -0x118(%rbp), %rdi
callq 0x5480
jmp 0x160d0
movq -0x18(%rbp), %rdi
leaq -0x118(%rbp), %rsi
xorl %edx, %edx
callq 0x162b0
jmp 0x160e4
leaq 0x23a57(%rip), %rsi     # 0x39b42
leaq -0x118(%rbp), %rdi
callq 0x56d0
jmp 0x160f9
movq -0x38(%rbp), %rax
movq (%rax), %rsi
leaq -0x118(%rbp), %rdi
callq 0x5480
jmp 0x1610e
movq -0x18(%rbp), %rdi
leaq -0x118(%rbp), %rsi
xorl %edx, %edx
callq 0x162b0
jmp 0x16122
leaq 0x23a22(%rip), %rsi     # 0x39b4b
leaq -0x118(%rbp), %rdi
callq 0x56d0
jmp 0x16137
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rsi
leaq -0x118(%rbp), %rdi
callq 0x5480
jmp 0x1614d
movq -0x18(%rbp), %rdi
leaq -0x118(%rbp), %rsi
xorl %edx, %edx
callq 0x162b0
jmp 0x16161
leaq 0x239e9(%rip), %rsi     # 0x39b51
leaq -0x118(%rbp), %rdi
callq 0x56d0
jmp 0x16176
movq -0x38(%rbp), %rax
movq 0x28(%rax), %rsi
leaq -0x118(%rbp), %rdi
callq 0x5480
jmp 0x1618c
movq -0x18(%rbp), %rdi
leaq -0x118(%rbp), %rsi
xorl %edx, %edx
callq 0x162b0
jmp 0x161a0
leaq 0x239b1(%rip), %rsi     # 0x39b58
leaq -0x118(%rbp), %rdi
callq 0x56d0
jmp 0x161b5
movq -0x38(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, %ecx
leaq 0x23924(%rip), %rdx     # 0x39ae9
xorl %eax, %eax
leaq -0x30(%rbp), %rdi
movq %rdi, -0x158(%rbp)
movl $0x14, %esi
callq 0x57d0
movq -0x158(%rbp), %rsi
leaq -0x118(%rbp), %rdi
callq 0x5480
jmp 0x161f1
movq -0x18(%rbp), %rdi
leaq -0x118(%rbp), %rsi
xorl %edx, %edx
callq 0x162b0
jmp 0x16205
leaq 0x23951(%rip), %rsi     # 0x39b5d
leaq -0x118(%rbp), %rdi
callq 0x56d0
jmp 0x1621a
movq -0x38(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, %ecx
leaq 0x238bf(%rip), %rdx     # 0x39ae9
xorl %eax, %eax
leaq -0x30(%rbp), %rdi
movq %rdi, -0x160(%rbp)
movl $0x14, %esi
callq 0x57d0
movq -0x160(%rbp), %rsi
leaq -0x118(%rbp), %rdi
callq 0x5480
jmp 0x16256
movq -0x18(%rbp), %rdi
leaq -0x118(%rbp), %rsi
xorl %edx, %edx
callq 0x162b0
jmp 0x1626a
leaq -0x118(%rbp), %rdi
callq 0x5320
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x5320
movq -0xa8(%rbp), %rdi
callq 0x5870
nopl (%rax)