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


x86 assembly (clang, -O0):
<qwertysh_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 <qwertysh_launch+0x55>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rsi
call   1060 <execvp@plt>
cmp    $0xffffffff,%eax
jne    11b7 <qwertysh_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 <qwertysh_launch+0x71>
lea    0xe29(%rip),%rdi
call   1050 <perror@plt>
jmp    1237 <qwertysh_launch+0xc7>
jmp    11e6 <qwertysh_launch+0x76>
mov    -0x10(%rbp),%rdi
mov    0x2def(%rip),%rax
mov    (%rax),%edx
lea    -0x14(%rbp),%rsi
call   1040 <waitpid@plt>
mov    -0x14(%rbp),%edi
call   1070 <WIFEXITED@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x15(%rbp)
jne    1227 <qwertysh_launch+0xb7>
mov    -0x14(%rbp),%edi
call   1030 <WIFSIGNALED@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    11e6 <qwertysh_launch+0x76>
jmp    1237 <qwertysh_launch+0xc7>
jmp    123c <qwertysh_launch+0xcc>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<qwertysh_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 <qwertysh_launch+0x75>
js     11d7 <qwertysh_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 <qwertysh_launch+0x58>
mov    0xc(%rsp),%edi
call   1030 <WIFSIGNALED@plt>
test   %eax,%eax
je     11a0 <qwertysh_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 <qwertysh_launch+0x58>
mov    (%r14),%rdi
mov    %r14,%rsi
call   1060 <execvp@plt>
cmp    $0xffffffff,%eax
jne    1201 <qwertysh_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 = [9 x i8] c"qwertysh\00"
@EXIT_FAILURE = global i32 0
@WUNTRACED = global i32 0
define i32 @qwertysh_launch(i8** %0) {
%2 = alloca i8**
%3 = alloca i64
%4 = alloca i32
store i8** %0, i8*** %2
%5 = call i64 (...) @fork()
store i64 %5, i64* %3
%6 = load i64, i64* %3
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %20
8: ; preds = %1
%9 = load i8**, i8*** %2
%10 = getelementptr inbounds i8*, i8** %9, i64 0
%11 = load i8*, i8** %10
%12 = load i8**, i8*** %2
%13 = call i32 @execvp(i8* %11, i8** %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %8
%16 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %8
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %1
%21 = load i64, i64* %3
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %42
25: ; preds = %20
br label %26
26: ; preds = %39, %25
%27 = load i64, i64* %3
%28 = load i32, i32* @WUNTRACED
%29 = call i32 @waitpid(i64 %27, i32* %4, i32 %28)
br label %30
30: ; preds = %26
%31 = load i32, i32* %4
%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* %4
%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, %23
br label %43
43: ; preds = %42
ret i32 1
}

LLVM IR (-O2):
@.str = [9 x i8] c"qwertysh\00"
@EXIT_FAILURE = global i32 0
@WUNTRACED = global i32 0
define i32 @qwertysh_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 ([9 x i8], [9 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 ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %29
19: ; preds = %15, %25
%20 = load i32, i32* @WUNTRACED
%21 = call i32 @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
}