#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 /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ SIGTERM;
int WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
int /*<<< orphan*/ execl(char *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ kill(int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int wait(int *);
int main() {
  int status = 0;
  pid_t senderPID, receiverPID;
  senderPID = fork();
  if (senderPID == 0) {
    execl("./Randomizer", 0);
    printf("execl sender failure\n");
    exit(EXIT_FAILURE);
  } else if (senderPID == -1) {
    perror("Can't open Randomizer");
    exit(EXIT_FAILURE);
  }
  receiverPID = fork();
  if (receiverPID == 0) {
    execl("./Selector", 0);
    printf("Can't open Selector \n");
    exit(EXIT_FAILURE);
  } else if (receiverPID == -1) {
    perror("fork receiver failure");
    exit(EXIT_FAILURE);
  }
  if (wait(&status) == -1)
    printf("Error! Wait()\n");
  else {
    if (WIFEXITED(status))
      if (WEXITSTATUS(status) == 3)
        kill(receiverPID, SIGTERM);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    11e2 <main+0x52>
lea    0xe3f(%rip),%rdi
xor    %esi,%esi
call   1090 <execl@plt>
lea    0xe3e(%rip),%rdi
call   1030 <printf@plt>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
cmpl   $0xffffffff,-0xc(%rbp)
jne    1206 <main+0x76>
lea    0xe30(%rip),%rdi
call   1060 <perror@plt>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    120b <main+0x7b>
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    1247 <main+0xb7>
lea    0xe13(%rip),%rdi
xor    %esi,%esi
call   1090 <execl@plt>
lea    0xe10(%rip),%rdi
call   1030 <printf@plt>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
cmpl   $0xffffffff,-0x10(%rbp)
jne    126b <main+0xdb>
lea    0xe02(%rip),%rdi
call   1060 <perror@plt>
mov    0x2d74(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    1270 <main+0xe0>
lea    -0x8(%rbp),%rdi
call   10a0 <wait@plt>
cmp    $0xffffffff,%eax
jne    1293 <main+0x103>
lea    0xde7(%rip),%rdi
call   1030 <printf@plt>
jmp    12d1 <main+0x141>
mov    -0x8(%rbp),%edi
call   1070 <WIFEXITED@plt>
cmp    $0x0,%rax
je     12cc <main+0x13c>
mov    -0x8(%rbp),%edi
call   1050 <WEXITSTATUS@plt>
cmp    $0x3,%eax
jne    12c7 <main+0x137>
mov    -0x10(%rbp),%edi
mov    0x2d28(%rip),%rax
mov    (%rax),%esi
call   1040 <kill@plt>
jmp    12cc <main+0x13c>
jmp    12d1 <main+0x141>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
xor    %eax,%eax
call   10b0 <fork@plt>
cmp    $0xffffffff,%eax
je     11c4 <main+0x34>
test   %eax,%eax
jne    11cd <main+0x3d>
lea    0xe4c(%rip),%rdi
xor    %esi,%esi
call   1090 <execl@plt>
lea    0xea5(%rip),%rdi
jmp    11f4 <main+0x64>
lea    0xe42(%rip),%rdi
jmp    1202 <main+0x72>
xor    %eax,%eax
call   10b0 <fork@plt>
cmp    $0xffffffff,%eax
je     11fb <main+0x6b>
mov    %eax,%ebx
test   %eax,%eax
jne    1215 <main+0x85>
lea    0xe3d(%rip),%rdi
xor    %esi,%esi
call   1090 <execl@plt>
lea    0xe5e(%rip),%rdi
call   1030 <puts@plt>
jmp    1207 <main+0x77>
lea    0xe2c(%rip),%rdi
call   1060 <perror@plt>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
lea    0xc(%rsp),%rdi
call   10a0 <wait@plt>
cmp    $0xffffffff,%eax
jne    1237 <main+0xa7>
lea    0xe19(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    0xc(%rsp),%edi
call   1070 <WIFEXITED@plt>
test   %rax,%rax
je     1263 <main+0xd3>
mov    0xc(%rsp),%edi
call   1050 <WEXITSTATUS@plt>
cmp    $0x3,%eax
jne    1263 <main+0xd3>
mov    0x2d8e(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1040 <kill@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"./Randomizer\00"
@.str.1 = [22 x i8] c"execl sender failure\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [22 x i8] c"Can't open Randomizer\00"
@.str.3 = [11 x i8] c"./Selector\00"
@.str.4 = [22 x i8] c"Can't open Selector \0A\00"
@.str.5 = [22 x i8] c"fork receiver failure\00"
@.str.6 = [15 x i8] c"Error! Wait()\0A\00"
@SIGTERM = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
%5 = call i32 (...) @fork()
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %0
%9 = call i32 @execl(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 0)
%10 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @exit(i32 %11)
unreachable
13: ; preds = %0
%14 = load i32, i32* %3
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %13
br label %21
21: ; preds = %20
%22 = call i32 (...) @fork()
store i32 %22, i32* %4
%23 = load i32, i32* %4
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %21
%26 = call i32 @execl(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 0)
%27 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %21
%31 = load i32, i32* %4
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %37
33: ; preds = %30
%34 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%35 = load i32, i32* @EXIT_FAILURE
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %30
br label %38
38: ; preds = %37
%39 = call i32 @wait(i32* %2)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %43
41: ; preds = %38
%42 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
br label %57
43: ; preds = %38
%44 = load i32, i32* %2
%45 = call i64 @WIFEXITED(i32 %44)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %56
47: ; preds = %43
%48 = load i32, i32* %2
%49 = call i32 @WEXITSTATUS(i32 %48)
%50 = icmp eq i32 %49, 3
br i1 %50, label %51, label %55
51: ; preds = %47
%52 = load i32, i32* %4
%53 = load i32, i32* @SIGTERM
%54 = call i32 @kill(i32 %52, i32 %53)
br label %55
55: ; preds = %51, %47
br label %56
56: ; preds = %55, %43
br label %57
57: ; preds = %56, %41
%58 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [13 x i8] c"./Randomizer\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [22 x i8] c"Can't open Randomizer\00"
@.str.3 = [11 x i8] c"./Selector\00"
@.str.5 = [22 x i8] c"fork receiver failure\00"
@SIGTERM = global i32 0
@str = [14 x i8] c"Error! Wait()\00"
@str.7 = [21 x i8] c"Can't open Selector \00"
@str.8 = [21 x i8] c"execl sender failure\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%3 = tail call i32 (...) @fork()
switch i32 %3, label %13 [
i32 0, label %4
i32 -1, label %9
]
4: ; preds = %0
%5 = tail call i32 @execl(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 0)
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.8, i64 0, i64 0))
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %0
%10 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %0
%14 = tail call i32 (...) @fork()
switch i32 %14, label %24 [
i32 0, label %15
i32 -1, label %20
]
15: ; preds = %13
%16 = tail call i32 @execl(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 0)
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.7, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
%19 = tail call i32 @exit(i32 %18)
unreachable
20: ; preds = %13
%21 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%22 = load i32, i32* @EXIT_FAILURE
%23 = tail call i32 @exit(i32 %22)
unreachable
24: ; preds = %13
%25 = call i32 @wait(i32* %1)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %40
29: ; preds = %24
%30 = load i32, i32* %1
%31 = call i64 @WIFEXITED(i32 %30)
%32 = icmp eq i64 %31, 0
br i1 %32, label %40, label %33
33: ; preds = %29
%34 = load i32, i32* %1
%35 = call i32 @WEXITSTATUS(i32 %34)
%36 = icmp eq i32 %35, 3
br i1 %36, label %37, label %40
37: ; preds = %33
%38 = load i32, i32* @SIGTERM
%39 = call i32 @kill(i32 %14, i32 %38)
br label %40
40: ; preds = %29, %37, %33, %27
%41 = call i32 @exit(i32 0)
unreachable
}