#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 */
scalar_t__ check_slash(char **, char **);
char *cpy_str(char *, char *);
int /*<<< orphan*/ execve(char *, char **, char **);
int /*<<< orphan*/ free(char *);
int my_access(char *);
int /*<<< orphan*/ my_putstr(char *);
int exec_path(char **env, char **tab, char **path) {
  int i;
  char *str;
  i = 0;
  if ((check_slash(tab, env) == 0))
    return (0);
  if (path == NULL)
    return (1);
  while (path[i] != NULL) {
    str = cpy_str(path[i], tab[0]);
    if ((my_access(str)) == 2) {
      execve(str, tab, env);
      return (0);
    }
    i++;
  }
  my_putstr("42sh : Command not found1\n");
  free(str);
  return (i);
}


x86 assembly (clang, -O0):
<exec_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <check_slash@plt>
cmp    $0x0,%rax
jne    119e <exec_path+0x3e>
movl   $0x0,-0x4(%rbp)
jmp    1241 <exec_path+0xe1>
cmpq   $0x0,-0x20(%rbp)
jne    11b5 <exec_path+0x55>
movl   $0x1,-0x4(%rbp)
jmp    1241 <exec_path+0xe1>
jmp    11ba <exec_path+0x5a>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1226 <exec_path+0xc6>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
call   1040 <cpy_str@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1060 <my_access@plt>
cmp    $0x2,%eax
jne    1218 <exec_path+0xb8>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1070 <execve@plt>
movl   $0x0,-0x4(%rbp)
jmp    1241 <exec_path+0xe1>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11ba <exec_path+0x5a>
lea    0xdd3(%rip),%rdi
call   1080 <my_putstr@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exec_path>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r12
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
mov    %r14,%rsi
call   1050 <check_slash@plt>
test   %rax,%rax
je     11f3 <exec_path+0x93>
test   %r12,%r12
je     11c8 <exec_path+0x68>
mov    (%r12),%rdi
xor    %ebx,%ebx
test   %rdi,%rdi
je     11cf <exec_path+0x6f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r15),%rsi
call   1040 <cpy_str@plt>
mov    %rax,%r13
mov    %rax,%rdi
call   1060 <my_access@plt>
cmp    $0x2,%eax
je     11e5 <exec_path+0x85>
mov    0x8(%r12,%rbx,8),%rdi
add    $0x1,%rbx
test   %rdi,%rdi
jne    11a0 <exec_path+0x40>
jmp    11cf <exec_path+0x6f>
mov    $0x1,%ebx
jmp    11f5 <exec_path+0x95>
lea    0xe2a(%rip),%rdi
call   1080 <my_putstr@plt>
mov    %r13,%rdi
call   1030 <free@plt>
jmp    11f5 <exec_path+0x95>
mov    %r13,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1070 <execve@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [27 x i8] c"42sh : Command not found1\0A\00"
define i32 @exec_path(i8** %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i8*
store i8** %0, i8*** %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
store i32 0, i32* %8
%10 = load i8**, i8*** %6
%11 = load i8**, i8*** %5
%12 = call i64 @check_slash(i8** %10, i8** %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 0, i32* %4
br label %53
15: ; preds = %3
%16 = load i8**, i8*** %7
%17 = icmp eq i8** %16, null
br i1 %17, label %18, label %19
18: ; preds = %15
store i32 1, i32* %4
br label %53
19: ; preds = %15
br label %20
20: ; preds = %45, %19
%21 = load i8**, i8*** %7
%22 = load i32, i32* %8
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8*, i8** %21, i64 %23
%25 = load i8*, i8** %24
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %48
27: ; preds = %20
%28 = load i8**, i8*** %7
%29 = load i32, i32* %8
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8*, i8** %28, i64 %30
%32 = load i8*, i8** %31
%33 = load i8**, i8*** %6
%34 = getelementptr inbounds i8*, i8** %33, i64 0
%35 = load i8*, i8** %34
%36 = call i8* @cpy_str(i8* %32, i8* %35)
store i8* %36, i8** %9
%37 = load i8*, i8** %9
%38 = call i32 @my_access(i8* %37)
%39 = icmp eq i32 %38, 2
br i1 %39, label %40, label %45
40: ; preds = %27
%41 = load i8*, i8** %9
%42 = load i8**, i8*** %6
%43 = load i8**, i8*** %5
%44 = call i32 @execve(i8* %41, i8** %42, i8** %43)
store i32 0, i32* %4
br label %53
45: ; preds = %27
%46 = load i32, i32* %8
%47 = add nsw i32 %46, 1
store i32 %47, i32* %8
br label %20
48: ; preds = %20
%49 = call i32 @my_putstr(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%50 = load i8*, i8** %9
%51 = call i32 @free(i8* %50)
%52 = load i32, i32* %8
store i32 %52, i32* %4
br label %53
53: ; preds = %48, %40, %18, %14
%54 = load i32, i32* %4
ret i32 %54
}

LLVM IR (-O2):
@.str = [27 x i8] c"42sh : Command not found1\0A\00"
define i32 @exec_path(i8** %0, i8** %1, i8** %2) {
%4 = tail call i64 @check_slash(i8** %1, i8** %0)
%5 = icmp eq i64 %4, 0
br i1 %5, label %32, label %6
6: ; preds = %3
%7 = icmp eq i8** %2, null
br i1 %7, label %32, label %8
8: ; preds = %6
%9 = load i8*, i8** %2
%10 = icmp eq i8* %9, null
br i1 %10, label %27, label %11
11: ; preds = %8, %20
%12 = phi i64 [ %21, %20 ], [ 0, %8 ]
%13 = phi i8* [ %23, %20 ], [ %9, %8 ]
%14 = load i8*, i8** %1
%15 = tail call i8* @cpy_str(i8* %13, i8* %14)
%16 = tail call i32 @my_access(i8* %15)
%17 = icmp eq i32 %16, 2
br i1 %17, label %18, label %20
18: ; preds = %11
%19 = tail call i32 @execve(i8* %15, i8** %1, i8** %0)
br label %32
20: ; preds = %11
%21 = add nuw i64 %12, 1
%22 = getelementptr inbounds i8*, i8** %2, i64 %21
%23 = load i8*, i8** %22
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %11
25: ; preds = %20
%26 = trunc i64 %21 to i32
br label %27
27: ; preds = %25, %8
%28 = phi i32 [ 0, %8 ], [ %26, %25 ]
%29 = phi i8* [ undef, %8 ], [ %15, %25 ]
%30 = tail call i32 @my_putstr(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%31 = tail call i32 @free(i8* %29)
br label %32
32: ; preds = %6, %3, %27, %18
%33 = phi i32 [ 0, %18 ], [ %28, %27 ], [ 0, %3 ], [ 1, %6 ]
ret i32 %33
}