// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/dinitctl.cc
// Function: find_service_desc(char const*, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&)
static std::pair<int,int> find_service_desc(const char *svc_name, const std::vector<std::string> &paths,
        std::string &service_file_path)
{
    using std::cout;
    using std::cerr;

    // We use this to store a copy of the service name without argument, if needed
    std::string svc_name_store;

    // Check for service argument which must be stripped
    auto at_ptr = svc_name;
    while (*at_ptr != '\0' && *at_ptr != '@') ++at_ptr;
    if (*at_ptr == '@') {
        svc_name_store = std::string(svc_name, at_ptr - svc_name);
        svc_name = svc_name_store.c_str();
    }

    for (std::string path : paths) {
        std::string test_path = combine_paths(path, ::string_view(svc_name, at_ptr - svc_name));

        auto sdf_fds = open_with_dir(path.c_str(), svc_name);
        if (sdf_fds.first != -1 || sdf_fds.second != ENOENT) {
            service_file_path = test_path;
            return sdf_fds;
        }
    }

    return {-1, ENOENT};
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdx, %rbx
movq %rsi, %r12
leaq 0x68(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movq %rdi, %r15
movb $0x0, (%rax)
movq %rdi, %r14
movq %rdi, %rdx
movq %rbx, 0x28(%rsp)
movzbl (%rdx), %eax
testl %eax, %eax
je 0xaaac
cmpl $0x40, %eax
je 0xaa76
incq %rdx
incq %r14
jmp 0xaa62
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0xb1e2
leaq 0x58(%rsp), %rbx
leaq 0x8(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x43b0
movq %r15, %rdi
callq 0x4150
movq (%rbx), %r15
movq (%r12), %r13
movq 0x8(%r12), %rax
movq %rax, 0x30(%rsp)
subq %r15, %r14
movabsq $0x200000000, %rbp      # imm = 0x200000000
leaq 0x8(%rsp), %r12
cmpq 0x30(%rsp), %r13
je 0xab32
movq %r12, %rdi
movq %r13, %rsi
callq 0x4420
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
leaq 0x38(%rsp), %rdi
movq %r15, %rcx
movq %r14, %r8
callq 0xcaf1
movq 0x8(%rsp), %rdi
movq %r15, %rsi
pushq $-0x64
popq %rdx
callq 0xbd15
movq %rax, %rbx
movabsq $0x2ffffffff, %rax      # imm = 0x2FFFFFFFF
cmpq %rax, %rbx
jne 0xab39
leaq 0x38(%rsp), %rdi
callq 0x4150
movq %r12, %rdi
callq 0x4150
addq $0x20, %r13
jmp 0xaacc
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0xab6b
leaq 0x38(%rsp), %rsi
movq 0x28(%rsp), %rdi
callq 0x41d0
leaq 0x38(%rsp), %rdi
callq 0x4150
leaq 0x8(%rsp), %rdi
callq 0x4150
movabsq $-0x100000000, %rbp     # imm = 0xFFFFFFFF00000000
andq %rbx, %rbp
movl %ebx, %ebx
orq %rbp, %rbx
leaq 0x58(%rsp), %rdi
callq 0x4150
movq %rbx, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x4150
jmp 0xab9e
jmp 0xabaa
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x4150
jmp 0xabad
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x4150
movq %rbx, %rdi
callq 0x4510
nop