#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*/ Cuber();
int /*<<< orphan*/ Reader();
int /*<<< orphan*/ SIGCHLD;
int /*<<< orphan*/ SIG_IGN;
int S_IFIFO;
int /*<<< orphan*/ Writer();
int /*<<< orphan*/ exit(int);
int fork();
int getpid();
int /*<<< orphan*/ mknod(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ signal(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main(void) {
  pid_t pid;
  int rv;
  char buf[30];
  signal(SIGCHLD, SIG_IGN);
  remove("/mnt/ramdisk/CuberPipe.pip");
  remove("/mnt/ramdisk/WriterPipe.pip");
  mknod("/mnt/ramdisk/CuberPipe.pip", S_IFIFO | 0666, 0);
  mknod("/mnt/ramdisk/WriterPipe.pip", S_IFIFO | 0666, 0);
  remove("/mnt/ramdisk/START");
  remove("/mnt/ramdisk/STOP");
  remove("/mnt/ramdisk/QUIT");
  switch (pid = fork()) {
  case -1:
    perror("fork");
    exit(1);
  case 0:
    Writer();
    exit(0);
  default:
    printf("You have invoked PacketMaster2.  This is the socket reader "
           "process.\n");
    printf("My PID is %d\n", getpid());
    printf("Writer's PID is %d\n", pid);
    if (!fork()) {
      Cuber();
      exit(0);
    }
    Reader();
    wait(NULL);
    printf("Reader: En Taro Adun!\n");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
mov    0x2e08(%rip),%rax
mov    (%rax),%esi
call   1080 <signal@plt>
lea    0xe1a(%rip),%rdi
mov    %rdi,-0x50(%rbp)
call   1030 <remove@plt>
lea    0xe25(%rip),%rdi
mov    %rdi,-0x48(%rbp)
call   1030 <remove@plt>
mov    -0x50(%rbp),%rdi
mov    0x2dc6(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    (%rax),%esi
or     $0x1b6,%esi
xor    %edx,%edx
mov    %edx,-0x38(%rbp)
call   1090 <mknod@plt>
mov    -0x48(%rbp),%rdi
mov    -0x38(%rbp),%edx
mov    -0x40(%rbp),%rax
mov    (%rax),%esi
or     $0x1b6,%esi
call   1090 <mknod@plt>
lea    0xdf8(%rip),%rdi
call   1030 <remove@plt>
lea    0xdff(%rip),%rdi
call   1030 <remove@plt>
lea    0xe05(%rip),%rdi
call   1030 <remove@plt>
mov    -0x38(%rbp),%eax
call   10d0 <fork@plt>
mov    %eax,-0x4(%rbp)
mov    %eax,%ecx
mov    %ecx,-0x34(%rbp)
sub    $0xffffffff,%eax
je     128a <main+0xca>
jmp    127a <main+0xba>
mov    -0x34(%rbp),%eax
test   %eax,%eax
je     12a0 <main+0xe0>
jmp    12ae <main+0xee>
lea    0xddd(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    $0x0,%al
call   10e0 <Writer@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
lea    0xdbe(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x0,%al
call   1050 <getpid@plt>
mov    %eax,%esi
lea    0xdec(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x4(%rbp),%esi
lea    0xde9(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x0,%al
call   10d0 <fork@plt>
cmp    $0x0,%eax
jne    1302 <main+0x142>
mov    $0x0,%al
call   1040 <Cuber@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    $0x0,%al
call   1060 <Reader@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10c0 <wait@plt>
lea    0xdc1(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
mov    0x2df9(%rip),%rax
mov    (%rax),%esi
call   1090 <signal@plt>
lea    0xe0b(%rip),%r15
mov    %r15,%rdi
call   1030 <remove@plt>
lea    0xe17(%rip),%r14
mov    %r14,%rdi
call   1030 <remove@plt>
mov    0x2dbd(%rip),%rbx
mov    $0x1b6,%ebp
mov    (%rbx),%esi
or     %ebp,%esi
mov    %r15,%rdi
xor    %edx,%edx
call   10a0 <mknod@plt>
or     (%rbx),%ebp
mov    %r14,%rdi
mov    %ebp,%esi
xor    %edx,%edx
call   10a0 <mknod@plt>
lea    0xdfc(%rip),%rdi
call   1030 <remove@plt>
lea    0xe03(%rip),%rdi
call   1030 <remove@plt>
lea    0xe09(%rip),%rdi
call   1030 <remove@plt>
xor    %eax,%eax
call   10e0 <fork@plt>
test   %eax,%eax
je     12cf <main+0xff>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     12dd <main+0x10d>
lea    0xe24(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   1060 <getpid@plt>
lea    0xdef(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xded(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1080 <printf@plt>
xor    %eax,%eax
call   10e0 <fork@plt>
test   %eax,%eax
je     12f3 <main+0x123>
xor    %eax,%eax
call   1070 <Reader@plt>
xor    %edi,%edi
call   10d0 <wait@plt>
lea    0xe1c(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
call   10f0 <Writer@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
lea    0xd8a(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
xor    %eax,%eax
call   1040 <Cuber@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@SIGCHLD = global i32 0
@SIG_IGN = global i32 0
@.str = [27 x i8] c"/mnt/ramdisk/CuberPipe.pip\00"
@.str.1 = [28 x i8] c"/mnt/ramdisk/WriterPipe.pip\00"
@S_IFIFO = global i32 0
@.str.2 = [19 x i8] c"/mnt/ramdisk/START\00"
@.str.3 = [18 x i8] c"/mnt/ramdisk/STOP\00"
@.str.4 = [18 x i8] c"/mnt/ramdisk/QUIT\00"
@.str.5 = [5 x i8] c"fork\00"
@.str.6 = [69 x i8] c"You have invoked PacketMaster2. This is the socket reader process.\0A\00"
@.str.7 = [14 x i8] c"My PID is %d\0A\00"
@.str.8 = [20 x i8] c"Writer's PID is %d\0A\00"
@.str.9 = [23 x i8] c"Reader: En Taro Adun!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [30 x i8]
%4 = load i32, i32* @SIGCHLD
%5 = load i32, i32* @SIG_IGN
%6 = call i32 @signal(i32 %4, i32 %5)
%7 = call i32 @remove(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @remove(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%9 = load i32, i32* @S_IFIFO
%10 = or i32 %9, 438
%11 = call i32 @mknod(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %10, i32 0)
%12 = load i32, i32* @S_IFIFO
%13 = or i32 %12, 438
%14 = call i32 @mknod(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %13, i32 0)
%15 = call i32 @remove(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 @remove(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%17 = call i32 @remove(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%18 = call i32 (...) @fork()
store i32 %18, i32* %1
switch i32 %18, label %25 [
i32 -1, label %19
i32 0, label %22
]
19: ; preds = %0
%20 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %0
%23 = call i32 (...) @Writer()
%24 = call i32 @exit(i32 0)
unreachable
25: ; preds = %0
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.6, i64 0, i64 0))
%27 = call i32 (...) @getpid()
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %1
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i32 %29)
%31 = call i32 (...) @fork()
%32 = icmp ne i32 %31, 0
br i1 %32, label %36, label %33
33: ; preds = %25
%34 = call i32 (...) @Cuber()
%35 = call i32 @exit(i32 0)
unreachable
36: ; preds = %25
%37 = call i32 (...) @Reader()
%38 = call i32 @wait(i32* null)
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0))
br label %40
40: ; preds = %36
ret i32 0
}

LLVM IR (-O2):
@SIGCHLD = global i32 0
@SIG_IGN = global i32 0
@.str = [27 x i8] c"/mnt/ramdisk/CuberPipe.pip\00"
@.str.1 = [28 x i8] c"/mnt/ramdisk/WriterPipe.pip\00"
@S_IFIFO = global i32 0
@.str.2 = [19 x i8] c"/mnt/ramdisk/START\00"
@.str.3 = [18 x i8] c"/mnt/ramdisk/STOP\00"
@.str.4 = [18 x i8] c"/mnt/ramdisk/QUIT\00"
@.str.5 = [5 x i8] c"fork\00"
@.str.7 = [14 x i8] c"My PID is %d\0A\00"
@.str.8 = [20 x i8] c"Writer's PID is %d\0A\00"
@str = [68 x i8] c"You have invoked PacketMaster2. This is the socket reader process.\00"
@str.10 = [22 x i8] c"Reader: En Taro Adun!\00"
define i32 @main() {
%1 = load i32, i32* @SIGCHLD
%2 = load i32, i32* @SIG_IGN
%3 = tail call i32 @signal(i32 %1, i32 %2)
%4 = tail call i32 @remove(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @remove(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%6 = load i32, i32* @S_IFIFO
%7 = or i32 %6, 438
%8 = tail call i32 @mknod(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %7, i32 0)
%9 = load i32, i32* @S_IFIFO
%10 = or i32 %9, 438
%11 = tail call i32 @mknod(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %10, i32 0)
%12 = tail call i32 @remove(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%13 = tail call i32 @remove(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%14 = tail call i32 @remove(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%15 = tail call i32 (...) @fork()
switch i32 %15, label %22 [
i32 -1, label %16
i32 0, label %19
]
16: ; preds = %0
%17 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %0
%20 = tail call i32 (...) @Writer()
%21 = tail call i32 @exit(i32 0)
unreachable
22: ; preds = %0
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([68 x i8], [68 x i8]* @str, i64 0, i64 0))
%24 = tail call i32 (...) @getpid()
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i32 %24)
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i32 %15)
%27 = tail call i32 (...) @fork()
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %22
%30 = tail call i32 (...) @Cuber()
%31 = tail call i32 @exit(i32 0)
unreachable
32: ; preds = %22
%33 = tail call i32 (...) @Reader()
%34 = tail call i32 @wait(i32* null)
%35 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.10, i64 0, i64 0))
ret i32 0
}