#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*/ *execv(char *, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ free(char **);
int /*<<< orphan*/ getline(char **, size_t *, int /*<<< orphan*/);
char **parse_cmdline(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stdin;
scalar_t__ waitpid(scalar_t__, int *, int /*<<< orphan*/);
int main() {
  int status;
  pid_t pid;
  size_t bs = 0;
  while (status != -1) {
    char *cmdline;
    getline(&cmdline, &bs, stdin);
    pid = fork();
    if (pid < 0) {
      status = -1;
      perror("Unsuccessful fork");
    } else if (pid == 0) {
      char **cmd_proccesed = parse_cmdline(cmdline);
      if (execv(cmd_proccesed[0], cmd_proccesed) != NULL) {
        perror("Unsuccessful execute");
        status = -1;
      }
      free(cmd_proccesed);
      exit(0);
    } else {
      if (waitpid(pid, &status, 0) != pid) {
        status = -1;
      }
    }
  }
  return status;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x18(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
je     1269 <main+0xe9>
mov    0x2e40(%rip),%rax
mov    (%rax),%edx
lea    -0x20(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <getline@plt>
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    11e5 <main+0x65>
movl   $0xffffffff,-0x8(%rbp)
lea    0xe25(%rip),%rdi
call   1050 <perror@plt>
jmp    1264 <main+0xe4>
cmpq   $0x0,-0x10(%rbp)
jne    123a <main+0xba>
mov    -0x20(%rbp),%rdi
call   1070 <parse_cmdline@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
mov    -0x28(%rbp),%rsi
call   1090 <execv@plt>
cmp    $0x0,%rax
je     122a <main+0xaa>
lea    0xdf4(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x8(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rdi
lea    -0x8(%rbp),%rsi
xor    %edx,%edx
call   1040 <waitpid@plt>
cmp    -0x10(%rbp),%rax
je     125a <main+0xda>
movl   $0xffffffff,-0x8(%rbp)
jmp    125f <main+0xdf>
jmp    1264 <main+0xe4>
jmp    1197 <main+0x17>
mov    -0x8(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movq   $0x0,0x10(%rsp)
mov    0x2e4a(%rip),%rbp
lea    0x8(%rsp),%r14
lea    0x10(%rsp),%r13
lea    0xe51(%rip),%r15
lea    0x4(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x0(%rbp),%edx
mov    %r14,%rdi
mov    %r13,%rsi
call   1060 <getline@plt>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %rax,%rax
js     11fa <main+0x7a>
je     1225 <main+0xa5>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
xor    %edx,%edx
call   1040 <waitpid@plt>
cmp    %rbx,%rax
jne    1211 <main+0x91>
cmpl   $0xffffffff,0x4(%rsp)
jne    11c0 <main+0x40>
jmp    1211 <main+0x91>
movl   $0xffffffff,0x4(%rsp)
ff
mov    %r15,%rdi
call   1050 <perror@plt>
cmpl   $0xffffffff,0x4(%rsp)
jne    11c0 <main+0x40>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%rsp),%rdi
call   1070 <parse_cmdline@plt>
mov    %rax,%rbx
mov    (%rax),%rdi
mov    %rax,%rsi
call   1090 <execv@plt>
test   %rax,%rax
je     1256 <main+0xd6>
lea    0xdc9(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,0x4(%rsp)
ff
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stdin = global i32 0
@.str = [18 x i8] c"Unsuccessful fork\00"
@.str.1 = [21 x i8] c"Unsuccessful execute\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i8**
store i32 0, i32* %1
store i64 0, i64* %4
br label %7
7: ; preds = %44, %0
%8 = load i32, i32* %2
%9 = icmp ne i32 %8, -1
br i1 %9, label %10, label %45
10: ; preds = %7
%11 = load i32, i32* @stdin
%12 = call i32 @getline(i8** %5, i64* %4, i32 %11)
%13 = call i64 (...) @fork()
store i64 %13, i64* %3
%14 = load i64, i64* %3
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %10
store i32 -1, i32* %2
%17 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %44
18: ; preds = %10
%19 = load i64, i64* %3
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %36
21: ; preds = %18
%22 = load i8*, i8** %5
%23 = call i8** @parse_cmdline(i8* %22)
store i8** %23, i8*** %6
%24 = load i8**, i8*** %6
%25 = getelementptr inbounds i8*, i8** %24, i64 0
%26 = load i8*, i8** %25
%27 = load i8**, i8*** %6
%28 = call i32* @execv(i8* %26, i8** %27)
%29 = icmp ne i32* %28, null
br i1 %29, label %30, label %32
30: ; preds = %21
%31 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %32
32: ; preds = %30, %21
%33 = load i8**, i8*** %6
%34 = call i32 @free(i8** %33)
%35 = call i32 @exit(i32 0)
unreachable
36: ; preds = %18
%37 = load i64, i64* %3
%38 = call i64 @waitpid(i64 %37, i32* %2, i32 0)
%39 = load i64, i64* %3
%40 = icmp ne i64 %38, %39
br i1 %40, label %41, label %42
41: ; preds = %36
store i32 -1, i32* %2
br label %42
42: ; preds = %41, %36
br label %43
43: ; preds = %42
br label %44
44: ; preds = %43, %16
br label %7
45: ; preds = %7
%46 = load i32, i32* %2
ret i32 %46
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [18 x i8] c"Unsuccessful fork\00"
@.str.1 = [21 x i8] c"Unsuccessful execute\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i8*
%4 = bitcast i32* %1 to i8*
%5 = bitcast i64* %2 to i8*
store i64 0, i64* %2
%6 = bitcast i8** %3 to i8*
br label %7
7: ; preds = %0, %31
%8 = load i32, i32* @stdin
%9 = call i32 @getline(i8** %3, i64* %2, i32 %8)
%10 = call i64 (...) @fork()
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %7
store i32 -1, i32* %1
%13 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %31
14: ; preds = %7
%15 = icmp eq i64 %10, 0
br i1 %15, label %16, label %27
16: ; preds = %14
%17 = load i8*, i8** %3
%18 = call i8** @parse_cmdline(i8* %17)
%19 = load i8*, i8** %18
%20 = call i32* @execv(i8* %19, i8** %18)
%21 = icmp eq i32* %20, null
br i1 %21, label %24, label %22
22: ; preds = %16
%23 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %24
24: ; preds = %22, %16
%25 = call i32 @free(i8** %18)
%26 = call i32 @exit(i32 0)
unreachable
27: ; preds = %14
%28 = call i64 @waitpid(i64 %10, i32* %1, i32 0)
%29 = icmp eq i64 %28, %10
br i1 %29, label %31, label %30
30: ; preds = %27
br label %34
31: ; preds = %27, %12
%32 = load i32, i32* %1
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %7
34: ; preds = %31, %30
ret i32 -1
}