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


x86 assembly (clang, -O0):
<launch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d1 <launch+0x51>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <execvp@plt>
cmp    $0xffffffff,%eax
jne    11c7 <launch+0x47>
lea    0xe3e(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jg     123e <launch+0xbe>
jmp    11e2 <launch+0x62>
mov    -0x18(%rbp),%rdi
mov    0x2df3(%rip),%rax
mov    (%rax),%edx
lea    -0x1c(%rbp),%rsi
call   1050 <waitpid@plt>
mov    -0x1c(%rbp),%edi
call   1080 <WIFEXITED@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1d(%rbp)
jne    1223 <launch+0xa3>
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    11e2 <launch+0x62>
mov    -0x1c(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
mov    %eax,-0x4(%rbp)
jmp    1256 <launch+0xd6>
lea    0xdc4(%rip),%rdi
call   1060 <perror@plt>
jmp    124f <launch+0xcf>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<launch>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
xor    %eax,%eax
call   10a0 <fork@plt>
test   %rax,%rax
je     11fe <launch+0x7e>
js     11eb <launch+0x6b>
mov    %rax,%rbx
mov    0x2e3c(%rip),%r15
lea    0xc(%rsp),%r14
nopl   0x0(%rax)
mov    (%r15),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <waitpid@plt>
mov    0xc(%rsp),%edi
call   1080 <WIFEXITED@plt>
test   %eax,%eax
jne    11d8 <launch+0x58>
mov    0xc(%rsp),%edi
call   1030 <WIFSIGNALED@plt>
test   %eax,%eax
je     11b0 <launch+0x30>
mov    0xc(%rsp),%edi
call   1040 <WEXITSTATUS@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe17(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%eax
jmp    11e1 <launch+0x61>
mov    (%r14),%rdi
mov    %r14,%rsi
call   1070 <execvp@plt>
cmp    $0xffffffff,%eax
jne    121a <launch+0x9a>
lea    0xdeb(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

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

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