// File: /workspace/github_cpp_makefile_star2_O2/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 0xe366
addq $0x18, %rbx
leaq 0x10(%rsp), %r14
leaq 0xf(%rsp), %r15
cmpq %r13, %r12
je 0xe56c
movq (%r12), %rax
movq %rax, 0x10(%rsp)
movb $0x0, 0xf(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0xe6e6
addq $0x8, %r12
jmp 0xe33b
testb %sil, %sil
jne 0xe501
leaq 0x50f0(%rip), %rdi      # 0x13466
callq 0x43a0
movq %rax, %r14
testq %rax, %rax
je 0xe3f9
cmpb $0x0, (%r14)
je 0xe3f9
movq %r14, %rdi
callq 0x4140
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 0x4280
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 0xe57c
movb $0x1, %bpl
jmp 0xe3fb
xorl %ebp, %ebp
callq 0xe2c0
testq %rax, %rax
je 0xe4a9
movq %rax, %r12
cmpb $0x0, (%rax)
je 0xe4a9
movq %r12, %rdi
callq 0x4140
movq %rax, %r13
testq %r14, %r14
je 0xe45c
cmpb $0x0, (%r14)
je 0xe45c
leaq 0x8(%r13), %rax
cmpq %rax, %r15
jne 0xe45c
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x4170
testl %eax, %eax
jne 0xe45c
addq %r13, %r14
leaq 0x5026(%rip), %rsi      # 0x13476
movq %r14, %rdi
callq 0x4450
testl %eax, %eax
je 0xe4a9
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 0x4280
movups 0x4ff7(%rip), %xmm0     # 0x1347f
movups %xmm0, (%r14,%r13)
movb $0x0, 0x10(%r14,%r13)
leaq 0x18(%rbx), %rdi
leaq 0xf(%rsp), %rdx
movb $0x1, (%rdx)
movq %r15, %rsi
callq 0xe57c
jmp 0xe4ae
testb %bpl, %bpl
je 0xe501
addq $0x18, %rbx
xorl %ebp, %ebp
leaq 0x10(%rsp), %r14
movb %bpl, (%r14)
leaq 0x4fcd(%rip), %rsi      # 0x13490
movq %rbx, %rdi
movq %r14, %rdx
callq 0xe5ba
movb %bpl, (%r14)
leaq 0x4fca(%rip), %rsi      # 0x134a2
leaq 0x10(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rdx
callq 0xe5f6
movb %bpl, (%r14)
leaq 0x4fc6(%rip), %rsi      # 0x134b8
leaq 0x10(%rsp), %rdx
movq %rbx, %rdi
callq 0xe632
jmp 0xe56c
addq $0x18, %rbx
xorl %ebp, %ebp
leaq 0x10(%rsp), %r14
movb %bpl, (%r14)
leaq 0x4fbe(%rip), %rsi      # 0x134d4
movq %rbx, %rdi
movq %r14, %rdx
callq 0xe66e
movb %bpl, (%r14)
leaq 0x4fb6(%rip), %rsi      # 0x134e1
leaq 0x10(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rdx
callq 0xe66e
movb %bpl, (%r14)
leaq 0x4fa9(%rip), %rsi      # 0x134ee
leaq 0x10(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rdx
callq 0xe6aa
movb %bpl, (%r14)
leaq 0x4f99(%rip), %rsi      # 0x134f8
leaq 0x10(%rsp), %rdx
movq %rbx, %rdi
callq 0xe66e
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop