#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 scalar_t__ pid_t;

/* Variables and functions */
scalar_t__ WEXITSTATUS(int);
int /*<<< orphan*/ WIFEXITED(int);
int /*<<< orphan*/ _exit(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ execv(char *, char **);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ waitpid(scalar_t__, int *, int /*<<< orphan*/);
int run_exec_process(char **argv) {
  pid_t pid;
  int status;
  pid = fork();
  if (pid == 0) {
    execv(argv[0], argv);
    fprintf(stderr, "E:Can't run (%s)\n", strerror(errno));
    _exit(-1);
  }
  waitpid(pid, &status, 0);
  if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<run_exec_process>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e8 <run_exec_process+0x68>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1090 <execv@plt>
mov    0x2e27(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x20(%rbp),%edi
mov    %rax,%rdx
lea    0xe27(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1030 <_exit@plt>
mov    -0x18(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
xor    %edx,%edx
call   1060 <waitpid@plt>
mov    -0x1c(%rbp),%edi
call   1070 <WIFEXITED@plt>
cmp    $0x0,%eax
je     121a <run_exec_process+0x9a>
mov    -0x1c(%rbp),%edi
call   1050 <WEXITSTATUS@plt>
cmp    $0x0,%rax
je     1226 <run_exec_process+0xa6>
movl   $0x1,-0x4(%rbp)
jmp    122d <run_exec_process+0xad>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_exec_process>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
xor    %eax,%eax
call   10a0 <fork@plt>
test   %rax,%rax
je     11d1 <run_exec_process+0x51>
lea    0xc(%rsp),%rsi
mov    %rax,%rdi
xor    %edx,%edx
call   1060 <waitpid@plt>
mov    0xc(%rsp),%edi
call   1070 <WIFEXITED@plt>
test   %eax,%eax
je     11c6 <run_exec_process+0x46>
mov    0xc(%rsp),%edi
call   1050 <WEXITSTATUS@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
setne  %al
jmp    11cb <run_exec_process+0x4b>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    (%rbx),%rdi
mov    %rbx,%rsi
call   1090 <execv@plt>
mov    0x2dfd(%rip),%rax
mov    (%rax),%ebx
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe06(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [18 x i8] c"E:Can't run (%s)\0A\00"
@errno = global i32 0
define i32 @run_exec_process(i8** %0) {
%2 = alloca i32
%3 = alloca i8**
%4 = alloca i64
%5 = alloca i32
store i8** %0, i8*** %3
%6 = call i64 (...) @fork()
store i64 %6, i64* %4
%7 = load i64, i64* %4
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %20
9: ; preds = %1
%10 = load i8**, i8*** %3
%11 = getelementptr inbounds i8*, i8** %10, i64 0
%12 = load i8*, i8** %11
%13 = load i8**, i8*** %3
%14 = call i32 @execv(i8* %12, i8** %13)
%15 = load i32, i32* @stderr
%16 = load i32, i32* @errno
%17 = call i8* @strerror(i32 %16)
%18 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = call i32 @_exit(i32 -1)
unreachable
20: ; preds = %1
%21 = load i64, i64* %4
%22 = call i32 @waitpid(i64 %21, i32* %5, i32 0)
%23 = load i32, i32* %5
%24 = call i32 @WIFEXITED(i32 %23)
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %20
%27 = load i32, i32* %5
%28 = call i64 @WEXITSTATUS(i32 %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %26, %20
store i32 1, i32* %2
br label %32
31: ; preds = %26
store i32 0, i32* %2
br label %32
32: ; preds = %31, %30
%33 = load i32, i32* %2
ret i32 %33
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [18 x i8] c"E:Can't run (%s)\0A\00"
@errno = global i32 0
define i32 @run_exec_process(i8** %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i64 (...) @fork()
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %14
6: ; preds = %1
%7 = load i8*, i8** %0
%8 = tail call i32 @execv(i8* %7, i8** %0)
%9 = load i32, i32* @stderr
%10 = load i32, i32* @errno
%11 = tail call i8* @strerror(i32 %10)
%12 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = tail call i32 @_exit(i32 -1)
unreachable
14: ; preds = %1
%15 = call i32 @waitpid(i64 %4, i32* %2, i32 0)
%16 = load i32, i32* %2
%17 = call i32 @WIFEXITED(i32 %16)
%18 = icmp eq i32 %17, 0
br i1 %18, label %24, label %19
19: ; preds = %14
%20 = load i32, i32* %2
%21 = call i64 @WEXITSTATUS(i32 %20)
%22 = icmp ne i64 %21, 0
%23 = zext i1 %22 to i32
br label %24
24: ; preds = %19, %14
%25 = phi i32 [ 1, %14 ], [ %23, %19 ]
ret i32 %25
}