#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ F_OK;
scalar_t__ access(char const *, int /*<<< orphan*/);
char *find_in_path(char const *, char *);
char *getenv(char *);
scalar_t__ should_skip_path_search(char const *);
char *strdup(char const *);
char *resolve_program_path(const char *program) {
  char *env_path;
  char *path;
  if (should_skip_path_search(program)) {
    if (access(program, F_OK) == 0)
      path = strdup(program);
    else
      path = NULL;
  } else {
    env_path = getenv("PATH");
    if (!env_path)
      path = strdup(program);
    else
      path = find_in_path(program, env_path);
  }
  return (path);
}


x86 assembly (clang, -O0):
<resolve_program_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <should_skip_path_search@plt>
cmp    $0x0,%rax
je     11aa <resolve_program_path+0x5a>
mov    -0x8(%rbp),%rdi
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
call   1060 <access@plt>
cmp    $0x0,%rax
jne    119d <resolve_program_path+0x4d>
mov    -0x8(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x18(%rbp)
jmp    11a5 <resolve_program_path+0x55>
movq   $0x0,-0x18(%rbp)
jmp    11ed <resolve_program_path+0x9d>
lea    0xe4f(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11d7 <resolve_program_path+0x87>
mov    -0x8(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x18(%rbp)
jmp    11e8 <resolve_program_path+0x98>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <find_in_path@plt>
mov    %rax,-0x18(%rbp)
jmp    11ed <resolve_program_path+0x9d>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<resolve_program_path>:
push   %rbx
mov    %rdi,%rbx
call   1040 <should_skip_path_search@plt>
test   %rax,%rax
je     1178 <resolve_program_path+0x28>
mov    0x2e73(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <access@plt>
test   %rax,%rax
je     1195 <resolve_program_path+0x45>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe81(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1195 <resolve_program_path+0x45>
mov    %rbx,%rdi
mov    %rax,%rsi
pop    %rbx
jmp    1050 <find_in_path@plt>
mov    %rbx,%rdi
pop    %rbx
jmp    1070 <strdup@plt>

LLVM IR (-O0):
@F_OK = global i32 0
@.str = [5 x i8] c"PATH\00"
define i8* @resolve_program_path(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i64 @should_skip_path_search(i8* %5)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %18
8: ; preds = %1
%9 = load i8*, i8** %2
%10 = load i32, i32* @F_OK
%11 = call i64 @access(i8* %9, i32 %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = load i8*, i8** %2
%15 = call i8* @strdup(i8* %14)
store i8* %15, i8** %4
br label %17
16: ; preds = %8
store i8* null, i8** %4
br label %17
17: ; preds = %16, %13
br label %30
18: ; preds = %1
%19 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %19, i8** %3
%20 = load i8*, i8** %3
%21 = icmp ne i8* %20, null
br i1 %21, label %25, label %22
22: ; preds = %18
%23 = load i8*, i8** %2
%24 = call i8* @strdup(i8* %23)
store i8* %24, i8** %4
br label %29
25: ; preds = %18
%26 = load i8*, i8** %2
%27 = load i8*, i8** %3
%28 = call i8* @find_in_path(i8* %26, i8* %27)
store i8* %28, i8** %4
br label %29
29: ; preds = %25, %22
br label %30
30: ; preds = %29, %17
%31 = load i8*, i8** %4
ret i8* %31
}

LLVM IR (-O2):
@F_OK = global i32 0
@.str = [5 x i8] c"PATH\00"
define i8* @resolve_program_path(i8* %0) {
%2 = tail call i64 @should_skip_path_search(i8* %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %10, label %4
4: ; preds = %1
%5 = load i32, i32* @F_OK
%6 = tail call i64 @access(i8* %0, i32 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %17
8: ; preds = %4
%9 = tail call i8* @strdup(i8* %0)
br label %17
10: ; preds = %1
%11 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = tail call i8* @strdup(i8* %0)
br label %17
15: ; preds = %10
%16 = tail call i8* @find_in_path(i8* %0, i8* %11)
br label %17
17: ; preds = %4, %13, %15, %8
%18 = phi i8* [ %9, %8 ], [ %16, %15 ], [ %14, %13 ], [ null, %4 ]
ret i8* %18
}