#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 */
char *find_command_in_path(char const *, char const *, int *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ free(char *);
char *path_clean_up(char *);
int /*<<< orphan*/ stdout;
int path_search(int indent, const char *cmd, const char *path_list) {
  char *result = NULL;
  int found_something = 0;
  if (path_list && *path_list != '\0') {
    int next;
    int path_index = 0;
    do {
      next = 0;
      result = find_command_in_path(cmd, path_list, &path_index);
      if (result) {
        const char *full_path = path_clean_up(result);
        fprintf(stdout, "%s\n", full_path);
        free(result);
        found_something = 1;
      } else
        break;
    } while (next);
  }
  return found_something;
}


x86 assembly (clang, -O0):
<path_search>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11ff <path_search+0xbf>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11ff <path_search+0xbf>
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   1050 <find_command_in_path@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11e6 <path_search+0xa6>
mov    -0x20(%rbp),%rdi
call   1060 <path_clean_up@plt>
mov    %rax,-0x38(%rbp)
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rdx
lea    0xe34(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x24(%rbp)
jmp    11eb <path_search+0xab>
jmp    11fa <path_search+0xba>
jmp    11f0 <path_search+0xb0>
cmpl   $0x0,-0x28(%rbp)
jne    1184 <path_search+0x44>
jmp    11ff <path_search+0xbf>
mov    -0x24(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<path_search>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
test   %rdx,%rdx
je     11a5 <path_search+0x65>
cmpb   $0x0,(%rdx)
je     11a5 <path_search+0x65>
movl   $0x0,0xc(%rsp)
lea    0xc(%rsp),%rax
mov    %rsi,%rdi
mov    %rdx,%rsi
mov    %rax,%rdx
call   1050 <find_command_in_path@plt>
test   %rax,%rax
je     11a3 <path_search+0x63>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <path_clean_up@plt>
mov    0x2e5d(%rip),%rcx
mov    (%rcx),%edi
lea    0xe74(%rip),%rsi
mov    %rax,%rdx
call   1040 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x1,%eax
jmp    11a5 <path_search+0x65>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [4 x i8] c"%s\0A\00"
define i32 @path_search(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
store i32 %0, i32* %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store i8* null, i8** %7
store i32 0, i32* %8
%12 = load i8*, i8** %6
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %40
14: ; preds = %3
%15 = load i8*, i8** %6
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %40
19: ; preds = %14
store i32 0, i32* %10
br label %20
20: ; preds = %36, %19
store i32 0, i32* %9
%21 = load i8*, i8** %5
%22 = load i8*, i8** %6
%23 = call i8* @find_command_in_path(i8* %21, i8* %22, i32* %10)
store i8* %23, i8** %7
%24 = load i8*, i8** %7
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %34
26: ; preds = %20
%27 = load i8*, i8** %7
%28 = call i8* @path_clean_up(i8* %27)
store i8* %28, i8** %11
%29 = load i32, i32* @stdout
%30 = load i8*, i8** %11
%31 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %30)
%32 = load i8*, i8** %7
%33 = call i32 @free(i8* %32)
store i32 1, i32* %8
br label %35
34: ; preds = %20
br label %39
35: ; preds = %26
br label %36
36: ; preds = %35
%37 = load i32, i32* %9
%38 = icmp ne i32 %37, 0
br i1 %38, label %20, label %39
39: ; preds = %36, %34
br label %40
40: ; preds = %39, %14, %3
%41 = load i32, i32* %8
ret i32 %41
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [4 x i8] c"%s\0A\00"
define i32 @path_search(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = icmp eq i8* %2, null
br i1 %5, label %20, label %6
6: ; preds = %3
%7 = load i8, i8* %2
%8 = icmp eq i8 %7, 0
br i1 %8, label %20, label %9
9: ; preds = %6
%10 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%11 = call i8* @find_command_in_path(i8* %1, i8* %2, i32* %4)
%12 = icmp eq i8* %11, null
br i1 %12, label %18, label %13
13: ; preds = %9
%14 = call i8* @path_clean_up(i8* %11)
%15 = load i32, i32* @stdout
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %14)
%17 = call i32 @free(i8* %11)
br label %18
18: ; preds = %13, %9
%19 = phi i32 [ 1, %13 ], [ 0, %9 ]
br label %20
20: ; preds = %18, %6, %3
%21 = phi i32 [ %19, %18 ], [ 0, %6 ], [ 0, %3 ]
ret i32 %21
}