#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*/ WIFEXITED(int);
int /*<<< orphan*/ WIFSIGNALED(int);
int /*<<< orphan*/ WUNTRACED;
int errno;
int execvp(char *, char **);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
scalar_t__ waitpid(scalar_t__, int *, int /*<<< orphan*/);
int launch_process(char **args) {
  pid_t pid;
  pid_t wpid;
  int status;
  pid = fork();
  if (pid == 0) {
    if (execvp(args[0], args) == -1) {
      fprintf(stderr, "Error forking, errno = %d\n", errno);
    }
    exit(-1);
  } else if (pid < 0) {
    fprintf(stderr, "Error forking, errno = %d\n", errno);
    return 1;
  } else {
    do {
      wpid = waitpid(pid, &status, WUNTRACED);
    } while (!WIFEXITED(status) && !WIFSIGNALED(status));
  }
  return 1;
}


x86 assembly (clang, -O0):
<launch_process>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1090 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d3 <launch_process+0x63>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <execvp@plt>
cmp    $0xffffffff,%eax
jne    11c9 <launch_process+0x59>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
mov    0x2e15(%rip),%rax
mov    (%rax),%edx
lea    0xe3c(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
cmpq   $0x0,-0x18(%rbp)
jge    1208 <launch_process+0x98>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
mov    0x2de2(%rip),%rax
mov    (%rax),%edx
lea    0xe09(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    126e <launch_process+0xfe>
jmp    120d <launch_process+0x9d>
mov    -0x18(%rbp),%rdi
mov    0x2dc8(%rip),%rax
mov    (%rax),%edx
lea    -0x24(%rbp),%rsi
call   1050 <waitpid@plt>
mov    %rax,-0x20(%rbp)
mov    -0x24(%rbp),%edi
call   1070 <WIFEXITED@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x25(%rbp)
jne    1252 <launch_process+0xe2>
mov    -0x24(%rbp),%edi
call   1030 <WIFSIGNALED@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    120d <launch_process+0x9d>
jmp    1262 <launch_process+0xf2>
jmp    1267 <launch_process+0xf7>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<launch_process>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
je     11f7 <launch_process+0x87>
js     11ca <launch_process+0x5a>
mov    %rax,%rbx
mov    0x2e4c(%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   1070 <WIFEXITED@plt>
test   %eax,%eax
jne    11e8 <launch_process+0x78>
mov    0xc(%rsp),%edi
call   1030 <WIFSIGNALED@plt>
test   %eax,%eax
je     11a0 <launch_process+0x30>
jmp    11e8 <launch_process+0x78>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
mov    0x2df6(%rip),%rax
mov    (%rax),%edx
lea    0xe1d(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    (%r14),%rdi
mov    %r14,%rsi
call   1060 <execvp@plt>
cmp    $0xffffffff,%eax
jne    1225 <launch_process+0xb5>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
mov    0x2db9(%rip),%rax
mov    (%rax),%edx
lea    0xde0(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

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

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