// File: gdaws[P]process-monitor/monitor.cpp
// Function: find_program(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 bool find_program(const std::string & program, std::string & output_filename)
{
    if(file_exists(program))
    {
        output_filename = program;
        return true;
    }
    
    const char * search_paths = getenv("PATH");
    const char * search_paths_begin = search_paths;
    const char * search_paths_end = search_paths + strlen(search_paths);
    
    std::string filename;
    
    while(search_paths_begin < search_paths_end)
    {
        const char * limit = strstr(search_paths_begin, ":");
        if(!limit) limit = search_paths_end;
        
        filename.reserve(std::max(filename.capacity(), 
            (limit - search_paths_begin) + program.length() + 1));
        
        filename.assign(search_paths_begin, limit);
        filename.append(1, '/');
        filename.append(program);
        
        if(file_exists(filename))
        {
            output_filename = filename;
            return true;
        }
        
        search_paths_begin = (*limit == ':' ? limit + 1 : limit);
    }
    
    return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdi
callq 0x3cd0
testb $0x1, %al
jne 0x39d2
jmp 0x39e8
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdi
callq 0x3060
movb $0x1, -0x1(%rbp)
jmp 0x3b92
leaq 0xb680(%rip), %rdi      # 0xf06f
callq 0x3340
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x20(%rbp), %rdi
callq 0x3100
movq %rax, %rcx
movq -0x80(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x30(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x3390
movq -0x28(%rbp), %rax
cmpq -0x30(%rbp), %rax
jae 0x3b7e
movq -0x28(%rbp), %rdi
leaq 0xb633(%rip), %rsi      # 0xf074
callq 0x3090
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0x3a59
movq -0x30(%rbp), %rax
movq %rax, -0x58(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x3040
movq %rax, -0x60(%rbp)
movq -0x58(%rbp), %rax
movq -0x28(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x90(%rbp)
movq -0x10(%rbp), %rdi
callq 0x33b0
movq %rax, %rcx
movq -0x90(%rbp), %rax
leaq 0x1(%rax,%rcx), %rax
movq %rax, -0x68(%rbp)
leaq -0x60(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x3ea0
movq %rax, -0x88(%rbp)
jmp 0x3aaa
movq -0x88(%rbp), %rax
movq (%rax), %rsi
leaq -0x50(%rbp), %rdi
callq 0x33e0
jmp 0x3abf
movq -0x28(%rbp), %rsi
movq -0x58(%rbp), %rdx
leaq -0x50(%rbp), %rdi
callq 0x3ee0
jmp 0x3ad2
leaq -0x50(%rbp), %rdi
movl $0x1, %esi
movl $0x2f, %edx
callq 0x32d0
jmp 0x3ae7
movq -0x10(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0x3460
jmp 0x3af6
leaq -0x50(%rbp), %rdi
callq 0x3cd0
movb %al, -0x91(%rbp)
jmp 0x3b07
movb -0x91(%rbp), %al
testb $0x1, %al
jne 0x3b13
jmp 0x3b46
movq -0x18(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x3060
jmp 0x3b22
movb $0x1, -0x1(%rbp)
movl $0x1, -0x78(%rbp)
jmp 0x3b89
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x3160
jmp 0x3ba0
movq -0x58(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x3a, %eax
jne 0x3b63
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xa0(%rbp)
jmp 0x3b6e
movq -0x58(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x3a28
movb $0x0, -0x1(%rbp)
movl $0x1, -0x78(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x3160
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xa0, %rsp
popq %rbp
retq
movq -0x70(%rbp), %rdi
callq 0x3430
nopl (%rax)