#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;
int /*<<< orphan*/ WIFEXITED(int);
int /*<<< orphan*/ WIFSIGNALED(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*/);
int pshell_launch(char **args) {
  pid_t pid, wpid;
  int status;
  pid = fork();
  if (pid == 0) {
    if (execvp(args[0], args) == -1) {
      perror("pshell");
    }
    exit(EXIT_FAILURE);
  } else if (pid < 0) {
    perror("pshell");
  } else {
    do {
      wpid = waitpid(pid, &status, WUNTRACED);
    } while (!WIFEXITED(status) && !WIFSIGNALED(status));
  }
  return 1;
}


x86 assembly (clang, -O0):
<pshell_launch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1090 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11c5 <pshell_launch+0x55>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rsi
call   1060 <execvp@plt>
cmp    $0xffffffff,%eax
jne    11b7 <pshell_launch+0x47>
lea    0xe4e(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
cmpq   $0x0,-0x10(%rbp)
jge    11e1 <pshell_launch+0x71>
lea    0xe29(%rip),%rdi
call   1050 <perror@plt>
jmp    123b <pshell_launch+0xcb>
jmp    11e6 <pshell_launch+0x76>
mov    -0x10(%rbp),%rdi
mov    0x2def(%rip),%rax
mov    (%rax),%edx
lea    -0x1c(%rbp),%rsi
call   1040 <waitpid@plt>
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%edi
call   1070 <WIFEXITED@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1d(%rbp)
jne    122b <pshell_launch+0xbb>
mov    -0x1c(%rbp),%edi
call   1030 <WIFSIGNALED@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    11e6 <pshell_launch+0x76>
jmp    123b <pshell_launch+0xcb>
jmp    1240 <pshell_launch+0xd0>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pshell_launch>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
je     11e5 <pshell_launch+0x75>
js     11d7 <pshell_launch+0x67>
mov    %rax,%rbx
mov    0x2e4c(%rip),%r15
lea    0xc(%rsp),%r14
nopl   0x0(%rax)
mov    (%r15),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <waitpid@plt>
mov    0xc(%rsp),%edi
call   1070 <WIFEXITED@plt>
test   %eax,%eax
jne    11c8 <pshell_launch+0x58>
mov    0xc(%rsp),%edi
call   1030 <WIFSIGNALED@plt>
test   %eax,%eax
je     11a0 <pshell_launch+0x30>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe22(%rip),%rdi
call   1050 <perror@plt>
jmp    11c8 <pshell_launch+0x58>
mov    (%r14),%rdi
mov    %r14,%rsi
call   1060 <execvp@plt>
cmp    $0xffffffff,%eax
jne    1201 <pshell_launch+0x91>
lea    0xe04(%rip),%rdi
call   1050 <perror@plt>
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

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

LLVM IR (-O2):
@.str = [7 x i8] c"pshell\00"
@EXIT_FAILURE = global i32 0
@WUNTRACED = global i32 0
define i32 @pshell_launch(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 %15
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 %12
10: ; preds = %6
%11 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %6
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %1
%16 = icmp slt i64 %4, 0
br i1 %16, label %17, label %19
17: ; preds = %15
%18 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %29
19: ; preds = %15, %25
%20 = load i32, i32* @WUNTRACED
%21 = call i64 @waitpid(i64 %4, i32* %2, i32 %20)
%22 = load i32, i32* %2
%23 = call i32 @WIFEXITED(i32 %22)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %19
%26 = load i32, i32* %2
%27 = call i32 @WIFSIGNALED(i32 %26)
%28 = icmp eq i32 %27, 0
br i1 %28, label %19, label %29
29: ; preds = %19, %25, %17
ret i32 1
}