#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 /*<<< orphan*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ execl(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  pid_t pid;
  int i;
  if (argc != 3) {
    printf("Number of Arguements provided != 3 \n");
    printf("Arguements Required: \n");
    printf("Path \n");
    printf("Command \n");
    exit(-1);
  }
  switch (pid = fork()) {
  case -1:
    printf("Process Creation Error. \n");
    exit(-1);
  case 0:
    printf("Child Starts :\n");
    if (execl(argv[1], argv[2], 0) < 0) {
      perror(argv[2]);
      exit(-1);
    }
    break;
  default:
    wait(NULL);
    printf("Child Terminated. \n");
  }
  printf("\n");
  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)
cmpl   $0x3,-0x8(%rbp)
je     11ba <main+0x5a>
lea    0xe79(%rip),%rdi
call   1030 <printf@plt>
lea    0xe92(%rip),%rdi
call   1030 <printf@plt>
lea    0xe9d(%rip),%rdi
call   1030 <printf@plt>
lea    0xe98(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
xor    %eax,%eax
call   1080 <fork@plt>
mov    %eax,-0x14(%rbp)
mov    %eax,%ecx
mov    %ecx,-0x1c(%rbp)
sub    $0xffffffff,%eax
je     11e7 <main+0x87>
jmp    11d7 <main+0x77>
mov    -0x1c(%rbp),%eax
test   %eax,%eax
je     11fd <main+0x9d>
jmp    1245 <main+0xe5>
lea    0xe5f(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
lea    0xe63(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
xor    %edx,%edx
call   1060 <execl@plt>
cmp    $0x0,%eax
jge    1240 <main+0xe0>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
jmp    125a <main+0xfa>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <wait@plt>
lea    0xe22(%rip),%rdi
call   1030 <printf@plt>
lea    0xe28(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x3,%edi
jne    11cb <main+0x5b>
mov    %rsi,%rbx
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
je     119e <main+0x2e>
cmp    $0xffffffff,%eax
je     11f8 <main+0x88>
xor    %edi,%edi
call   1080 <wait@plt>
lea    0xe91(%rip),%rdi
call   1040 <puts@plt>
jmp    11bd <main+0x4d>
lea    0xe5b(%rip),%rdi
call   1040 <puts@plt>
mov    0x8(%rbx),%rdi
mov    0x10(%rbx),%rsi
xor    %edx,%edx
call   1070 <execl@plt>
test   %eax,%eax
js     120e <main+0x9e>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe69(%rip),%rdi
call   1040 <puts@plt>
lea    0xe81(%rip),%rdi
call   1040 <puts@plt>
lea    0xe8b(%rip),%rdi
call   1040 <puts@plt>
lea    0xe85(%rip),%rdi
jmp    11ff <main+0x8f>
lea    0xe10(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
mov    0x10(%rbx),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [37 x i8] c"Number of Arguements provided != 3 \0A\00"
@.str.1 = [23 x i8] c"Arguements Required: \0A\00"
@.str.2 = [7 x i8] c"Path \0A\00"
@.str.3 = [10 x i8] c"Command \0A\00"
@.str.4 = [26 x i8] c"Process Creation Error. \0A\00"
@.str.5 = [16 x i8] c"Child Starts :\0A\00"
@.str.6 = [20 x i8] c"Child Terminated. \0A\00"
@.str.7 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 3
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%15 = call i32 @exit(i32 -1)
unreachable
16: ; preds = %2
%17 = call i32 (...) @fork()
store i32 %17, i32* %6
switch i32 %17, label %38 [
i32 -1, label %18
i32 0, label %21
]
18: ; preds = %16
%19 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%20 = call i32 @exit(i32 -1)
unreachable
21: ; preds = %16
%22 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i32 @execl(i8* %25, i8* %28, i32 0)
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %37
31: ; preds = %21
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 2
%34 = load i8*, i8** %33
%35 = call i32 @perror(i8* %34)
%36 = call i32 @exit(i32 -1)
unreachable
37: ; preds = %21
br label %41
38: ; preds = %16
%39 = call i32 @wait(i32* null)
%40 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
br label %41
41: ; preds = %38, %37
%42 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@str = [15 x i8] c"Child Starts :\00"
@str.8 = [25 x i8] c"Process Creation Error. \00"
@str.9 = [19 x i8] c"Child Terminated. \00"
@str.10 = [36 x i8] c"Number of Arguements provided != 3 \00"
@str.11 = [22 x i8] c"Arguements Required: \00"
@str.12 = [6 x i8] c"Path \00"
@str.13 = [9 x i8] c"Command \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %10, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.10, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.11, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.12, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.13, i64 0, i64 0))
%9 = tail call i32 @exit(i32 -1)
unreachable
10: ; preds = %2
%11 = tail call i32 (...) @fork()
switch i32 %11, label %27 [
i32 -1, label %12
i32 0, label %15
]
12: ; preds = %10
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.8, i64 0, i64 0))
%14 = tail call i32 @exit(i32 -1)
unreachable
15: ; preds = %10
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = tail call i32 @execl(i8* %18, i8* %20, i32 0)
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %30
23: ; preds = %15
%24 = load i8*, i8** %19
%25 = tail call i32 @perror(i8* %24)
%26 = tail call i32 @exit(i32 -1)
unreachable
27: ; preds = %10
%28 = tail call i32 @wait(i32* null)
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.9, i64 0, i64 0))
br label %30
30: ; preds = %15, %27
%31 = tail call i32 @putchar(i32 10)
ret i32 0
}