#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 */
int /*<<< orphan*/ EXIT_FAILURE;
scalar_t__ WIFEXITED(int);
scalar_t__ WIFSIGNALED(int);
scalar_t__ WIFSTOPPED(int);
int /*<<< orphan*/ WUNTRACED;
int execvp(char *, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ perror(char *);
scalar_t__ waitpid(scalar_t__, int *, int /*<<< orphan*/);
void run_command(char **arguments) {
  pid_t c_pid, wait_pid;
  int status, ret;
  c_pid = fork();
  if (c_pid == 0) {
    ret = execvp(arguments[0], arguments);
    if (ret == -1) {
      perror("run_command failed");
      exit(EXIT_FAILURE);
    }
    return;
  } else if (c_pid < 0) {
    perror("Fork failed.");
    exit(EXIT_FAILURE);
  } else {
    do {
      wait_pid = waitpid(c_pid, &status, WUNTRACED);
      if (wait_pid == -1) {
        perror("Waitpid failed.");
        exit(EXIT_FAILURE);
      }
      if (WIFEXITED(status)) {
        ;
        return;
      } else if (WIFSIGNALED(status)) {
        ;
        return;
      } else if (WIFSTOPPED(status)) {
        ;
        return;
      }
    } while (WIFEXITED(status) || WIFSIGNALED(status));
  }
  return;
}


x86 assembly (clang, -O0):
<run_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11de <run_command+0x5e>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rsi
call   1070 <execvp@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    11d9 <run_command+0x59>
lea    0xe3a(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    12e1 <run_command+0x161>
cmpq   $0x0,-0x10(%rbp)
jge    1203 <run_command+0x83>
lea    0xe23(%rip),%rdi
call   1060 <perror@plt>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    1208 <run_command+0x88>
mov    -0x10(%rbp),%rdi
mov    0x2dcd(%rip),%rax
mov    (%rax),%edx
lea    -0x1c(%rbp),%rsi
call   1050 <waitpid@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0xffffffffffffffff,-0x18(%rbp)
jne    1247 <run_command+0xc7>
lea    0xdec(%rip),%rdi
call   1060 <perror@plt>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x1c(%rbp),%edi
call   1080 <WIFEXITED@plt>
cmp    $0x0,%rax
je     125e <run_command+0xde>
jmp    12e1 <run_command+0x161>
mov    -0x1c(%rbp),%edi
call   1030 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     1275 <run_command+0xf5>
jmp    12e1 <run_command+0x161>
mov    -0x1c(%rbp),%edi
call   1040 <WIFSTOPPED@plt>
cmp    $0x0,%rax
je     128c <run_command+0x10c>
jmp    12e1 <run_command+0x161>
jmp    1291 <run_command+0x111>
jmp    1296 <run_command+0x116>
jmp    129b <run_command+0x11b>
mov    -0x1c(%rbp),%edi
call   1080 <WIFEXITED@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x21(%rbp)
jne    12c7 <run_command+0x147>
mov    -0x1c(%rbp),%edi
call   1030 <WIFSIGNALED@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1208 <run_command+0x88>
jmp    12d7 <run_command+0x157>
jmp    12dc <run_command+0x15c>
jmp    12e1 <run_command+0x161>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_command>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
xor    %eax,%eax
call   10a0 <fork@plt>
test   %rax,%rax
je     122c <run_command+0xac>
js     1260 <run_command+0xe0>
mov    %rax,%rbx
mov    0x2e34(%rip),%r15
mov    (%r15),%edx
lea    0xc(%rsp),%rsi
mov    %rax,%rdi
call   1050 <waitpid@plt>
cmp    $0xffffffffffffffff,%rax
je     1246 <run_command+0xc6>
lea    0xc(%rsp),%r14
jmp    11e4 <run_command+0x64>
nopl   (%rax)
mov    (%r15),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <waitpid@plt>
cmp    $0xffffffffffffffff,%rax
je     1246 <run_command+0xc6>
mov    0xc(%rsp),%edi
call   1080 <WIFEXITED@plt>
test   %rax,%rax
jne    123c <run_command+0xbc>
mov    0xc(%rsp),%edi
call   1030 <WIFSIGNALED@plt>
test   %rax,%rax
jne    123c <run_command+0xbc>
mov    0xc(%rsp),%edi
call   1040 <WIFSTOPPED@plt>
test   %rax,%rax
jne    123c <run_command+0xbc>
mov    0xc(%rsp),%edi
call   1080 <WIFEXITED@plt>
test   %rax,%rax
jne    11d0 <run_command+0x50>
mov    0xc(%rsp),%edi
call   1030 <WIFSIGNALED@plt>
test   %rax,%rax
jne    11d0 <run_command+0x50>
jmp    123c <run_command+0xbc>
mov    (%r14),%rdi
mov    %r14,%rsi
call   1070 <execvp@plt>
cmp    $0xffffffff,%eax
je     1269 <run_command+0xe9>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xdd3(%rip),%rdi
call   1060 <perror@plt>
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    0xdac(%rip),%rdi
jmp    124d <run_command+0xcd>
lea    0xd90(%rip),%rdi
jmp    124d <run_command+0xcd>

LLVM IR (-O0):
@.str = [19 x i8] c"run_command failed\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [13 x i8] c"Fork failed.\00"
@WUNTRACED = global i32 0
@.str.2 = [16 x i8] c"Waitpid failed.\00"
define void @run_command(i8** %0) {
%2 = alloca i8**
%3 = alloca i64
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
store i8** %0, i8*** %2
%7 = call i64 (...) @fork()
store i64 %7, i64* %3
%8 = load i64, i64* %3
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %23
10: ; preds = %1
%11 = load i8**, i8*** %2
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = load i8**, i8*** %2
%15 = call i32 @execvp(i8* %13, i8** %14)
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %22
18: ; preds = %10
%19 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %10
br label %72
23: ; preds = %1
%24 = load i64, i64* %3
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %23
%27 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %23
br label %31
31: ; preds = %67, %30
%32 = load i64, i64* %3
%33 = load i32, i32* @WUNTRACED
%34 = call i64 @waitpid(i64 %32, i32* %5, i32 %33)
store i64 %34, i64* %4
%35 = load i64, i64* %4
%36 = icmp eq i64 %35, -1
br i1 %36, label %37, label %41
37: ; preds = %31
%38 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%39 = load i32, i32* @EXIT_FAILURE
%40 = call i32 @exit(i32 %39)
unreachable
41: ; preds = %31
%42 = load i32, i32* %5
%43 = call i64 @WIFEXITED(i32 %42)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %41
br label %72
46: ; preds = %41
%47 = load i32, i32* %5
%48 = call i64 @WIFSIGNALED(i32 %47)
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %46
br label %72
51: ; preds = %46
%52 = load i32, i32* %5
%53 = call i64 @WIFSTOPPED(i32 %52)
%54 = icmp ne i64 %53, 0
br i1 %54, label %55, label %56
55: ; preds = %51
br label %72
56: ; preds = %51
br label %57
57: ; preds = %56
br label %58
58: ; preds = %57
br label %59
59: ; preds = %58
%60 = load i32, i32* %5
%61 = call i64 @WIFEXITED(i32 %60)
%62 = icmp ne i64 %61, 0
br i1 %62, label %67, label %63
63: ; preds = %59
%64 = load i32, i32* %5
%65 = call i64 @WIFSIGNALED(i32 %64)
%66 = icmp ne i64 %65, 0
br label %67
67: ; preds = %63, %59
%68 = phi i1 [ true, %59 ], [ %66, %63 ]
br i1 %68, label %31, label %69
69: ; preds = %67
br label %70
70: ; preds = %69
br label %71
71: ; preds = %70
br label %72
72: ; preds = %71, %55, %50, %45, %22
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"run_command failed\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [13 x i8] c"Fork failed.\00"
@WUNTRACED = global i32 0
@.str.2 = [16 x i8] c"Waitpid failed.\00"
define void @run_command(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 @execvp(i8* %7, i8** %0)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %52
10: ; preds = %6
%11 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %1
%15 = icmp slt i64 %4, 0
br i1 %15, label %20, label %16
16: ; preds = %14
%17 = load i32, i32* @WUNTRACED
%18 = call i64 @waitpid(i64 %4, i32* %2, i32 %17)
%19 = icmp eq i64 %18, -1
br i1 %19, label %24, label %28
20: ; preds = %14
%21 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%22 = load i32, i32* @EXIT_FAILURE
%23 = tail call i32 @exit(i32 %22)
unreachable
24: ; preds = %48, %16
%25 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %16, %48
%29 = load i32, i32* %2
%30 = call i64 @WIFEXITED(i32 %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %52
32: ; preds = %28
%33 = load i32, i32* %2
%34 = call i64 @WIFSIGNALED(i32 %33)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %52
36: ; preds = %32
%37 = load i32, i32* %2
%38 = call i64 @WIFSTOPPED(i32 %37)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %52
40: ; preds = %36
%41 = load i32, i32* %2
%42 = call i64 @WIFEXITED(i32 %41)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %48
44: ; preds = %40
%45 = load i32, i32* %2
%46 = call i64 @WIFSIGNALED(i32 %45)
%47 = icmp eq i64 %46, 0
br i1 %47, label %52, label %48
48: ; preds = %44, %40
%49 = load i32, i32* @WUNTRACED
%50 = call i64 @waitpid(i64 %4, i32* %2, i32 %49)
%51 = icmp eq i64 %50, -1
br i1 %51, label %24, label %28
52: ; preds = %44, %36, %32, %28, %6
ret void
}