#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*/ cwd;

/* Variables and functions */
int /*<<< orphan*/ execl(char *, char *, void *);
int fork();
int /*<<< orphan*/ getcwd(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ util_shellCmd(char *);
int /*<<< orphan*/ wait(int *);
int apps_opt_uop() {
  char cwd[128] = "";
  char app[128] = "";
  getcwd((char *)&cwd, sizeof(cwd) / sizeof(cwd[0]));
  char cmd[128] = "ls -l | egrep 'wx|-x' | grep -v '^d'";
  util_shellCmd((char *)&cmd);
  printf("Enter the name of an application to run: ");
  scanf(" %[^\n]", (char *)&app);
  int pid = fork();
  if (pid == 0) {
    char path[128] = "";
    strcat((char *)&path, (char *)&cwd);
    strcat((char *)&path, "/");
    strcat((char *)&path, (char *)&app);
    printf("Running %s...", (char *)&path);
    execl((char *)&path, (char *)&path, (void *)NULL);
  } else if (pid == -1) {
    return 1;
  } else {
    int status;
    wait(&status);
  }
  return 0;
}


x86 assembly (clang, -O0):
<apps_opt_uop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1040 <memset@plt>
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1040 <memset@plt>
lea    -0x90(%rbp),%rdi
mov    $0x80,%esi
call   1050 <getcwd@plt>
lea    -0x190(%rbp),%rdi
lea    0xe10(%rip),%rsi
mov    $0x80,%edx
call   1070 <memcpy@plt>
lea    -0x190(%rbp),%rdi
call   1060 <util_shellCmd@plt>
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x110(%rbp),%rsi
lea    0xe88(%rip),%rdi
call   1080 <scanf@plt>
mov    $0x0,%al
call   10c0 <fork@plt>
mov    %eax,-0x194(%rbp)
cmpl   $0x0,-0x194(%rbp)
jne    12be <apps_opt_uop+0x11e>
lea    -0x220(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1040 <memset@plt>
lea    -0x220(%rbp),%rdi
lea    -0x90(%rbp),%rsi
call   1090 <strcat@plt>
lea    -0x220(%rbp),%rdi
lea    0xe3c(%rip),%rsi
call   1090 <strcat@plt>
lea    -0x220(%rbp),%rdi
lea    -0x110(%rbp),%rsi
call   1090 <strcat@plt>
lea    -0x220(%rbp),%rsi
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x220(%rbp),%rdi
lea    -0x220(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   10a0 <execl@plt>
jmp    12e8 <apps_opt_uop+0x148>
cmpl   $0xffffffff,-0x194(%rbp)
jne    12d7 <apps_opt_uop+0x137>
movl   $0x1,-0x4(%rbp)
jmp    12ef <apps_opt_uop+0x14f>
lea    -0x224(%rbp),%rdi
call   10b0 <wait@plt>
jmp    12e8 <apps_opt_uop+0x148>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<apps_opt_uop>:
push   %r14
push   %rbx
sub    $0x208,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x170(%rsp)
movaps %xmm0,0x160(%rsp)
movaps %xmm0,0x150(%rsp)
movaps %xmm0,0x140(%rsp)
movaps %xmm0,0x130(%rsp)
movaps %xmm0,0x120(%rsp)
movaps %xmm0,0x110(%rsp)
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
lea    0x100(%rsp),%rdi
mov    $0x80,%esi
call   1040 <getcwd@plt>
movaps 0xe4a(%rip),%xmm0
movaps %xmm0,0x1f0(%rsp)
movaps 0xe2b(%rip),%xmm0
movaps %xmm0,0x1e0(%rsp)
movaps 0xe0c(%rip),%xmm0
movaps %xmm0,0x1d0(%rsp)
movaps 0xded(%rip),%xmm0
movaps %xmm0,0x1c0(%rsp)
movaps 0xdce(%rip),%xmm0
movaps %xmm0,0x1b0(%rsp)
movaps 0xdaf(%rip),%xmm0
movaps %xmm0,0x1a0(%rsp)
movaps 0xd90(%rip),%xmm0
movaps %xmm0,0x190(%rsp)
movaps 0xd71(%rip),%xmm0
movaps %xmm0,0x180(%rsp)
lea    0x180(%rsp),%rdi
call   1050 <util_shellCmd@plt>
lea    0xdd5(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xdf1(%rip),%rdi
lea    0x80(%rsp),%rsi
call   1060 <scanf@plt>
xor    %eax,%eax
call   10a0 <fork@plt>
cmp    $0xffffffff,%eax
je     135c <apps_opt_uop+0x1dc>
test   %eax,%eax
jne    1363 <apps_opt_uop+0x1e3>
xorps  %xmm0,%xmm0
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    %rsp,%r14
lea    0x100(%rsp),%rsi
mov    %r14,%rdi
call   1070 <strcat@plt>
lea    0xd8f(%rip),%rsi
mov    %r14,%rdi
call   1070 <strcat@plt>
lea    0x80(%rsp),%rsi
mov    %r14,%rdi
call   1070 <strcat@plt>
lea    0xd72(%rip),%rdi
xor    %ebx,%ebx
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1080 <execl@plt>
jmp    136d <apps_opt_uop+0x1ed>
mov    $0x1,%ebx
jmp    136d <apps_opt_uop+0x1ed>
mov    %rsp,%rdi
call   1090 <wait@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.apps_opt_uop.cmd = [128 x i8] c"ls -l | egrep 'wx|-x' | grep -v '^d'\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [42 x i8] c"Enter the name of an application to run: \00"
@.str.1 = [7 x i8] c" %[^\0A]\00"
@.str.2 = [2 x i8] c"/\00"
@.str.3 = [14 x i8] c"Running %s...\00"
define i32 @apps_opt_uop() {
%1 = alloca i32
%2 = alloca [128 x i8]
%3 = alloca [128 x i8]
%4 = alloca [128 x i8]
%5 = alloca i32
%6 = alloca [128 x i8]
%7 = alloca i32
%8 = bitcast [128 x i8]* %2 to i8*
%9 = bitcast [128 x i8]* %3 to i8*
%10 = bitcast [128 x i8]* %2 to i8*
%11 = call i32 @getcwd(i8* %10, i32 128)
%12 = bitcast [128 x i8]* %4 to i8*
%13 = bitcast [128 x i8]* %4 to i8*
%14 = call i32 @util_shellCmd(i8* %13)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%16 = bitcast [128 x i8]* %3 to i8*
%17 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = call i32 (...) @fork()
store i32 %18, i32* %5
%19 = load i32, i32* %5
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %36
21: ; preds = %0
%22 = bitcast [128 x i8]* %6 to i8*
%23 = bitcast [128 x i8]* %6 to i8*
%24 = bitcast [128 x i8]* %2 to i8*
%25 = call i32 @strcat(i8* %23, i8* %24)
%26 = bitcast [128 x i8]* %6 to i8*
%27 = call i32 @strcat(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%28 = bitcast [128 x i8]* %6 to i8*
%29 = bitcast [128 x i8]* %3 to i8*
%30 = call i32 @strcat(i8* %28, i8* %29)
%31 = bitcast [128 x i8]* %6 to i8*
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %31)
%33 = bitcast [128 x i8]* %6 to i8*
%34 = bitcast [128 x i8]* %6 to i8*
%35 = call i32 @execl(i8* %33, i8* %34, i8* null)
br label %43
36: ; preds = %0
%37 = load i32, i32* %5
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %40
39: ; preds = %36
store i32 1, i32* %1
br label %44
40: ; preds = %36
%41 = call i32 @wait(i32* %7)
br label %42
42: ; preds = %40
br label %43
43: ; preds = %42, %21
store i32 0, i32* %1
br label %44
44: ; preds = %43, %39
%45 = load i32, i32* %1
ret i32 %45
}

LLVM IR (-O2):
@__const.apps_opt_uop.cmd = [128 x i8] c"ls -l | egrep 'wx|-x' | grep -v '^d'\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [42 x i8] c"Enter the name of an application to run: \00"
@.str.1 = [7 x i8] c" %[^\0A]\00"
@.str.2 = [2 x i8] c"/\00"
@.str.3 = [14 x i8] c"Running %s...\00"
define i32 @apps_opt_uop() {
%1 = alloca [128 x i8]
%2 = alloca [128 x i8]
%3 = alloca [128 x i8]
%4 = alloca [128 x i8]
%5 = alloca i32
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%9 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%10 = call i32 @getcwd(i8* %9, i32 128)
%11 = call i32 @util_shellCmd(i8* %7)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%14 = call i32 (...) @fork()
switch i32 %14, label %21 [
i32 0, label %15
i32 -1, label %24
]
15: ; preds = %0
%16 = call i32 @strcat(i8* %6, i8* %9)
%17 = call i32 @strcat(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @strcat(i8* %6, i8* %8)
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %6)
%20 = call i32 @execl(i8* %6, i8* %6, i8* null)
br label %24
21: ; preds = %0
%22 = bitcast i32* %5 to i8*
%23 = call i32 @wait(i32* %5)
br label %24
24: ; preds = %15, %21, %0
%25 = phi i32 [ 1, %0 ], [ 0, %21 ], [ 0, %15 ]
ret i32 %25
}