#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
scalar_t__ file_exists(char *);
int /*<<< orphan*/ max_strncat(char *, char *, int);
char *newstr(char *);
char *strchr(char *, char);
int /*<<< orphan*/ strlcpy(char *, char *, int);
int strlen(char *);
int /*<<< orphan*/ strlncpy(char *, char *, int, size_t);
char *find_file_in_path_list(char *name, char *opt_suffix, char *path_list) {
  char buf[256];
  strlcpy(buf, name, sizeof(buf));
  if (file_exists(buf))
    goto found;
  if (opt_suffix) {
    max_strncat(buf, opt_suffix, sizeof(buf));
    if (file_exists(buf))
      goto found;
  }
  while (path_list && *path_list) {
    char *p = strchr(path_list, ':');
    size_t n = p ? (p - path_list) : strlen(path_list);
    strlncpy(buf, path_list, sizeof(buf), n);
    max_strncat(buf, "/", sizeof(buf));
    max_strncat(buf, name, sizeof(buf));
    if (file_exists(buf))
      goto found;
    if (opt_suffix) {
      max_strncat(buf, opt_suffix, sizeof(buf));
      if (file_exists(buf))
        goto found;
    }
    if (p)
      path_list = p + 1;
    else
      path_list = NULL;
  }
  return NULL;
found:
  return (newstr(buf));
}


