#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*/ execve(char *, int /*<<< orphan*/, char **,
                          int /*<<< orphan*/);
char **mystrsplit(char *, char);
int /*<<< orphan*/ path_exists(char *);
int /*<<< orphan*/ putc(char);
int /*<<< orphan*/ puts(char *);
int strlen(char *);
int /*<<< orphan*/ strptrlen(char **);
void setupelf(char *input) {
  char **app_argv;
  app_argv = mystrsplit(input + strlen("setupelf") + 1, ' ');
  if (!path_exists(app_argv[0])) {
    execve(app_argv[0], strptrlen(app_argv), app_argv, 0);
    puts("OK\n");
  } else {
    puts("File not found: ");
    puts(app_argv[0]);
    putc('\n');
  }
}


x86 assembly (clang, -O0):
<setupelf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
lea    0xe75(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x18(%rbp),%rdi
cltq
add    %rax,%rdi
add    $0x1,%rdi
mov    $0x20,%esi
call   1080 <mystrsplit@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <path_exists@plt>
cmp    $0x0,%eax
jne    11f6 <setupelf+0x86>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1090 <strptrlen@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%esi
mov    -0x10(%rbp),%rdx
xor    %ecx,%ecx
call   1060 <execve@plt>
lea    0xe1d(%rip),%rdi
call   1030 <puts@plt>
jmp    1218 <setupelf+0xa8>
lea    0xe10(%rip),%rdi
call   1030 <puts@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <puts@plt>
mov    $0xa,%edi
call   1070 <putc@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setupelf>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xe82(%rip),%rdi
call   1050 <strlen@plt>
cltq
lea    (%rbx,%rax,1),%rdi
add    $0x1,%rdi
mov    $0x20,%esi
call   1080 <mystrsplit@plt>
mov    %rax,%rbx
mov    (%rax),%rdi
call   1040 <path_exists@plt>
test   %eax,%eax
je     11cb <setupelf+0x5b>
lea    0xe60(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx),%rdi
call   1030 <puts@plt>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1070 <putc@plt>
mov    (%rbx),%r14
mov    %rbx,%rdi
call   1090 <strptrlen@plt>
mov    %r14,%rdi
mov    %eax,%esi
mov    %rbx,%rdx
xor    %ecx,%ecx
call   1060 <execve@plt>
lea    0xe1d(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"setupelf\00"
@.str.1 = [4 x i8] c"OK\0A\00"
@.str.2 = [17 x i8] c"File not found: \00"
define void @setupelf(i8* %0) {
%2 = alloca i8*
%3 = alloca i8**
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds i8, i8* %4, i64 %6
%8 = getelementptr inbounds i8, i8* %7, i64 1
%9 = call i8** @mystrsplit(i8* %8, i8 signext 32)
store i8** %9, i8*** %3
%10 = load i8**, i8*** %3
%11 = getelementptr inbounds i8*, i8** %10, i64 0
%12 = load i8*, i8** %11
%13 = call i32 @path_exists(i8* %12)
%14 = icmp ne i32 %13, 0
br i1 %14, label %24, label %15
15: ; preds = %1
%16 = load i8**, i8*** %3
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = load i8**, i8*** %3
%20 = call i32 @strptrlen(i8** %19)
%21 = load i8**, i8*** %3
%22 = call i32 @execve(i8* %18, i32 %20, i8** %21, i32 0)
%23 = call i32 @puts(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %31
24: ; preds = %1
%25 = call i32 @puts(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%26 = load i8**, i8*** %3
%27 = getelementptr inbounds i8*, i8** %26, i64 0
%28 = load i8*, i8** %27
%29 = call i32 @puts(i8* %28)
%30 = call i32 @putc(i8 signext 10)
br label %31
31: ; preds = %24, %15
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"setupelf\00"
@.str.1 = [4 x i8] c"OK\0A\00"
@.str.2 = [17 x i8] c"File not found: \00"
define void @setupelf(i8* %0) {
%2 = tail call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%3 = sext i32 %2 to i64
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = getelementptr inbounds i8, i8* %4, i64 1
%6 = tail call i8** @mystrsplit(i8* %5, i8 signext 32)
%7 = load i8*, i8** %6
%8 = tail call i32 @path_exists(i8* %7)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %1
%11 = load i8*, i8** %6
%12 = tail call i32 @strptrlen(i8** %6)
%13 = tail call i32 @execve(i8* %11, i32 %12, i8** %6, i32 0)
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %20
15: ; preds = %1
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%17 = load i8*, i8** %6
%18 = tail call i32 @puts(i8* dereferenceable(1) %17)
%19 = tail call i32 @putc(i8 signext 10)
br label %20
20: ; preds = %15, %10
ret void
}