#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 errno;
int /*<<< orphan*/ execl(char *, char *, char *, char *, char *);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
char *strrchr(char *, char);
int main(int argc, char **argv) {
  pid_t pid;
  char *Prog;
  if (argc != 3) {
    fprintf(stderr, "Usage: %s <process> <datafile>\n", argv[0]);
    exit(2);
  }
  Prog = strrchr(argv[1], '/');
  Prog++;
  if ((pid = fork()) < 0) {
    printf("Failed in forking, Errno = %d", errno);
    exit(2);
  } else if (pid == 0) {
    execl(argv[1], Prog, "0", argv[2], (char *)0);
  } else {
    execl(argv[1], Prog, "1", argv[2], (char *)0);
  }
  exit(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     11a6 <main+0x46>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe69(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x2,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jge    11fc <main+0x9c>
mov    0x2df4(%rip),%rax
mov    (%rax),%esi
lea    0xe33(%rip),%rdi
call   1030 <printf@plt>
mov    $0x2,%edi
call   1060 <exit@plt>
cmpq   $0x0,-0x18(%rbp)
jne    1231 <main+0xd1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
lea    0xe1c(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
call   1070 <execl@plt>
jmp    1256 <main+0xf6>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
lea    0xdf4(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
call   1070 <execl@plt>
jmp    125b <main+0xfb>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    11a8 <main+0x48>
mov    0x8(%rbx),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
jns    11ca <main+0x6a>
mov    0x2e48(%rip),%rax
mov    (%rax),%esi
lea    0xe87(%rip),%rdi
call   1030 <printf@plt>
mov    $0x2,%edi
call   1060 <exit@plt>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe45(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x2,%edi
call   1060 <exit@plt>
add    $0x1,%r14
test   %rax,%rax
mov    0x8(%rbx),%rdi
mov    0x10(%rbx),%rcx
lea    0xe5e(%rip),%rax
lea    0xe59(%rip),%rdx
cmove  %rax,%rdx
mov    %r14,%rsi
xor    %r8d,%r8d
call   1070 <execl@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [32 x i8] c"Usage: %s <process> <datafile>\0A\00"
@.str.1 = [30 x i8] c"Failed in forking, Errno = %d\00"
@errno = global i32 0
@.str.2 = [2 x i8] c"0\00"
@.str.3 = [2 x i8] c"1\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i8*
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 %17
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = call i32 @exit(i32 2)
unreachable
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i8* @strrchr(i8* %20, i8 signext 47)
store i8* %21, i8** %7
%22 = load i8*, i8** %7
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %7
%24 = call i64 (...) @fork()
store i64 %24, i64* %6
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %17
%27 = load i32, i32* @errno
%28 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %27)
%29 = call i32 @exit(i32 2)
unreachable
30: ; preds = %17
%31 = load i64, i64* %6
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %42
33: ; preds = %30
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = load i8*, i8** %7
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 2
%40 = load i8*, i8** %39
%41 = call i32 @execl(i8* %36, i8* %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* %40, i8* null)
br label %51
42: ; preds = %30
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 1
%45 = load i8*, i8** %44
%46 = load i8*, i8** %7
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 2
%49 = load i8*, i8** %48
%50 = call i32 @execl(i8* %45, i8* %46, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* %49, i8* null)
br label %51
51: ; preds = %42, %33
br label %52
52: ; preds = %51
%53 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [32 x i8] c"Usage: %s <process> <datafile>\0A\00"
@.str.1 = [30 x i8] c"Failed in forking, Errno = %d\00"
@errno = global i32 0
@.str.2 = [2 x i8] c"0\00"
@.str.3 = [2 x i8] c"1\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = tail call i32 @exit(i32 2)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i8* @strrchr(i8* dereferenceable(1) %11, i8 signext 47)
%13 = tail call i64 (...) @fork()
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %9
%16 = load i32, i32* @errno
%17 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = tail call i32 @exit(i32 2)
unreachable
19: ; preds = %9
%20 = getelementptr inbounds i8, i8* %12, i64 1
%21 = icmp eq i64 %13, 0
%22 = load i8*, i8** %10
%23 = getelementptr inbounds i8*, i8** %1, i64 2
%24 = load i8*, i8** %23
%25 = select i1 %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0)
%26 = tail call i32 @execl(i8* %22, i8* %20, i8* %25, i8* %24, i8* null)
%27 = tail call i32 @exit(i32 0)
unreachable
}