#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 **);
int execve(char *, char **, char **);
int /*<<< orphan*/ my_putstr(char *);
char *my_strcomp(char *, char *, int);
int call_exec(char **arg, char **env, char **tab) {
  int i;
  char *way;
  i = 0;
  if ((check_slash(arg, env)) == 0)
    return (0);
  if (tab[i] == NULL) {
    my_putstr("No path detected\n");
    return (-1);
  }
  while (tab[i]) {
    way = my_strcomp(tab[i], arg[0], 1);
    if (execve(way, arg, env) == -1)
      i++;
  }
  return (-1);
}


x86 assembly (clang, -O0):
<call_exec>:
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    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <check_slash@plt>
cmp    $0x0,%rax
jne    117e <call_exec+0x3e>
movl   $0x0,-0x4(%rbp)
jmp    1211 <call_exec+0xd1>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    11a9 <call_exec+0x69>
lea    0xe68(%rip),%rdi
call   1060 <my_putstr@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1211 <call_exec+0xd1>
jmp    11ae <call_exec+0x6e>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     120a <call_exec+0xca>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    $0x1,%edx
call   1040 <my_strcomp@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <execve@plt>
cmp    $0xffffffff,%eax
jne    1205 <call_exec+0xc5>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11ae <call_exec+0x6e>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<call_exec>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
call   1030 <check_slash@plt>
test   %rax,%rax
je     11a1 <call_exec+0x61>
mov    (%r14),%rdi
test   %rdi,%rdi
je     11a5 <call_exec+0x65>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r12),%rsi
mov    $0x1,%edx
call   1040 <my_strcomp@plt>
mov    %rax,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   1050 <execve@plt>
xor    %ecx,%ecx
cmp    $0xffffffff,%eax
sete   %cl
add    %ecx,%ebx
mov    (%r14,%rbx,8),%rdi
test   %rdi,%rdi
jne    1170 <call_exec+0x30>
jmp    11b1 <call_exec+0x71>
xor    %eax,%eax
jmp    11b6 <call_exec+0x76>
lea    0xe54(%rip),%rdi
call   1060 <my_putstr@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [18 x i8] c"No path detected\0A\00"
define i32 @call_exec(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*** %5
%11 = load i8**, i8*** %6
%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 %52
15: ; preds = %3
%16 = load i8**, i8*** %7
%17 = load i32, i32* %8
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8*, i8** %16, i64 %18
%20 = load i8*, i8** %19
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %24
22: ; preds = %15
%23 = call i32 @my_putstr(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %52
24: ; preds = %15
br label %25
25: ; preds = %50, %24
%26 = load i8**, i8*** %7
%27 = load i32, i32* %8
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %26, i64 %28
%30 = load i8*, i8** %29
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %51
32: ; preds = %25
%33 = load i8**, i8*** %7
%34 = load i32, i32* %8
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %33, i64 %35
%37 = load i8*, i8** %36
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 0
%40 = load i8*, i8** %39
%41 = call i8* @my_strcomp(i8* %37, i8* %40, i32 1)
store i8* %41, i8** %9
%42 = load i8*, i8** %9
%43 = load i8**, i8*** %5
%44 = load i8**, i8*** %6
%45 = call i32 @execve(i8* %42, i8** %43, i8** %44)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %50
47: ; preds = %32
%48 = load i32, i32* %8
%49 = add nsw i32 %48, 1
store i32 %49, i32* %8
br label %50
50: ; preds = %47, %32
br label %25
51: ; preds = %25
store i32 -1, i32* %4
br label %52
52: ; preds = %51, %22, %14
%53 = load i32, i32* %4
ret i32 %53
}

LLVM IR (-O2):
@.str = [18 x i8] c"No path detected\0A\00"
define i32 @call_exec(i8** %0, i8** %1, i8** nocapture %2) {
%4 = tail call i64 @check_slash(i8** %0, i8** %1)
%5 = icmp eq i64 %4, 0
br i1 %5, label %24, label %6
6: ; preds = %3
%7 = load i8*, i8** %2
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @my_putstr(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %24
11: ; preds = %6, %11
%12 = phi i8* [ %22, %11 ], [ %7, %6 ]
%13 = phi i32 [ %19, %11 ], [ 0, %6 ]
%14 = load i8*, i8** %0
%15 = tail call i8* @my_strcomp(i8* %12, i8* %14, i32 1)
%16 = tail call i32 @execve(i8* %15, i8** %0, i8** %1)
%17 = icmp eq i32 %16, -1
%18 = zext i1 %17 to i32
%19 = add nuw nsw i32 %13, %18
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds i8*, i8** %2, i64 %20
%22 = load i8*, i8** %21
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %11
24: ; preds = %11, %3, %9
%25 = phi i32 [ -1, %9 ], [ 0, %3 ], [ -1, %11 ]
ret i32 %25
}