// File: /workspace/github_cpp_makefile_star2_O3/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 0x121e9
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 0x12568
addq $0x8, %r12
cmpq %r13, %r12
jne 0x121bf
jmp 0x123ef
testb %sil, %sil
jne 0x12384
leaq 0x527d(%rip), %rdi      # 0x17476
callq 0x4380
movq %rax, %r14
testq %rax, %rax
je 0x1227c
cmpb $0x0, (%r14)
je 0x1227c
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 0x123fe
movb $0x1, %bpl
jmp 0x1227e
xorl %ebp, %ebp
callq 0x12144
testq %rax, %rax
je 0x1232c
movq %rax, %r12
cmpb $0x0, (%rax)
je 0x1232c
movq %r12, %rdi
callq 0x4150
movq %rax, %r13
testq %r14, %r14
je 0x122df
cmpb $0x0, (%r14)
je 0x122df
leaq 0x8(%r13), %rax
cmpq %rax, %r15
jne 0x122df
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x4170
testl %eax, %eax
jne 0x122df
addq %r13, %r14
leaq 0x51b3(%rip), %rsi      # 0x17486
movq %r14, %rdi
callq 0x4400
testl %eax, %eax
je 0x1232c
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 0x5184(%rip), %xmm0     # 0x1748f
movups %xmm0, (%r14,%r13)
movb $0x0, 0x10(%r14,%r13)
leaq 0x18(%rbx), %rdi
leaq 0xf(%rsp), %rdx
movb $0x1, (%rdx)
movq %r15, %rsi
callq 0x123fe
jmp 0x12331
testb %bpl, %bpl
je 0x12384
addq $0x18, %rbx
xorl %ebp, %ebp
leaq 0x10(%rsp), %r14
movb %bpl, (%r14)
leaq 0x515a(%rip), %rsi      # 0x174a0
movq %rbx, %rdi
movq %r14, %rdx
callq 0x1243c
movb %bpl, (%r14)
leaq 0x5157(%rip), %rsi      # 0x174b2
leaq 0x10(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rdx
callq 0x12478
movb %bpl, (%r14)
leaq 0x5153(%rip), %rsi      # 0x174c8
leaq 0x10(%rsp), %rdx
movq %rbx, %rdi
callq 0x124b4
jmp 0x123ef
addq $0x18, %rbx
xorl %ebp, %ebp
leaq 0x10(%rsp), %r14
movb %bpl, (%r14)
leaq 0x514b(%rip), %rsi      # 0x174e4
movq %rbx, %rdi
movq %r14, %rdx
callq 0x124f0
movb %bpl, (%r14)
leaq 0x5143(%rip), %rsi      # 0x174f1
leaq 0x10(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rdx
callq 0x124f0
movb %bpl, (%r14)
leaq 0x5136(%rip), %rsi      # 0x174fe
leaq 0x10(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rdx
callq 0x1252c
movb %bpl, (%r14)
leaq 0x5126(%rip), %rsi      # 0x17508
leaq 0x10(%rsp), %rdx
movq %rbx, %rdi
callq 0x124f0
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq