// File: davmac314[P]dinit/src/load-service.cc
// Function: process_dep_dir(dirload_service_set&, char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::__cxx11::list<prelim_dep, std::allocator<prelim_dep>>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, dependency_type, service_record const*)
static void process_dep_dir(dirload_service_set &sset,
        const char *servicename,
        const string &service_filename,
        std::list<prelim_dep> &deplist, const std::string &depdirpath,
        dependency_type dep_type,
        const service_record *avoid_circular)
{
    std::string depdir_fname = combine_paths(parent_path(service_filename), depdirpath.c_str());

    DIR *depdir = opendir(depdir_fname.c_str());
    if (depdir == nullptr) {
        log(loglevel_t::WARN, "Could not open dependency directory '", depdir_fname,
                "' for ", servicename, " service.");
        return;
    }

    errno = 0;
    dirent * dent = readdir(depdir);
    while (dent != nullptr) {
        char * name =  dent->d_name;
        if (name[0] != '.') {
            try {
                service_record * sr = sset.load_service(name);
                deplist.emplace_back(sr, dep_type);
            }
            catch (service_not_found &) {
                log(loglevel_t::WARN, "Ignoring unresolved dependency '", name,
                        "' in dependency directory '", depdirpath,
                        "' for ", servicename, " service.");
            }
        }
        errno = 0; // errno may have changed in the meantime
        dent = readdir(depdir);
    }

    if (errno != 0) {
        log(loglevel_t::WARN, "Error reading dependency directory '", depdirpath,
                "' for ", servicename, " service.");
    }

    closedir(depdir);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
movq -0x18(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0x36ba0
movq -0x70(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x31220
movq %rax, -0x60(%rbp)
movq %rdx, -0x58(%rbp)
movq -0x28(%rbp), %rdi
callq 0xa250
movq %rax, %rcx
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
leaq -0x50(%rbp), %rdi
movq %rdi, -0xb8(%rbp)
callq 0x2e820
movq -0xb8(%rbp), %rdi
callq 0xa250
movq %rax, %rdi
callq 0xab30
movq %rax, -0xb0(%rbp)
jmp 0x2b81a
movq -0xb0(%rbp), %rax
movq %rax, -0x78(%rbp)
cmpq $0x0, -0x78(%rbp)
jne 0x2b876
movl $0x2, %edi
leaq 0x4cc49(%rip), %rsi     # 0x78481
leaq -0x50(%rbp), %rdx
leaq 0x4cc64(%rip), %rcx     # 0x784a7
leaq -0x10(%rbp), %r8
leaq 0x4c1e5(%rip), %r9      # 0x77a33
callq 0x2ba30
movl $0x1, -0x88(%rbp)
jmp 0x2ba09
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x2ba1b
callq 0xa060
movl $0x0, (%rax)
movq -0x78(%rbp), %rdi
callq 0xab60
movq %rax, -0xc0(%rbp)
jmp 0x2b893
movq -0xc0(%rbp), %rax
movq %rax, -0x90(%rbp)
cmpq $0x0, -0x90(%rbp)
je 0x2b9c3
movq -0x90(%rbp), %rax
addq $0x13, %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2e, %eax
je 0x2b993
movq -0x8(%rbp), %rdi
movq -0x98(%rbp), %rsi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movq %rax, -0xc8(%rbp)
jmp 0x2b8f1
movq -0xc8(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x20(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
leaq -0x2c(%rbp), %rdx
callq 0x4a3e0
jmp 0x2b915
jmp 0x2b991
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
movl -0x84(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x2ba1b
movq -0x80(%rbp), %rdi
callq 0xa240
movq %rax, -0xa8(%rbp)
movq -0x28(%rbp), %r8
leaq 0x4c0df(%rip), %rcx     # 0x77a33
movq %rsp, %rax
movq %rcx, 0x8(%rax)
leaq -0x10(%rbp), %rcx
movq %rcx, (%rax)
leaq 0x4cb45(%rip), %rsi     # 0x784ae
leaq 0x4cb5f(%rip), %rcx     # 0x784cf
leaq 0x4cb30(%rip), %r9      # 0x784a7
movl $0x2, %edi
leaq -0x98(%rbp), %rdx
callq 0x2ba80
callq 0xac30
jmp 0x2b98f
jmp 0x2b991
jmp 0x2b993
callq 0xa060
movl $0x0, (%rax)
movq -0x78(%rbp), %rdi
callq 0xab60
movq %rax, -0xd0(%rbp)
jmp 0x2b9b0
movq -0xd0(%rbp), %rax
movq %rax, -0x90(%rbp)
jmp 0x2b8a1
callq 0xa060
cmpl $0x0, (%rax)
je 0x2b9f4
movq -0x28(%rbp), %rdx
movl $0x2, %edi
leaq 0x4cb0e(%rip), %rsi     # 0x784eb
leaq 0x4cac3(%rip), %rcx     # 0x784a7
leaq -0x10(%rbp), %r8
leaq 0x4c044(%rip), %r9      # 0x77a33
callq 0x2bae0
movq -0x78(%rbp), %rdi
callq 0xabd0
jmp 0x2b9ff
movl $0x0, -0x88(%rbp)
leaq -0x50(%rbp), %rdi
callq 0xade8
addq $0xe0, %rsp
popq %rbp
retq
leaq -0x50(%rbp), %rdi
callq 0xade8
movq -0x80(%rbp), %rdi
callq 0xacc0
nopl (%rax)