#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 *);
int /*<<< orphan*/ F_SETFL;
int /*<<< orphan*/ O_NONBLOCK;
int /*<<< orphan*/ SIGCHLD;
int /*<<< orphan*/ SIG_IGN;
int /*<<< orphan*/ TestReader(int *, int *);
int /*<<< orphan*/ Writer(int *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int fork();
int getpid();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ pipe(int *);
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;
  int pfdsa[2];
  int pfdsb[2];
  char buf[30];
  signal(SIGCHLD, SIG_IGN);
  pipe(pfdsa);
  pipe(pfdsb);
  fcntl(pfdsa[0], F_SETFL, O_NONBLOCK);
  fcntl(pfdsb[0], F_SETFL, O_NONBLOCK);
  remove("/mnt/ramdisk/START");
  remove("/mnt/ramdisk/STOP");
  remove("/mnt/ramdisk/QUIT");
  switch (pid = fork()) {
  case -1:
    perror("fork");
    exit(1);
  case 0:
    Writer(pfdsa);
    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(pfdsb);
      exit(0);
    }
    TestReader(pfdsa, pfdsb);
    wait(NULL);
    printf("Reader: En Taro Adun!\n");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
mov    0x2df0(%rip),%rax
mov    (%rax),%esi
call   1090 <signal@plt>
lea    -0x10(%rbp),%rdi
call   1080 <pipe@plt>
lea    -0x18(%rbp),%rdi
call   1080 <pipe@plt>
mov    -0x10(%rbp),%edi
mov    0x2dbd(%rip),%rax
mov    %rax,-0x58(%rbp)
mov    (%rax),%esi
mov    0x2dd0(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    (%rax),%edx
call   1050 <fcntl@plt>
mov    -0x58(%rbp),%rcx
mov    -0x50(%rbp),%rax
mov    -0x18(%rbp),%edi
mov    (%rcx),%esi
mov    (%rax),%edx
call   1050 <fcntl@plt>
lea    0xdc2(%rip),%rdi
call   1030 <remove@plt>
lea    0xdc9(%rip),%rdi
call   1030 <remove@plt>
lea    0xdcf(%rip),%rdi
call   1030 <remove@plt>
xor    %eax,%eax
call   10e0 <fork@plt>
mov    %eax,-0x4(%rbp)
mov    %eax,%ecx
mov    %ecx,-0x44(%rbp)
sub    $0xffffffff,%eax
je     1288 <main+0xb8>
jmp    1278 <main+0xa8>
mov    -0x44(%rbp),%eax
test   %eax,%eax
je     129e <main+0xce>
jmp    12ae <main+0xde>
lea    0xda8(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    -0x10(%rbp),%rdi
call   10f0 <Writer@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
lea    0xd87(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x0,%al
call   1060 <getpid@plt>
mov    %eax,%esi
lea    0xdb5(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x4(%rbp),%esi
lea    0xdb2(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x0,%al
call   10e0 <fork@plt>
cmp    $0x0,%eax
jne    1304 <main+0x134>
lea    -0x18(%rbp),%rdi
call   1040 <Cuber@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   10a0 <TestReader@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10d0 <wait@plt>
lea    0xd82(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
mov    0x2de1(%rip),%rax
mov    (%rax),%esi
call   10a0 <signal@plt>
lea    0x10(%rsp),%rdi
call   1090 <pipe@plt>
lea    0x8(%rsp),%rdi
call   1090 <pipe@plt>
mov    0x10(%rsp),%edi
mov    0x2dab(%rip),%r14
mov    (%r14),%esi
mov    0x2dc1(%rip),%rbx
mov    (%rbx),%edx
call   1060 <fcntl@plt>
mov    0x8(%rsp),%edi
mov    (%r14),%esi
mov    (%rbx),%edx
call   1060 <fcntl@plt>
lea    0xdbd(%rip),%rdi
call   1030 <remove@plt>
lea    0xdc4(%rip),%rdi
call   1030 <remove@plt>
lea    0xdca(%rip),%rdi
call   1030 <remove@plt>
xor    %eax,%eax
call   10f0 <fork@plt>
test   %eax,%eax
je     12dc <main+0xfc>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     12ed <main+0x10d>
lea    0xde5(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   1070 <getpid@plt>
lea    0xdb0(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xdae(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1080 <printf@plt>
xor    %eax,%eax
call   10f0 <fork@plt>
test   %eax,%eax
je     1303 <main+0x123>
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   10b0 <TestReader@plt>
xor    %edi,%edi
call   10e0 <wait@plt>
lea    0xdd5(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
lea    0x10(%rsp),%rdi
call   1100 <Writer@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
lea    0xd43(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    0x8(%rsp),%rdi
call   1040 <Cuber@plt>
xor    %edi,%edi
call   10d0 <exit@plt>

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

LLVM IR (-O2):
@SIGCHLD = global i32 0
@SIG_IGN = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str = [19 x i8] c"/mnt/ramdisk/START\00"
@.str.1 = [18 x i8] c"/mnt/ramdisk/STOP\00"
@.str.2 = [18 x i8] c"/mnt/ramdisk/QUIT\00"
@.str.3 = [5 x i8] c"fork\00"
@.str.5 = [14 x i8] c"My PID is %d\0A\00"
@.str.6 = [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.8 = [22 x i8] c"Reader: En Taro Adun!\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca [2 x i32]
%3 = bitcast [2 x i32]* %1 to i8*
%4 = bitcast [2 x i32]* %2 to i8*
%5 = load i32, i32* @SIGCHLD
%6 = load i32, i32* @SIG_IGN
%7 = tail call i32 @signal(i32 %5, i32 %6)
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%9 = call i32 @pipe(i32* %8)
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%11 = call i32 @pipe(i32* %10)
%12 = load i32, i32* %8
%13 = load i32, i32* @F_SETFL
%14 = load i32, i32* @O_NONBLOCK
%15 = call i32 @fcntl(i32 %12, i32 %13, i32 %14)
%16 = load i32, i32* %10
%17 = load i32, i32* @F_SETFL
%18 = load i32, i32* @O_NONBLOCK
%19 = call i32 @fcntl(i32 %16, i32 %17, i32 %18)
%20 = call i32 @remove(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @remove(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 @remove(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%23 = call i32 (...) @fork()
switch i32 %23, label %30 [
i32 -1, label %24
i32 0, label %27
]
24: ; preds = %0
%25 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %0
%28 = call i32 @Writer(i32* %8)
%29 = call i32 @exit(i32 0)
unreachable
30: ; preds = %0
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([68 x i8], [68 x i8]* @str, i64 0, i64 0))
%32 = call i32 (...) @getpid()
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32 %32)
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i32 %23)
%35 = call i32 (...) @fork()
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %30
%38 = call i32 @Cuber(i32* %10)
%39 = call i32 @exit(i32 0)
unreachable
40: ; preds = %30
%41 = call i32 @TestReader(i32* %8, i32* %10)
%42 = call i32 @wait(i32* null)
%43 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.8, i64 0, i64 0))
ret i32 0
}