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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
scalar_t__ waitpid(int, int *, int /*<<< orphan*/);
int runCommand(char *program, char *argv_list[]) {
  pid_t pid;
  int ret = 1;
  int status;
  pid = fork();
  if (pid == -1) {
    fprintf(stderr, "can't fork, error occured\n");
    exit(EXIT_FAILURE);
  } else if (pid == 0) {
    execvp(program, argv_list);
    exit(0);
  } else {
    if (waitpid(pid, &status, 0) > 0) {
      if (WIFEXITED(status) && !WEXITSTATUS(status))
        fprintf(stderr, "*info* program execution successful\n");
      else if (WIFEXITED(status) && WEXITSTATUS(status)) {
        if (WEXITSTATUS(status) == 127) {
          fprintf(stderr, "execv failed\n");
        } else
          fprintf(stderr, "program terminated normally,"
                          " but returned a non-zero status\n");
      } else
        fprintf(stderr, "program didn't terminate normally\n");
    } else {
      fprintf(stderr, "waitpid() failed\n");
    }
  }
  return ret;
}


x86 assembly (clang, -O0):
<runCommand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x18(%rbp)
mov    $0x0,%al
call   1090 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11be <runCommand+0x4e>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
lea    0xe55(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
cmpl   $0x0,-0x14(%rbp)
jne    11dc <runCommand+0x6c>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <execvp@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x1c(%rbp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
cmp    $0x0,%rax
jle    12b8 <runCommand+0x148>
mov    -0x1c(%rbp),%edi
call   1070 <WIFEXITED@plt>
cmp    $0x0,%rax
je     1231 <runCommand+0xc1>
mov    -0x1c(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
cmp    $0x0,%eax
jne    1231 <runCommand+0xc1>
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
lea    0xdf4(%rip),%rsi
call   1030 <fprintf@plt>
jmp    12b3 <runCommand+0x143>
mov    -0x1c(%rbp),%edi
call   1070 <WIFEXITED@plt>
cmp    $0x0,%rax
je     1299 <runCommand+0x129>
mov    -0x1c(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
cmp    $0x0,%eax
je     1299 <runCommand+0x129>
mov    -0x1c(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
cmp    $0x7f,%eax
jne    127f <runCommand+0x10f>
mov    0x2d74(%rip),%rax
mov    (%rax),%edi
lea    0xdcb(%rip),%rsi
call   1030 <fprintf@plt>
jmp    1294 <runCommand+0x124>
mov    0x2d5a(%rip),%rax
mov    (%rax),%edi
lea    0xdbf(%rip),%rsi
call   1030 <fprintf@plt>
jmp    12ae <runCommand+0x13e>
mov    0x2d40(%rip),%rax
mov    (%rax),%edi
lea    0xde2(%rip),%rsi
call   1030 <fprintf@plt>
jmp    12b3 <runCommand+0x143>
jmp    12cd <runCommand+0x15d>
mov    0x2d21(%rip),%rax
mov    (%rax),%edi
lea    0xde6(%rip),%rsi
call   1030 <fprintf@plt>
jmp    12d2 <runCommand+0x162>
jmp    12d7 <runCommand+0x167>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<runCommand>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
je     124a <runCommand+0xda>
cmp    $0xffffffff,%eax
je     125c <runCommand+0xec>
lea    0x4(%rsp),%rsi
mov    %eax,%edi
xor    %edx,%edx
call   1050 <waitpid@plt>
test   %rax,%rax
jle    11fb <runCommand+0x8b>
mov    0x4(%rsp),%edi
call   1070 <WIFEXITED@plt>
test   %rax,%rax
je     11c0 <runCommand+0x50>
mov    0x4(%rsp),%edi
call   1040 <WEXITSTATUS@plt>
test   %eax,%eax
je     121f <runCommand+0xaf>
mov    0x4(%rsp),%edi
call   1070 <WIFEXITED@plt>
test   %rax,%rax
je     120d <runCommand+0x9d>
mov    0x4(%rsp),%edi
call   1040 <WEXITSTATUS@plt>
test   %eax,%eax
je     120d <runCommand+0x9d>
mov    0x4(%rsp),%edi
call   1040 <WEXITSTATUS@plt>
mov    0x2df5(%rip),%rcx
mov    (%rcx),%edi
cmp    $0x7f,%eax
jne    1231 <runCommand+0xc1>
lea    0xe47(%rip),%rsi
jmp    1238 <runCommand+0xc8>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
lea    0xea3(%rip),%rsi
jmp    1238 <runCommand+0xc8>
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
lea    0xe6e(%rip),%rsi
jmp    1238 <runCommand+0xc8>
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
lea    0xdec(%rip),%rsi
jmp    1238 <runCommand+0xc8>
lea    0xe16(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <execvp@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    0x2d7d(%rip),%rax
mov    (%rax),%edi
lea    0xd94(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2d60(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [27 x i8] c"can't fork, error occured\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [37 x i8] c"*info* program execution successful\0A\00"
@.str.2 = [14 x i8] c"execv failed\0A\00"
@.str.3 = [61 x i8] c"program terminated normally, but returned a non-zero status\0A\00"
@.str.4 = [35 x i8] c"program didn't terminate normally\0A\00"
@.str.5 = [18 x i8] c"waitpid() failed\0A\00"
define i32 @runCommand(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i8** %1, i8*** %4
store i32 1, i32* %6
%8 = call i32 (...) @fork()
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %2
%17 = load i32, i32* %5
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %16
%20 = load i8*, i8** %3
%21 = load i8**, i8*** %4
%22 = call i32 @execvp(i8* %20, i8** %21)
%23 = call i32 @exit(i32 0)
unreachable
24: ; preds = %16
%25 = load i32, i32* %5
%26 = call i64 @waitpid(i32 %25, i32* %7, i32 0)
%27 = icmp sgt i64 %26, 0
br i1 %27, label %28, label %63
28: ; preds = %24
%29 = load i32, i32* %7
%30 = call i64 @WIFEXITED(i32 %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %39
32: ; preds = %28
%33 = load i32, i32* %7
%34 = call i32 @WEXITSTATUS(i32 %33)
%35 = icmp ne i32 %34, 0
br i1 %35, label %39, label %36
36: ; preds = %32
%37 = load i32, i32* @stderr
%38 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
br label %62
39: ; preds = %32, %28
%40 = load i32, i32* %7
%41 = call i64 @WIFEXITED(i32 %40)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %58
43: ; preds = %39
%44 = load i32, i32* %7
%45 = call i32 @WEXITSTATUS(i32 %44)
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %58
47: ; preds = %43
%48 = load i32, i32* %7
%49 = call i32 @WEXITSTATUS(i32 %48)
%50 = icmp eq i32 %49, 127
br i1 %50, label %51, label %54
51: ; preds = %47
%52 = load i32, i32* @stderr
%53 = call i32 @fprintf(i32 %52, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %57
54: ; preds = %47
%55 = load i32, i32* @stderr
%56 = call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.3, i64 0, i64 0))
br label %57
57: ; preds = %54, %51
br label %61
58: ; preds = %43, %39
%59 = load i32, i32* @stderr
%60 = call i32 @fprintf(i32 %59, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
br label %61
61: ; preds = %58, %57
br label %62
62: ; preds = %61, %36
br label %66
63: ; preds = %24
%64 = load i32, i32* @stderr
%65 = call i32 @fprintf(i32 %64, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
br label %66
66: ; preds = %63, %62
br label %67
67: ; preds = %66
br label %68
68: ; preds = %67
%69 = load i32, i32* %6
ret i32 %69
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"can't fork, error occured\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [37 x i8] c"*info* program execution successful\0A\00"
@.str.2 = [14 x i8] c"execv failed\0A\00"
@.str.3 = [61 x i8] c"program terminated normally, but returned a non-zero status\0A\00"
@.str.4 = [35 x i8] c"program didn't terminate normally\0A\00"
@.str.5 = [18 x i8] c"waitpid() failed\0A\00"
define i32 @runCommand(i8* %0, i8** %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 (...) @fork()
switch i32 %5, label %14 [
i32 -1, label %6
i32 0, label %11
]
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %2
%12 = tail call i32 @execvp(i8* %0, i8** %1)
%13 = tail call i32 @exit(i32 0)
unreachable
14: ; preds = %2
%15 = call i64 @waitpid(i32 %5, i32* %3, i32 0)
%16 = icmp sgt i64 %15, 0
br i1 %16, label %17, label %48
17: ; preds = %14
%18 = load i32, i32* %3
%19 = call i64 @WIFEXITED(i32 %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %28, label %21
21: ; preds = %17
%22 = load i32, i32* %3
%23 = call i32 @WEXITSTATUS(i32 %22)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
br label %51
28: ; preds = %21, %17
%29 = load i32, i32* %3
%30 = call i64 @WIFEXITED(i32 %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %45, label %32
32: ; preds = %28
%33 = load i32, i32* %3
%34 = call i32 @WEXITSTATUS(i32 %33)
%35 = icmp eq i32 %34, 0
br i1 %35, label %45, label %36
36: ; preds = %32
%37 = load i32, i32* %3
%38 = call i32 @WEXITSTATUS(i32 %37)
%39 = icmp eq i32 %38, 127
%40 = load i32, i32* @stderr
br i1 %39, label %41, label %43
41: ; preds = %36
%42 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %51
43: ; preds = %36
%44 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.3, i64 0, i64 0))
br label %51
45: ; preds = %32, %28
%46 = load i32, i32* @stderr
%47 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
br label %51
48: ; preds = %14
%49 = load i32, i32* @stderr
%50 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
br label %51
51: ; preds = %25, %41, %43, %45, %48
ret i32 1
}