#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 int pid_t;

/* Variables and functions */
int execv(char *, char **);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ printHandler(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ wait(int *);
int main(int argc, char *argv[]) {
  int childStatus;
  pid_t forkVal = fork();
  if (forkVal == -1) {
    printHandler(0);
    return 1;
  } else if (forkVal == 0) {
    if (argc <= 1)
      fprintf(stderr, "\nUsage: Provide %s a task\n", argv[argc]);
    else if (argc >= 2) {
      int execStatus = execv(argv[1], argv + 1);
      if (execStatus == -1)
        printHandler(1);
    }
    exit(7);
  } else {
    int childID = forkVal;
    fprintf(stderr, "%s \t$$ %d\n", argv[1], childID);
    wait(&childStatus);
    fprintf(stderr, "%s \t$? %d\n", argv[1], childStatus);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    119d <main+0x3d>
xor    %edi,%edi
call   1030 <printHandler@plt>
movl   $0x1,-0x4(%rbp)
jmp    1282 <main+0x122>
cmpl   $0x0,-0x18(%rbp)
jne    1223 <main+0xc3>
cmpl   $0x1,-0x8(%rbp)
jg     11d9 <main+0x79>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe33(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1219 <main+0xb9>
cmpl   $0x2,-0x8(%rbp)
jl     1214 <main+0xb4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
call   1070 <execv@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    120f <main+0xaf>
mov    $0x1,%edi
call   1030 <printHandler@plt>
jmp    1214 <main+0xb4>
jmp    1219 <main+0xb9>
mov    $0x7,%edi
call   1050 <exit@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x20(%rbp),%ecx
lea    0xdd7(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
lea    -0x14(%rbp),%rdi
call   1060 <wait@plt>
mov    0x2d85(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x14(%rbp),%ecx
lea    0xdb7(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    127b <main+0x11b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %eax,%eax
call   1080 <fork@plt>
cmp    $0xffffffff,%eax
je     11c2 <main+0x62>
test   %eax,%eax
je     11d9 <main+0x79>
mov    0x2e5c(%rip),%r14
mov    (%r14),%edi
mov    0x8(%rbx),%rdx
lea    0xe89(%rip),%rsi
xor    %ebp,%ebp
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0xc(%rsp),%rdi
call   1060 <wait@plt>
mov    (%r14),%edi
mov    0x8(%rbx),%rdx
mov    0xc(%rsp),%ecx
lea    0xe6d(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    11ce <main+0x6e>
xor    %edi,%edi
call   1030 <printHandler@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
cmp    $0x1,%ebp
jg     1206 <main+0xa6>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
movslq %ebp,%rax
mov    (%rbx,%rax,8),%rdx
lea    0xe0b(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x7,%edi
call   1050 <exit@plt>
mov    0x8(%rbx),%rdi
add    $0x8,%rbx
mov    %rbx,%rsi
call   1070 <execv@plt>
cmp    $0xffffffff,%eax
jne    1225 <main+0xc5>
mov    $0x1,%edi
call   1030 <printHandler@plt>
mov    $0x7,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [27 x i8] c"\0AUsage: Provide %s a task\0A\00"
@.str.1 = [11 x i8] c"%s \09$$ %d\0A\00"
@.str.2 = [11 x i8] c"%s \09$? %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32 (...) @fork()
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @printHandler(i32 0)
store i32 1, i32* %3
br label %64
15: ; preds = %2
%16 = load i32, i32* %7
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %47
18: ; preds = %15
%19 = load i32, i32* %4
%20 = icmp sle i32 %19, 1
br i1 %20, label %21, label %29
21: ; preds = %18
%22 = load i32, i32* @stderr
%23 = load i8**, i8*** %5
%24 = load i32, i32* %4
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8*, i8** %23, i64 %25
%27 = load i8*, i8** %26
%28 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %27)
br label %45
29: ; preds = %18
%30 = load i32, i32* %4
%31 = icmp sge i32 %30, 2
br i1 %31, label %32, label %44
32: ; preds = %29
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = call i32 @execv(i8* %35, i8** %37)
store i32 %38, i32* %8
%39 = load i32, i32* %8
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %43
41: ; preds = %32
%42 = call i32 @printHandler(i32 1)
br label %43
43: ; preds = %41, %32
br label %44
44: ; preds = %43, %29
br label %45
45: ; preds = %44, %21
%46 = call i32 @exit(i32 7)
unreachable
47: ; preds = %15
%48 = load i32, i32* %7
store i32 %48, i32* %9
%49 = load i32, i32* @stderr
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 1
%52 = load i8*, i8** %51
%53 = load i32, i32* %9
%54 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %52, i32 %53)
%55 = call i32 @wait(i32* %6)
%56 = load i32, i32* @stderr
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 1
%59 = load i8*, i8** %58
%60 = load i32, i32* %6
%61 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %59, i32 %60)
br label %62
62: ; preds = %47
br label %63
63: ; preds = %62
store i32 0, i32* %3
br label %64
64: ; preds = %63, %13
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"\0AUsage: Provide %s a task\0A\00"
@.str.1 = [11 x i8] c"%s \09$$ %d\0A\00"
@.str.2 = [11 x i8] c"%s \09$? %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 (...) @fork()
switch i32 %5, label %25 [
i32 -1, label %6
i32 0, label %8
]
6: ; preds = %2
%7 = tail call i32 @printHandler(i32 0)
br label %35
8: ; preds = %2
%9 = icmp slt i32 %0, 2
br i1 %9, label %10, label %16
10: ; preds = %8
%11 = load i32, i32* @stderr
%12 = sext i32 %0 to i64
%13 = getelementptr inbounds i8*, i8** %1, i64 %12
%14 = load i8*, i8** %13
%15 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %14)
br label %23
16: ; preds = %8
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = tail call i32 @execv(i8* %18, i8** %17)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = tail call i32 @printHandler(i32 1)
br label %23
23: ; preds = %16, %21, %10
%24 = tail call i32 @exit(i32 7)
unreachable
25: ; preds = %2
%26 = load i32, i32* @stderr
%27 = getelementptr inbounds i8*, i8** %1, i64 1
%28 = load i8*, i8** %27
%29 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %28, i32 %5)
%30 = call i32 @wait(i32* %3)
%31 = load i32, i32* @stderr
%32 = load i8*, i8** %27
%33 = load i32, i32* %3
%34 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %32, i32 %33)
br label %35
35: ; preds = %25, %6
%36 = phi i32 [ 1, %6 ], [ 0, %25 ]
ret i32 %36
}