// File: davmac314[P]dinit/src/options-processing.cc
// Function: service_dir_opt::build_paths(bool)
void service_dir_opt::build_paths(bool am_system_init)
{
    if (service_dirs.empty()) {
        bool home_service_dir_set = false;

        /* service directory name */
        if (!am_system_init) {
            const char * xdg_config_home = getenv("XDG_CONFIG_HOME");
            size_t xdg_config_home_len;
            if (xdg_config_home != nullptr && *xdg_config_home != '\0') {
                xdg_config_home_len = strlen(xdg_config_home);
                if (xdg_config_home[xdg_config_home_len - 1] == '/') {
                    // strip any trailing slash
                    --xdg_config_home_len;
                }
                size_t dinit_d_len = strlen("/dinit.d");
                size_t full_len = xdg_config_home_len + dinit_d_len + 1;
                char *service_dir_w = new char[full_len];
                std::memcpy(service_dir_w, xdg_config_home, xdg_config_home_len);
                std::memcpy(service_dir_w + xdg_config_home_len, "/dinit.d", dinit_d_len);
                service_dir_w[full_len - 1] = 0;

                service_dir_paths.emplace_back(service_dir_w, /*dyn_allocd=*/true);
                home_service_dir_set = true;
            }

            const char * user_home = get_user_home();
            if (user_home != nullptr && *user_home != '\0') {
                size_t user_home_len = strlen(user_home);
                if (xdg_config_home != nullptr && *xdg_config_home != '\0'
                        && xdg_config_home_len == (user_home_len + strlen("/.config"))
                        && strncmp(xdg_config_home, user_home, user_home_len) == 0
                        && strcmp(xdg_config_home + user_home_len, "/.config") == 0) {
                    // don't add duplicate directories:
                    goto done_user_home;
                }

                size_t dinit_d_len = strlen("/.config/dinit.d");
                size_t full_len = user_home_len + dinit_d_len + 1;
                char *service_dir_w = new char[full_len];
                std::memcpy(service_dir_w, user_home, user_home_len);
                std::memcpy(service_dir_w + user_home_len, "/.config/dinit.d", dinit_d_len);
                service_dir_w[full_len - 1] = 0;

                service_dir_paths.emplace_back(service_dir_w, /*dyn_allocd=*/true);
                home_service_dir_set = true;
            }
        }

        done_user_home:

        if (home_service_dir_set) {
            service_dir_paths.emplace_back("/etc/dinit.d/user", /*dyn_allocd=*/false);
            service_dir_paths.emplace_back("/usr/lib/dinit.d/user", /*dyn_allocd=*/false);
            service_dir_paths.emplace_back("/usr/local/lib/dinit.d/user", /*dyn_allocd=*/false);
        }
        else {
            service_dir_paths.emplace_back("/etc/dinit.d", /*dyn_allocd=*/false);
            service_dir_paths.emplace_back("/run/dinit.d", false);
            service_dir_paths.emplace_back("/usr/local/lib/dinit.d", false);
            service_dir_paths.emplace_back("/lib/dinit.d", false);
        }
    }
    else {
        for (const char *dir : service_dirs) {
            service_dir_paths.emplace_back(dir, /*dyn_allocd=*/false);
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movb %sil, %al
movq %rdi, -0x8(%rbp)
andb $0x1, %al
movb %al, -0x9(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0xa0(%rbp)
callq 0x102c0
testb $0x1, %al
jne 0x1d5c0
jmp 0x1d896
movb $0x0, -0xa(%rbp)
testb $0x1, -0x9(%rbp)
jne 0x1d7ae
leaq 0x7e54(%rip), %rdi      # 0x25429
callq 0x54f0
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x1d6a5
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x1d6a5
movq -0x18(%rbp), %rdi
callq 0x5190
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rcx
subq $0x1, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2f, %eax
jne 0x1d627
movq -0x20(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x20(%rbp)
movq $0x8, -0x28(%rbp)
movq -0x20(%rbp), %rax
addq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0x5030
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x5330
movq -0x38(%rbp), %rdi
addq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rdx
leaq 0x7e4f(%rip), %rsi      # 0x254bf
callq 0x5330
movq -0xa0(%rbp), %rdi
movq -0x38(%rbp), %rax
movq -0x30(%rbp), %rcx
subq $0x1, %rcx
movb $0x0, (%rax,%rcx)
addq $0x18, %rdi
movb $0x1, -0x39(%rbp)
leaq -0x38(%rbp), %rsi
leaq -0x39(%rbp), %rdx
callq 0x1d930
movb $0x1, -0xa(%rbp)
callq 0x1d520
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x1d7ac
movq -0x48(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x1d7ac
movq -0x48(%rbp), %rdi
callq 0x5190
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x1d72e
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x1d72e
movq -0x20(%rbp), %rax
movq -0x50(%rbp), %rcx
addq $0x8, %rcx
cmpq %rcx, %rax
jne 0x1d72e
movq -0x18(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x50(%rbp), %rdx
callq 0x51b0
cmpl $0x0, %eax
jne 0x1d72e
movq -0x18(%rbp), %rdi
addq -0x50(%rbp), %rdi
leaq 0x7d1a(%rip), %rsi      # 0x25439
callq 0x55d0
cmpl $0x0, %eax
jne 0x1d72e
jmp 0x1d7b0
movq $0x10, -0x58(%rbp)
movq -0x50(%rbp), %rax
addq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rdi
callq 0x5030
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x50(%rbp), %rdx
callq 0x5330
movq -0x68(%rbp), %rdi
addq -0x50(%rbp), %rdi
movq -0x58(%rbp), %rdx
leaq 0x7ccb(%rip), %rsi      # 0x25442
callq 0x5330
movq -0xa0(%rbp), %rdi
movq -0x68(%rbp), %rax
movq -0x60(%rbp), %rcx
subq $0x1, %rcx
movb $0x0, (%rax,%rcx)
addq $0x18, %rdi
movb $0x1, -0x69(%rbp)
leaq -0x68(%rbp), %rsi
leaq -0x69(%rbp), %rdx
callq 0x1d930
movb $0x1, -0xa(%rbp)
jmp 0x1d7ae
jmp 0x1d7b0
testb $0x1, -0xa(%rbp)
je 0x1d815
movq -0xa0(%rbp), %rdi
addq $0x18, %rdi
movb $0x0, -0x6a(%rbp)
leaq 0x7c87(%rip), %rsi      # 0x25453
leaq -0x6a(%rbp), %rdx
callq 0x1d9b0
movq -0xa0(%rbp), %rdi
addq $0x18, %rdi
movb $0x0, -0x6b(%rbp)
leaq 0x7c7a(%rip), %rsi      # 0x25465
leaq -0x6b(%rbp), %rdx
callq 0x1da30
movq -0xa0(%rbp), %rdi
addq $0x18, %rdi
movb $0x0, -0x6c(%rbp)
leaq 0x7c71(%rip), %rsi      # 0x2547b
leaq -0x6c(%rbp), %rdx
callq 0x1dab0
jmp 0x1d891
movq -0xa0(%rbp), %rdi
addq $0x18, %rdi
movb $0x0, -0x6d(%rbp)
leaq 0x7c6c(%rip), %rsi      # 0x25497
leaq -0x6d(%rbp), %rdx
callq 0x1db30
movq -0xa0(%rbp), %rdi
addq $0x18, %rdi
movb $0x0, -0x6e(%rbp)
leaq 0x7c5a(%rip), %rsi      # 0x254a4
leaq -0x6e(%rbp), %rdx
callq 0x1db30
movq -0xa0(%rbp), %rdi
addq $0x18, %rdi
movb $0x0, -0x6f(%rbp)
leaq 0x7c48(%rip), %rsi      # 0x254b1
leaq -0x6f(%rbp), %rdx
callq 0x1dbb0
movq -0xa0(%rbp), %rdi
addq $0x18, %rdi
movb $0x0, -0x70(%rbp)
leaq 0x7c33(%rip), %rsi      # 0x254bb
leaq -0x70(%rbp), %rdx
callq 0x1db30
jmp 0x1d919
movq -0xa0(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rdi
callq 0x1c9c0
movq %rax, -0x80(%rbp)
movq -0x78(%rbp), %rdi
callq 0x1c9f0
movq %rax, -0x88(%rbp)
leaq -0x80(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x1ca20
testb $0x1, %al
jne 0x1d8d4
jmp 0x1d917
leaq -0x80(%rbp), %rdi
callq 0x1ca60
movq -0xa0(%rbp), %rdi
movq (%rax), %rax
movq %rax, -0x90(%rbp)
addq $0x18, %rdi
movb $0x0, -0x91(%rbp)
leaq -0x90(%rbp), %rsi
leaq -0x91(%rbp), %rdx
callq 0x1dc30
leaq -0x80(%rbp), %rdi
callq 0x1ca90
jmp 0x1d8be
jmp 0x1d919
addq $0xa0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)