// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movq (%rdi), %r12
movq 0x8(%rdi), %r13
cmpq %r13, %r12
je 0x123d9
addq $0x18, %rbx
leaq 0x10(%rsp), %r14
leaq 0xf(%rsp), %r15
movq (%r12), %rax
movq %rax, 0x10(%rsp)
movb $0x0, 0xf(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x12744
addq $0x8, %r12
cmpq %r13, %r12
jne 0x123af
jmp 0x125e0
testb %sil, %sil
jne 0x12575
leaq 0x50a2(%rip), %rdi      # 0x1748b
callq 0x4380
movq %rax, %r14
testq %rax, %rax
je 0x1246c
cmpb $0x0, (%r14)
je 0x1246c
movq %r14, %rdi
callq 0x4150
xorl %ecx, %ecx
cmpb $0x2f, -0x1(%r14,%rax)
sete %cl
movq %rax, %r15
subq %rcx, %r15
negq %rcx
leaq (%rax,%rcx), %rdi
addq $0x9, %rdi
callq 0x4030
movq %rax, %r12
leaq 0x10(%rsp), %r13
movq %rax, (%r13)
movq %rax, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x4270
movabsq $0x642e74696e69642f, %rax # imm = 0x642E74696E69642F
movq %rax, (%r12,%r15)
movb $0x0, 0x8(%r12,%r15)
leaq 0x18(%rbx), %rdi
leaq 0xf(%rsp), %rdx
movb $0x1, (%rdx)
movq %r13, %rsi
callq 0x125f0
movb $0x1, %bpl
jmp 0x1246e
xorl %ebp, %ebp
callq 0x12338
testq %rax, %rax
je 0x1251d
movq %rax, %r12
cmpb $0x0, (%rax)
je 0x1251d
movq %r12, %rdi
callq 0x4150
movq %rax, %r13
testq %r14, %r14
je 0x124cf
cmpb $0x0, (%r14)
je 0x124cf
leaq 0x8(%r13), %rax
cmpq %rax, %r15
jne 0x124cf
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x4170
testl %eax, %eax
jne 0x124cf
addq %r13, %r14
leaq 0x4fd8(%rip), %rsi      # 0x1749b
movq %r14, %rdi
callq 0x4400
testl %eax, %eax
je 0x1251d
movq %r13, %rdi
addq $0x11, %rdi
callq 0x4030
movq %rax, %r14
leaq 0x10(%rsp), %r15
movq %rax, (%r15)
movq %rax, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x4270
movups 0x4fa9(%rip), %xmm0     # 0x174a4
movups %xmm0, (%r14,%r13)
movb $0x0, 0x10(%r14,%r13)
leaq 0x18(%rbx), %rdi
leaq 0xf(%rsp), %rdx
movb $0x1, (%rdx)
movq %r15, %rsi
callq 0x125f0
movb $0x1, %bpl
testb %bpl, %bpl
je 0x12575
addq $0x18, %rbx
xorl %ebp, %ebp
leaq 0x10(%rsp), %r14
movb %bpl, (%r14)
leaq 0x4f7e(%rip), %rsi      # 0x174b5
movq %rbx, %rdi
movq %r14, %rdx
callq 0x1262c
movb %bpl, (%r14)
leaq 0x4f7b(%rip), %rsi      # 0x174c7
leaq 0x10(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rdx
callq 0x12664
movb %bpl, (%r14)
leaq 0x4f77(%rip), %rsi      # 0x174dd
leaq 0x10(%rsp), %rdx
movq %rbx, %rdi
callq 0x1269c
jmp 0x125e0
addq $0x18, %rbx
xorl %ebp, %ebp
leaq 0x10(%rsp), %r14
movb %bpl, (%r14)
leaq 0x4f6f(%rip), %rsi      # 0x174f9
movq %rbx, %rdi
movq %r14, %rdx
callq 0x126d4
movb %bpl, (%r14)
leaq 0x4f67(%rip), %rsi      # 0x17506
leaq 0x10(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rdx
callq 0x126d4
movb %bpl, (%r14)
leaq 0x4f5a(%rip), %rsi      # 0x17513
leaq 0x10(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rdx
callq 0x1270c
movb %bpl, (%r14)
leaq 0x4f4a(%rip), %rsi      # 0x1751d
leaq 0x10(%rsp), %rdx
movq %rbx, %rdi
callq 0x126d4
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop