#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 EXIT_FAILURE;
int /*<<< orphan*/ WIFEXITED(int);
int /*<<< orphan*/ WIFSIGNALED(int);
int /*<<< orphan*/ WUNTRACED;
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int system(char *);
scalar_t__ waitpid(scalar_t__, int *, int /*<<< orphan*/);
int run_command(char *command) {
  pid_t pid, wait_pid;
  int status;
  pid = fork();
  if (pid < 0) {
    fprintf(stderr, "fork failed\n");
    exit(1);
  } else if (pid == 0) {
    if (system(command) == -1)
      perror("SQshell");
    exit(EXIT_FAILURE);
  } else {
    do {
      wait_pid = waitpid(pid, &status, WUNTRACED);
    } while (!WIFEXITED(status) && !WIFSIGNALED(status));
  }
  return 1;
}


x86 assembly (clang, -O0):
<run_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    11c1 <run_command+0x41>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
lea    0xe4e(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
cmpq   $0x0,-0x10(%rbp)
jne    11f8 <run_command+0x78>
mov    -0x8(%rbp),%rdi
call   1030 <system@plt>
cmp    $0xffffffff,%eax
jne    11ea <run_command+0x6a>
lea    0xe28(%rip),%rdi
call   1070 <perror@plt>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    11fd <run_command+0x7d>
mov    -0x10(%rbp),%rdi
mov    0x2dd8(%rip),%rax
mov    (%rax),%edx
lea    -0x1c(%rbp),%rsi
call   1060 <waitpid@plt>
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%edi
call   1080 <WIFEXITED@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1d(%rbp)
jne    1242 <run_command+0xc2>
mov    -0x1c(%rbp),%edi
call   1040 <WIFSIGNALED@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    11fd <run_command+0x7d>
jmp    1252 <run_command+0xd2>
jmp    1257 <run_command+0xd7>
mov    $0x1,%eax
add    $0x20,%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
js     11e7 <run_command+0x67>
je     1206 <run_command+0x86>
mov    %rax,%rbx
mov    0x2e3c(%rip),%r15
lea    0xc(%rsp),%r14
nopl   0x0(%rax)
mov    (%r15),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <waitpid@plt>
mov    0xc(%rsp),%edi
call   1080 <WIFEXITED@plt>
test   %eax,%eax
jne    11d8 <run_command+0x58>
mov    0xc(%rsp),%edi
call   1040 <WIFSIGNALED@plt>
test   %eax,%eax
je     11b0 <run_command+0x30>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
lea    0xe09(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    %r14,%rdi
call   1030 <system@plt>
cmp    $0xffffffff,%eax
jne    121f <run_command+0x9f>
lea    0xdf3(%rip),%rdi
call   1070 <perror@plt>
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [13 x i8] c"fork failed\0A\00"
@.str.1 = [8 x i8] c"SQshell\00"
@EXIT_FAILURE = global i32 0
@WUNTRACED = global i32 0
define i32 @run_command(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i64
%5 = alloca i32
store i8* %0, i8** %2
%6 = call i64 (...) @fork()
store i64 %6, i64* %3
%7 = load i64, i64* %3
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %1
%14 = load i64, i64* %3
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %25
16: ; preds = %13
%17 = load i8*, i8** %2
%18 = call i32 @system(i8* %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %16
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %13
br label %26
26: ; preds = %39, %25
%27 = load i64, i64* %3
%28 = load i32, i32* @WUNTRACED
%29 = call i64 @waitpid(i64 %27, i32* %5, i32 %28)
store i64 %29, i64* %4
br label %30
30: ; preds = %26
%31 = load i32, i32* %5
%32 = call i32 @WIFEXITED(i32 %31)
%33 = icmp ne i32 %32, 0
br i1 %33, label %39, label %34
34: ; preds = %30
%35 = load i32, i32* %5
%36 = call i32 @WIFSIGNALED(i32 %35)
%37 = icmp ne i32 %36, 0
%38 = xor i1 %37, true
br label %39
39: ; preds = %34, %30
%40 = phi i1 [ false, %30 ], [ %38, %34 ]
br i1 %40, label %26, label %41
41: ; preds = %39
br label %42
42: ; preds = %41
br label %43
43: ; preds = %42
ret i32 1
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [13 x i8] c"fork failed\0A\00"
@.str.1 = [8 x i8] c"SQshell\00"
@EXIT_FAILURE = global i32 0
@WUNTRACED = global i32 0
define i32 @run_command(i8* nocapture %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i64 (...) @fork()
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %1
%11 = icmp eq i64 %4, 0
br i1 %11, label %12, label %20
12: ; preds = %10
%13 = tail call i32 @system(i8* %0)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %15, %12
%18 = load i32, i32* @EXIT_FAILURE
%19 = tail call i32 @exit(i32 %18)
unreachable
20: ; preds = %10, %26
%21 = load i32, i32* @WUNTRACED
%22 = call i64 @waitpid(i64 %4, i32* %2, i32 %21)
%23 = load i32, i32* %2
%24 = call i32 @WIFEXITED(i32 %23)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %20
%27 = load i32, i32* %2
%28 = call i32 @WIFSIGNALED(i32 %27)
%29 = icmp eq i32 %28, 0
br i1 %29, label %20, label %30
30: ; preds = %20, %26
ret i32 1
}