#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__ WEXITSTATUS(int);
int /*<<< orphan*/ execv(char *, char *const *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ waitpid(int, int *, int /*<<< orphan*/);
void exec_script(const char *name, const char *arg) {
  int pid, status;
  char path[255] = "";
  char *const args[] = {path, (char *)arg, NULL};
  strcat(path, "scripts/");
  strcat(path, name);
  pid = fork();
  if (pid == 0) {
    printf("  + Executing %s\n", path);
    exit(execv(path, args));
  } else {
    waitpid(pid, &status, 0);
    if (WEXITSTATUS(status) == 0)
      puts("+ Script execution is OK");
    else
      puts("+ Script execution has a error");
  }
}


x86 assembly (clang, -O0):
<exec_script>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0xff,%edx
call   1050 <memset@plt>
lea    -0x120(%rbp),%rax
mov    %rax,-0x140(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x138(%rbp)
movq   $0x0,-0x130(%rbp)
lea    -0x120(%rbp),%rdi
lea    0xe18(%rip),%rsi
call   1080 <strcat@plt>
lea    -0x120(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1080 <strcat@plt>
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    123e <exec_script+0xae>
lea    -0x120(%rbp),%rsi
lea    0xdea(%rip),%rdi
call   1040 <printf@plt>
lea    -0x120(%rbp),%rdi
lea    -0x140(%rbp),%rsi
call   10a0 <execv@plt>
mov    %eax,%edi
call   1090 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1070 <waitpid@plt>
mov    -0x18(%rbp),%edi
call   1060 <WEXITSTATUS@plt>
cmp    $0x0,%rax
jne    126f <exec_script+0xdf>
lea    0xdb6(%rip),%rdi
call   1030 <puts@plt>
jmp    127b <exec_script+0xeb>
lea    0xdbe(%rip),%rdi
call   1030 <puts@plt>
jmp    1280 <exec_script+0xf0>
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exec_script>:
push   %r14
push   %rbx
sub    $0x138,%rsp
mov    %rdi,%r14
xorps  %xmm0,%xmm0
movups %xmm0,0x11f(%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)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
lea    0x30(%rsp),%rbx
mov    %rbx,0x10(%rsp)
mov    %rsi,0x18(%rsp)
movq   $0x0,0x20(%rsp)
lea    0xde0(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <strcat@plt>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %eax,%eax
je     127a <exec_script+0xfa>
lea    0xc(%rsp),%rsi
mov    %eax,%edi
xor    %edx,%edx
call   1060 <waitpid@plt>
mov    0xc(%rsp),%edi
call   1050 <WEXITSTATUS@plt>
test   %rax,%rax
lea    0xdbc(%rip),%rax
lea    0xdce(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
add    $0x138,%rsp
pop    %rbx
pop    %r14
ret
lea    0xd88(%rip),%rdi
lea    0x30(%rsp),%rbx
mov    %rbx,%rsi
call   1040 <printf@plt>
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   1090 <execv@plt>
mov    %eax,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"scripts/\00"
@.str.1 = [18 x i8] c" + Executing %s\0A\00"
@.str.2 = [25 x i8] c"+ Script execution is OK\00"
@.str.3 = [31 x i8] c"+ Script execution has a error\00"
define void @exec_script(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [255 x i8]
%8 = alloca [3 x i8*]
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = bitcast [255 x i8]* %7 to i8*
%10 = getelementptr inbounds [3 x i8*], [3 x i8*]* %8, i64 0, i64 0
%11 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
store i8* %11, i8** %10
%12 = getelementptr inbounds i8*, i8** %10, i64 1
%13 = load i8*, i8** %4
store i8* %13, i8** %12
%14 = getelementptr inbounds i8*, i8** %12, i64 1
store i8* null, i8** %14
%15 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%16 = call i32 @strcat(i8* %15, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%17 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%18 = load i8*, i8** %3
%19 = call i32 @strcat(i8* %17, i8* %18)
%20 = call i32 (...) @fork()
store i32 %20, i32* %5
%21 = load i32, i32* %5
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %30
23: ; preds = %2
%24 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%25 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %24)
%26 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%27 = getelementptr inbounds [3 x i8*], [3 x i8*]* %8, i64 0, i64 0
%28 = call i32 @execv(i8* %26, i8** %27)
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %2
%31 = load i32, i32* %5
%32 = call i32 @waitpid(i32 %31, i32* %6, i32 0)
%33 = load i32, i32* %6
%34 = call i64 @WEXITSTATUS(i32 %33)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %30
%37 = call i32 @puts(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %40
38: ; preds = %30
%39 = call i32 @puts(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
br label %40
40: ; preds = %38, %36
br label %41
41: ; preds = %40
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"scripts/\00"
@.str.1 = [18 x i8] c" + Executing %s\0A\00"
@.str.2 = [25 x i8] c"+ Script execution is OK\00"
@.str.3 = [31 x i8] c"+ Script execution has a error\00"
define void @exec_script(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca [255 x i8]
%5 = alloca [3 x i8*]
%6 = bitcast i32* %3 to i8*
%7 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%8 = bitcast [3 x i8*]* %5 to i8*
%9 = getelementptr inbounds [3 x i8*], [3 x i8*]* %5, i64 0, i64 0
store i8* %7, i8** %9
%10 = getelementptr inbounds [3 x i8*], [3 x i8*]* %5, i64 0, i64 1
store i8* %1, i8** %10
%11 = getelementptr inbounds [3 x i8*], [3 x i8*]* %5, i64 0, i64 2
store i8* null, i8** %11
%12 = call i32 @strcat(i8* %7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @strcat(i8* %7, i8* %0)
%14 = call i32 (...) @fork()
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%18 = call i32 @execv(i8* %7, i8** %9)
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %2
%21 = call i32 @waitpid(i32 %14, i32* %3, i32 0)
%22 = load i32, i32* %3
%23 = call i64 @WEXITSTATUS(i32 %22)
%24 = icmp eq i64 %23, 0
%25 = select i1 %24, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0)
%26 = call i32 @puts(i8* dereferenceable(1) %25)
ret void
}