x86 assembly (clang, -O0):
<find_file_in_path_list>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x100,%edx
call   1080 <strlcpy@plt>
lea    -0x120(%rbp),%rdi
call   1040 <file_exists@plt>
cmp    $0x0,%rax
je     11b7 <find_file_in_path_list+0x47>
jmp    1372 <find_file_in_path_list+0x202>
cmpq   $0x0,-0x18(%rbp)
je     11f7 <find_file_in_path_list+0x87>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x100,%edx
call   1030 <max_strncat@plt>
lea    -0x120(%rbp),%rdi
call   1040 <file_exists@plt>
cmp    $0x0,%rax
je     11f2 <find_file_in_path_list+0x82>
jmp    1372 <find_file_in_path_list+0x202>
jmp    11f7 <find_file_in_path_list+0x87>
jmp    11fc <find_file_in_path_list+0x8c>
xor    %eax,%eax
cmpq   $0x0,-0x20(%rbp)
mov    %al,-0x131(%rbp)
je     1222 <find_file_in_path_list+0xb2>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x131(%rbp)
mov    -0x131(%rbp),%al
test   $0x1,%al
jne    1235 <find_file_in_path_list+0xc5>
jmp    1365 <find_file_in_path_list+0x1f5>
mov    -0x20(%rbp),%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
mov    %rax,-0x128(%rbp)
cmpq   $0x0,-0x128(%rbp)
je     1272 <find_file_in_path_list+0x102>
mov    -0x128(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x140(%rbp)
jmp    1284 <find_file_in_path_list+0x114>
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
cltq
mov    %rax,-0x140(%rbp)
mov    -0x140(%rbp),%rax
mov    %rax,-0x130(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x130(%rbp),%rcx
mov    $0x100,%edx
call   1070 <strlncpy@plt>
lea    -0x120(%rbp),%rdi
lea    0xd44(%rip),%rsi
mov    $0x100,%edx
call   1030 <max_strncat@plt>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x100,%edx
call   1030 <max_strncat@plt>
lea    -0x120(%rbp),%rdi
call   1040 <file_exists@plt>
cmp    $0x0,%rax
je     12f6 <find_file_in_path_list+0x186>
jmp    1372 <find_file_in_path_list+0x202>
cmpq   $0x0,-0x18(%rbp)
je     1336 <find_file_in_path_list+0x1c6>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x100,%edx
call   1030 <max_strncat@plt>
lea    -0x120(%rbp),%rdi
call   1040 <file_exists@plt>
cmp    $0x0,%rax
je     1331 <find_file_in_path_list+0x1c1>
jmp    1372 <find_file_in_path_list+0x202>
jmp    1336 <find_file_in_path_list+0x1c6>
cmpq   $0x0,-0x128(%rbp)
je     1358 <find_file_in_path_list+0x1e8>
mov    -0x128(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1360 <find_file_in_path_list+0x1f0>
movq   $0x0,-0x20(%rbp)
jmp    11fc <find_file_in_path_list+0x8c>
movq   $0x0,-0x8(%rbp)
jmp    1382 <find_file_in_path_list+0x212>
lea    -0x120(%rbp),%rdi
call   1090 <newstr@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_file_in_path_list>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rdx,%rbx
mov    %rsi,%r12
mov    %rdi,%r14
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %r14,%rsi
mov    $0x100,%edx
call   1080 <strlcpy@plt>
mov    %rbp,%rdi
call   1040 <file_exists@plt>
test   %rax,%rax
je     11ca <find_file_in_path_list+0x5a>
mov    %rsp,%rdi
call   1090 <newstr@plt>
mov    %rax,%r15
mov    %r15,%rax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
test   %r12,%r12
je     11ef <find_file_in_path_list+0x7f>
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %r12,%rsi
mov    $0x100,%edx
call   1030 <max_strncat@plt>
mov    %rbp,%rdi
call   1040 <file_exists@plt>
test   %rax,%rax
jne    11aa <find_file_in_path_list+0x3a>
xor    %r15d,%r15d
test   %rbx,%rbx
je     11b5 <find_file_in_path_list+0x45>
mov    %rsp,%r13
jmp    1209 <find_file_in_path_list+0x99>
nopl   0x0(%rax)
lea    0x1(%rbp),%rbx
test   %rbp,%rbp
je     11b5 <find_file_in_path_list+0x45>
cmpb   $0x0,(%rbx)
je     11b5 <find_file_in_path_list+0x45>
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
mov    %rax,%rbp
test   %rax,%rax
je     1230 <find_file_in_path_list+0xc0>
mov    %rbp,%rcx
sub    %rbx,%rcx
jmp    123b <find_file_in_path_list+0xcb>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <strlen@plt>
movslq %eax,%rcx
mov    %r13,%rdi
mov    %rbx,%rsi
mov    $0x100,%edx
call   1070 <strlncpy@plt>
mov    %r13,%rdi
lea    0xdab(%rip),%rsi
mov    $0x100,%edx
call   1030 <max_strncat@plt>
mov    %r13,%rdi
mov    %r14,%rsi
mov    $0x100,%edx
call   1030 <max_strncat@plt>
mov    %r13,%rdi
call   1040 <file_exists@plt>
test   %rax,%rax
jne    11aa <find_file_in_path_list+0x3a>
test   %r12,%r12
je     1200 <find_file_in_path_list+0x90>
mov    %r13,%rdi
mov    %r12,%rsi
mov    $0x100,%edx
call   1030 <max_strncat@plt>
mov    %r13,%rdi
call   1040 <file_exists@plt>
test   %rax,%rax
je     1200 <find_file_in_path_list+0x90>
jmp    11aa <find_file_in_path_list+0x3a>

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
define i8* @find_file_in_path_list(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca [256 x i8]
%9 = alloca i8*
%10 = alloca i64
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%12 = load i8*, i8** %5
%13 = call i32 @strlcpy(i8* %11, i8* %12, i32 256)
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%15 = call i64 @file_exists(i8* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %3
br label %92
18: ; preds = %3
%19 = load i8*, i8** %6
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %30
21: ; preds = %18
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%23 = load i8*, i8** %6
%24 = call i32 @max_strncat(i8* %22, i8* %23, i32 256)
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%26 = call i64 @file_exists(i8* %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %21
br label %92
29: ; preds = %21
br label %30
30: ; preds = %29, %18
br label %31
31: ; preds = %90, %30
%32 = load i8*, i8** %7
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %39
34: ; preds = %31
%35 = load i8*, i8** %7
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp ne i32 %37, 0
br label %39
39: ; preds = %34, %31
%40 = phi i1 [ false, %31 ], [ %38, %34 ]
br i1 %40, label %41, label %91
41: ; preds = %39
%42 = load i8*, i8** %7
%43 = call i8* @strchr(i8* %42, i8 signext 58)
store i8* %43, i8** %9
%44 = load i8*, i8** %9
%45 = icmp ne i8* %44, null
br i1 %45, label %46, label %52
46: ; preds = %41
%47 = load i8*, i8** %9
%48 = load i8*, i8** %7
%49 = ptrtoint i8* %47 to i64
%50 = ptrtoint i8* %48 to i64
%51 = sub i64 %49, %50
br label %56
52: ; preds = %41
%53 = load i8*, i8** %7
%54 = call i32 @strlen(i8* %53)
%55 = sext i32 %54 to i64
br label %56
56: ; preds = %52, %46
%57 = phi i64 [ %51, %46 ], [ %55, %52 ]
store i64 %57, i64* %10
%58 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%59 = load i8*, i8** %7
%60 = load i64, i64* %10
%61 = call i32 @strlncpy(i8* %58, i8* %59, i32 256, i64 %60)
%62 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%63 = call i32 @max_strncat(i8* %62, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 256)
%64 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%65 = load i8*, i8** %5
%66 = call i32 @max_strncat(i8* %64, i8* %65, i32 256)
%67 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%68 = call i64 @file_exists(i8* %67)
%69 = icmp ne i64 %68, 0
br i1 %69, label %70, label %71
70: ; preds = %56
br label %92
71: ; preds = %56
%72 = load i8*, i8** %6
%73 = icmp ne i8* %72, null
br i1 %73, label %74, label %83
74: ; preds = %71
%75 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%76 = load i8*, i8** %6
%77 = call i32 @max_strncat(i8* %75, i8* %76, i32 256)
%78 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%79 = call i64 @file_exists(i8* %78)
%80 = icmp ne i64 %79, 0
br i1 %80, label %81, label %82
81: ; preds = %74
br label %92
82: ; preds = %74
br label %83
83: ; preds = %82, %71
%84 = load i8*, i8** %9
%85 = icmp ne i8* %84, null
br i1 %85, label %86, label %89
86: ; preds = %83
%87 = load i8*, i8** %9
%88 = getelementptr inbounds i8, i8* %87, i64 1
store i8* %88, i8** %7
br label %90
89: ; preds = %83
store i8* null, i8** %7
br label %90
90: ; preds = %89, %86
br label %31
91: ; preds = %39
store i8* null, i8** %4
br label %95
92: ; preds = %81, %70, %28, %17
%93 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%94 = call i8* @newstr(i8* %93)
store i8* %94, i8** %4
br label %95
95: ; preds = %92, %91
%96 = load i8*, i8** %4
ret i8* %96
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
define i8* @find_file_in_path_list(i8* %0, i8* %1, i8* %2) {
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%6 = call i32 @strlcpy(i8* %5, i8* %0, i32 256)
%7 = call i64 @file_exists(i8* %5)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %45
9: ; preds = %3
%10 = icmp eq i8* %1, null
br i1 %10, label %15, label %11
11: ; preds = %9
%12 = call i32 @max_strncat(i8* %5, i8* %1, i32 256)
%13 = call i64 @file_exists(i8* %5)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %45
15: ; preds = %11, %9
%16 = icmp eq i8* %2, null
br i1 %16, label %47, label %17
17: ; preds = %15, %43
%18 = phi i8* [ %44, %43 ], [ %2, %15 ]
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 0
br i1 %20, label %47, label %21
21: ; preds = %17
%22 = call i8* @strchr(i8* %18, i8 signext 58)
%23 = icmp eq i8* %22, null
br i1 %23, label %28, label %24
24: ; preds = %21
%25 = ptrtoint i8* %22 to i64
%26 = ptrtoint i8* %18 to i64
%27 = sub i64 %25, %26
br label %31
28: ; preds = %21
%29 = call i32 @strlen(i8* %18)
%30 = sext i32 %29 to i64
br label %31
31: ; preds = %28, %24
%32 = phi i64 [ %27, %24 ], [ %30, %28 ]
%33 = call i32 @strlncpy(i8* %5, i8* %18, i32 256, i64 %32)
%34 = call i32 @max_strncat(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 256)
%35 = call i32 @max_strncat(i8* %5, i8* %0, i32 256)
%36 = call i64 @file_exists(i8* %5)
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %45
38: ; preds = %31
br i1 %10, label %43, label %39
39: ; preds = %38
%40 = call i32 @max_strncat(i8* %5, i8* %1, i32 256)
%41 = call i64 @file_exists(i8* %5)
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %38, %39
%44 = getelementptr inbounds i8, i8* %22, i64 1
br i1 %23, label %47, label %17
45: ; preds = %39, %31, %11, %3
%46 = call i8* @newstr(i8* %5)
br label %47
47: ; preds = %43, %17, %15, %45
%48 = phi i8* [ %46, %45 ], [ null, %15 ], [ null, %17 ], [ null, %43 ]
ret i8* %48
}