#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 time_t;
struct timespec {
  int tv_sec;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
int /*<<< orphan*/ F_OK;
int O_NDELAY;
int O_RDONLY;
int access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int getpid();
int getppid();
int open(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, int);
void Writer() {
  long ms;
  time_t s, olds;
  struct timespec spec;
  long dat, outcount;
  int mode = 0;
  FILE *wp, *rp;
  char data[1024];
  char path[80];
  char fname[120];
  int br, wwr;
  printf("Rev up the RAID array,WRITER is active!\n");
  printf(" Writer: My PID is %d\n", getpid());
  printf(" Writer: My parent's PID is %d\n", getppid());
  wwr = open("/mnt/ramdisk/WriterPipe.pip", O_RDONLY | O_NDELAY);
  while (mode != 3) {
    if (mode == 0) {
      br = read(wwr, data, 1024 * sizeof(char));
    }
    if (mode == 0 && access("/mnt/ramdisk/START", F_OK) != -1) {
      mode = 1;
      printf("Mode 0->1\n");
    }
    if (mode == 1) {
      rp = fopen("/mnt/ramdisk/START", "r");
      fscanf(rp, "%s", path);
      fclose(rp);
      remove("/mnt/ramdisk/START");
      clock_gettime(CLOCK_REALTIME, &spec);
      s = spec.tv_sec;
      olds = s;
      sprintf(fname, "%s/%d.bin", path, s);
      printf("Writing to %s\n", fname);
      wp = fopen(fname, "wb");
      mode = 2;
      outcount = 0;
      printf("Mode 1->2\n");
    }
    if (mode == 2) {
      if (access("/mnt/ramdisk/STOP", F_OK) != -1) {
        fclose(wp);
        remove("/mnt/ramdisk/STOP");
        mode = 0;
        printf("Mode 2->0\n");
      } else {
        clock_gettime(CLOCK_REALTIME, &spec);
        s = spec.tv_sec;
        if (s - olds >= 1) {
          fclose(wp);
          sprintf(fname, "%s/%d.bin", path, s);
          printf("WRITER: Writing to %s, rate = %ld MBytes/sec\n", fname,
                 outcount / 1000000);
          wp = fopen(fname, "wb");
          olds = s;
          outcount = 0;
        }
        br = read(wwr, data, 1024 * sizeof(char));
        if (br > 0) {
          fwrite(data, 1, br, wp);
          outcount += br;
        }
      }
    }
    if (access("/mnt/ramdisk/QUIT", F_OK) != -1) {
      fclose(wp);
      remove("/mnt/ramdisk/START");
      remove("/mnt/ramdisk/STOP");
      remove("/mnt/ramdisk/QUIT");
      mode = 3;
      printf("Mode 3\n");
    }
  }
  printf("WRITER: Closing\n");
  close(wwr);
  return;
}


x86 assembly (clang, -O0):
<Writer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x520,%rsp
movl   $0x0,-0x2c(%rbp)
lea    0xe07(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x0,%al
call   1050 <getpid@plt>
mov    %eax,%esi
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x0,%al
call   10f0 <getppid@plt>
mov    %eax,%esi
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2db3(%rip),%rax
mov    (%rax),%esi
mov    0x2d9a(%rip),%rax
or     (%rax),%esi
lea    0xe19(%rip),%rdi
call   10b0 <open@plt>
mov    %eax,-0x518(%rbp)
cmpl   $0x3,-0x2c(%rbp)
je     1543 <Writer+0x363>
cmpl   $0x0,-0x2c(%rbp)
jne    1283 <Writer+0xa3>
mov    -0x518(%rbp),%edi
lea    -0x440(%rbp),%rsi
mov    $0x400,%edx
call   10a0 <read@plt>
mov    %eax,-0x514(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    12c0 <Writer+0xe0>
mov    0x2d2c(%rip),%rax
mov    (%rax),%esi
lea    0xddf(%rip),%rdi
call   10c0 <access@plt>
cmp    $0xffffffff,%eax
je     12c0 <Writer+0xe0>
movl   $0x1,-0x2c(%rbp)
lea    0xdd6(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
cmpl   $0x1,-0x2c(%rbp)
jne    1391 <Writer+0x1b1>
lea    0xdab(%rip),%rdi
lea    0xdc2(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
lea    -0x490(%rbp),%rdx
lea    0xda9(%rip),%rsi
call   1080 <fscanf@plt>
mov    -0x40(%rbp),%rdi
call   1060 <fclose@plt>
lea    0xd74(%rip),%rdi
call   1030 <remove@plt>
mov    0x2cbc(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1040 <clock_gettime@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
lea    -0x510(%rbp),%rdi
lea    -0x490(%rbp),%rdx
mov    -0xc(%rbp),%ecx
lea    0xd5c(%rip),%rsi
call   10e0 <sprintf@plt>
lea    -0x510(%rbp),%rsi
lea    0xd53(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x510(%rbp),%rdi
lea    0xd4d(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x38(%rbp)
movl   $0x2,-0x2c(%rbp)
movq   $0x0,-0x28(%rbp)
lea    0xd31(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
cmpl   $0x2,-0x2c(%rbp)
jne    14de <Writer+0x2fe>
mov    0x2c1e(%rip),%rax
mov    (%rax),%esi
lea    0xd1b(%rip),%rdi
call   10c0 <access@plt>
cmp    $0xffffffff,%eax
je     13e8 <Writer+0x208>
mov    -0x38(%rbp),%rdi
call   1060 <fclose@plt>
lea    0xcfd(%rip),%rdi
call   1030 <remove@plt>
movl   $0x0,-0x2c(%rbp)
lea    0xcfc(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    14d9 <Writer+0x2f9>
mov    0x2be1(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1040 <clock_gettime@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
sub    -0x10(%rbp),%eax
cmp    $0x1,%eax
jl     1480 <Writer+0x2a0>
mov    -0x38(%rbp),%rdi
call   1060 <fclose@plt>
lea    -0x510(%rbp),%rdi
lea    -0x490(%rbp),%rdx
mov    -0xc(%rbp),%ecx
lea    0xc6f(%rip),%rsi
call   10e0 <sprintf@plt>
lea    -0x510(%rbp),%rsi
mov    -0x28(%rbp),%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
mov    %rax,%rdx
lea    0xc8f(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x510(%rbp),%rdi
lea    0xc4f(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x38(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x518(%rbp),%edi
lea    -0x440(%rbp),%rsi
mov    $0x400,%edx
call   10a0 <read@plt>
mov    %eax,-0x514(%rbp)
cmpl   $0x0,-0x514(%rbp)
jle    14d4 <Writer+0x2f4>
lea    -0x440(%rbp),%rdi
mov    -0x514(%rbp),%edx
mov    -0x38(%rbp),%rcx
mov    $0x1,%esi
call   1100 <fwrite@plt>
movslq -0x514(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    14d9 <Writer+0x2f9>
jmp    14de <Writer+0x2fe>
mov    0x2adb(%rip),%rax
mov    (%rax),%esi
lea    0xc23(%rip),%rdi
call   10c0 <access@plt>
cmp    $0xffffffff,%eax
je     153e <Writer+0x35e>
mov    -0x38(%rbp),%rdi
call   1060 <fclose@plt>
lea    0xb70(%rip),%rdi
call   1030 <remove@plt>
lea    0xbae(%rip),%rdi
call   1030 <remove@plt>
lea    0xbed(%rip),%rdi
call   1030 <remove@plt>
movl   $0x3,-0x2c(%rbp)
lea    0xbec(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1252 <Writer+0x72>
lea    0xbe1(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x518(%rbp),%edi
call   1090 <close@plt>
add    $0x520,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Writer>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x4e8,%rsp
lea    0xee1(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1060 <getpid@plt>
lea    0xdf5(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
xor    %eax,%eax
call   1100 <getppid@plt>
lea    0xdf5(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x2da6(%rip),%rax
mov    0x2d8f(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xdf3(%rip),%rdi
call   10c0 <open@plt>
mov    %eax,0xc(%rsp)
mov    0x2d5c(%rip),%r15
lea    0xe6c(%rip),%rbp
xor    %ebx,%ebx
nopl   (%rax)
cmp    $0x3,%ebx
ja     1486 <Writer+0x296>
mov    %ebx,%eax
lea    0xd7e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0xc(%rsp),%edi
lea    0xe0(%rsp),%rsi
mov    $0x400,%edx
call   10b0 <read@plt>
mov    (%r15),%esi
lea    0xdb8(%rip),%rdi
call   10d0 <access@plt>
cmp    $0xffffffff,%eax
je     13a3 <Writer+0x1b3>
lea    0xe7c(%rip),%rdi
call   1040 <puts@plt>
lea    0xd97(%rip),%rbx
mov    %rbx,%rdi
lea    0xda0(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,%rbp
mov    %rax,%rdi
lea    0xd90(%rip),%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdx
call   1090 <fscanf@plt>
mov    %rbp,%rdi
lea    0xdd8(%rip),%rbp
call   1070 <fclose@plt>
mov    %rbx,%rdi
call   1030 <remove@plt>
mov    0x2cbd(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1050 <clock_gettime@plt>
mov    0x8(%rsp),%r13d
lea    0x60(%rsp),%rbx
mov    %rbx,%rdi
lea    0xd48(%rip),%rsi
mov    %r14,%rdx
mov    %r13d,%ecx
call   10f0 <sprintf@plt>
lea    0xd40(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %rbx,%rdi
lea    0xd3b(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,%r14
lea    0xdca(%rip),%rdi
call   1040 <puts@plt>
xor    %r12d,%r12d
mov    (%r15),%esi
lea    0xd1d(%rip),%rbx
mov    %rbx,%rdi
call   10d0 <access@plt>
cmp    $0xffffffff,%eax
je     13b0 <Writer+0x1c0>
mov    %r14,%rdi
call   1070 <fclose@plt>
mov    %rbx,%rdi
call   1030 <remove@plt>
lea    0xd8a(%rip),%rdi
call   1040 <puts@plt>
xor    %ebx,%ebx
jmp    1486 <Writer+0x296>
nopw   0x0(%rax,%rax,1)
mov    0x2c19(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1050 <clock_gettime@plt>
mov    0x8(%rsp),%r15d
cmp    %r13d,%r15d
jle    1437 <Writer+0x247>
mov    %r14,%rdi
call   1070 <fclose@plt>
lea    0x60(%rsp),%rbx
mov    %rbx,%rdi
lea    0xc97(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %r15d,%ecx
call   10f0 <sprintf@plt>
mov    %r12,%rax
movabs $0x431bde82d7b634db,%rcx
de 1b 43
imul   %rcx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x12,%rdx
add    %rax,%rdx
lea    0xc93(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %rbx,%rdi
lea    0xc6a(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,%r14
xor    %r12d,%r12d
jmp    143a <Writer+0x24a>
mov    %r13d,%r15d
mov    0xc(%rsp),%edi
lea    0xe0(%rsp),%r13
mov    %r13,%rsi
mov    $0x400,%edx
call   10b0 <read@plt>
mov    $0x2,%ebx
test   %eax,%eax
jle    1475 <Writer+0x285>
mov    %eax,%ebp
mov    %r13,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %r14,%rcx
call   1110 <fwrite@plt>
mov    %ebp,%eax
add    %rax,%r12
mov    %r15d,%r13d
mov    0x2b41(%rip),%r15
lea    0xc51(%rip),%rbp
mov    (%r15),%esi
mov    %rbp,%rdi
call   10d0 <access@plt>
cmp    $0xffffffff,%eax
je     1270 <Writer+0x80>
mov    %r14,%rdi
call   1070 <fclose@plt>
lea    0xbba(%rip),%rdi
call   1030 <remove@plt>
lea    0xbe2(%rip),%rdi
call   1030 <remove@plt>
mov    %rbp,%rdi
call   1030 <remove@plt>
lea    0xc58(%rip),%rdi
call   1040 <puts@plt>
mov    $0x3,%ebx
jmp    1270 <Writer+0x80>
lea    0xc32(%rip),%rdi
call   1040 <puts@plt>
mov    0xc(%rsp),%edi
call   10a0 <close@plt>
add    $0x4e8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i32 }
@.str = [41 x i8] c"Rev up the RAID array,WRITER is active!\0A\00"
@.str.1 = [23 x i8] c" Writer: My PID is %d\0A\00"
@.str.2 = [32 x i8] c" Writer: My parent's PID is %d\0A\00"
@.str.3 = [28 x i8] c"/mnt/ramdisk/WriterPipe.pip\00"
@O_RDONLY = global i32 0
@O_NDELAY = global i32 0
@.str.4 = [19 x i8] c"/mnt/ramdisk/START\00"
@F_OK = global i32 0
@.str.5 = [11 x i8] c"Mode 0->1\0A\00"
@.str.6 = [2 x i8] c"r\00"
@.str.7 = [3 x i8] c"%s\00"
@CLOCK_REALTIME = global i32 0
@.str.8 = [10 x i8] c"%s/%d.bin\00"
@.str.9 = [15 x i8] c"Writing to %s\0A\00"
@.str.10 = [3 x i8] c"wb\00"
@.str.11 = [11 x i8] c"Mode 1->2\0A\00"
@.str.12 = [18 x i8] c"/mnt/ramdisk/STOP\00"
@.str.13 = [11 x i8] c"Mode 2->0\0A\00"
@.str.14 = [46 x i8] c"WRITER: Writing to %s, rate = %ld MBytes/sec\0A\00"
@.str.15 = [18 x i8] c"/mnt/ramdisk/QUIT\00"
@.str.16 = [8 x i8] c"Mode 3\0A\00"
@.str.17 = [17 x i8] c"WRITER: Closing\0A\00"
define void @Writer() {
%1 = alloca i64
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.timespec
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca [1024 x i8]
%11 = alloca [80 x i8]
%12 = alloca [120 x i8]
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %7
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%16 = call i32 (...) @getpid()
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = call i32 (...) @getppid()
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = load i32, i32* @O_RDONLY
%21 = load i32, i32* @O_NDELAY
%22 = or i32 %20, %21
%23 = call i32 @open(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %22)
store i32 %23, i32* %14
br label %24
24: ; preds = %131, %0
%25 = load i32, i32* %7
%26 = icmp ne i32 %25, 3
br i1 %26, label %27, label %132
27: ; preds = %24
%28 = load i32, i32* %7
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %27
%31 = load i32, i32* %14
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%33 = call i32 @read(i32 %31, i8* %32, i32 1024)
store i32 %33, i32* %13
br label %34
34: ; preds = %30, %27
%35 = load i32, i32* %7
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %43
37: ; preds = %34
%38 = load i32, i32* @F_OK
%39 = call i32 @access(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %38)
%40 = icmp ne i32 %39, -1
br i1 %40, label %41, label %43
41: ; preds = %37
store i32 1, i32* %7
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
br label %43
43: ; preds = %41, %37, %34
%44 = load i32, i32* %7
%45 = icmp eq i32 %44, 1
br i1 %45, label %46, label %68
46: ; preds = %43
%47 = call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %47, i32** %9
%48 = load i32*, i32** %9
%49 = getelementptr inbounds [80 x i8], [80 x i8]* %11, i64 0, i64 0
%50 = call i32 @fscanf(i32* %48, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %49)
%51 = load i32*, i32** %9
%52 = call i32 @fclose(i32* %51)
%53 = call i32 @remove(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%54 = load i32, i32* @CLOCK_REALTIME
%55 = call i32 @clock_gettime(i32 %54, %struct.timespec* %4)
%56 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
%57 = load i32, i32* %56
store i32 %57, i32* %2
%58 = load i32, i32* %2
store i32 %58, i32* %3
%59 = getelementptr inbounds [120 x i8], [120 x i8]* %12, i64 0, i64 0
%60 = getelementptr inbounds [80 x i8], [80 x i8]* %11, i64 0, i64 0
%61 = load i32, i32* %2
%62 = call i32 @sprintf(i8* %59, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i8* %60, i32 %61)
%63 = getelementptr inbounds [120 x i8], [120 x i8]* %12, i64 0, i64 0
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0), i8* %63)
%65 = getelementptr inbounds [120 x i8], [120 x i8]* %12, i64 0, i64 0
%66 = call i32* @fopen(i8* %65, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0))
store i32* %66, i32** %8
store i32 2, i32* %7
store i64 0, i64* %6
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.11, i64 0, i64 0))
br label %68
68: ; preds = %46, %43
%69 = load i32, i32* %7
%70 = icmp eq i32 %69, 2
br i1 %70, label %71, label %120
71: ; preds = %68
%72 = load i32, i32* @F_OK
%73 = call i32 @access(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.12, i64 0, i64 0), i32 %72)
%74 = icmp ne i32 %73, -1
br i1 %74, label %75, label %80
75: ; preds = %71
%76 = load i32*, i32** %8
%77 = call i32 @fclose(i32* %76)
%78 = call i32 @remove(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.12, i64 0, i64 0))
store i32 0, i32* %7
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.13, i64 0, i64 0))
br label %119
80: ; preds = %71
%81 = load i32, i32* @CLOCK_REALTIME
%82 = call i32 @clock_gettime(i32 %81, %struct.timespec* %4)
%83 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
%84 = load i32, i32* %83
store i32 %84, i32* %2
%85 = load i32, i32* %2
%86 = load i32, i32* %3
%87 = sub nsw i32 %85, %86
%88 = icmp sge i32 %87, 1
br i1 %88, label %89, label %103
89: ; preds = %80
%90 = load i32*, i32** %8
%91 = call i32 @fclose(i32* %90)
%92 = getelementptr inbounds [120 x i8], [120 x i8]* %12, i64 0, i64 0
%93 = getelementptr inbounds [80 x i8], [80 x i8]* %11, i64 0, i64 0
%94 = load i32, i32* %2
%95 = call i32 @sprintf(i8* %92, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i8* %93, i32 %94)
%96 = getelementptr inbounds [120 x i8], [120 x i8]* %12, i64 0, i64 0
%97 = load i64, i64* %6
%98 = sdiv i64 %97, 1000000
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.14, i64 0, i64 0), i8* %96, i64 %98)
%100 = getelementptr inbounds [120 x i8], [120 x i8]* %12, i64 0, i64 0
%101 = call i32* @fopen(i8* %100, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0))
store i32* %101, i32** %8
%102 = load i32, i32* %2
store i32 %102, i32* %3
store i64 0, i64* %6
br label %103
103: ; preds = %89, %80
%104 = load i32, i32* %14
%105 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%106 = call i32 @read(i32 %104, i8* %105, i32 1024)
store i32 %106, i32* %13
%107 = load i32, i32* %13
%108 = icmp sgt i32 %107, 0
br i1 %108, label %109, label %118
109: ; preds = %103
%110 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%111 = load i32, i32* %13
%112 = load i32*, i32** %8
%113 = call i32 @fwrite(i8* %110, i32 1, i32 %111, i32* %112)
%114 = load i32, i32* %13
%115 = sext i32 %114 to i64
%116 = load i64, i64* %6
%117 = add nsw i64 %116, %115
store i64 %117, i64* %6
br label %118
118: ; preds = %109, %103
br label %119
119: ; preds = %118, %75
br label %120
120: ; preds = %119, %68
%121 = load i32, i32* @F_OK
%122 = call i32 @access(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.15, i64 0, i64 0), i32 %121)
%123 = icmp ne i32 %122, -1
br i1 %123, label %124, label %131
124: ; preds = %120
%125 = load i32*, i32** %8
%126 = call i32 @fclose(i32* %125)
%127 = call i32 @remove(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%128 = call i32 @remove(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.12, i64 0, i64 0))
%129 = call i32 @remove(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.15, i64 0, i64 0))
store i32 3, i32* %7
%130 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.16, i64 0, i64 0))
br label %131
131: ; preds = %124, %120
br label %24
132: ; preds = %24
%133 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.17, i64 0, i64 0))
%134 = load i32, i32* %14
%135 = call i32 @close(i32 %134)
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
@.str.1 = [23 x i8] c" Writer: My PID is %d\0A\00"
@.str.2 = [32 x i8] c" Writer: My parent's PID is %d\0A\00"
@.str.3 = [28 x i8] c"/mnt/ramdisk/WriterPipe.pip\00"
@O_RDONLY = global i32 0
@O_NDELAY = global i32 0
@.str.4 = [19 x i8] c"/mnt/ramdisk/START\00"
@F_OK = global i32 0
@.str.6 = [2 x i8] c"r\00"
@.str.7 = [3 x i8] c"%s\00"
@CLOCK_REALTIME = global i32 0
@.str.8 = [10 x i8] c"%s/%d.bin\00"
@.str.9 = [15 x i8] c"Writing to %s\0A\00"
@.str.10 = [3 x i8] c"wb\00"
@.str.12 = [18 x i8] c"/mnt/ramdisk/STOP\00"
@.str.14 = [46 x i8] c"WRITER: Writing to %s, rate = %ld MBytes/sec\0A\00"
@.str.15 = [18 x i8] c"/mnt/ramdisk/QUIT\00"
@str = [40 x i8] c"Rev up the RAID array,WRITER is active!\00"
@str.18 = [16 x i8] c"WRITER: Closing\00"
@str.19 = [7 x i8] c"Mode 3\00"
@str.20 = [10 x i8] c"Mode 2->0\00"
@str.21 = [10 x i8] c"Mode 1->2\00"
@str.22 = [10 x i8] c"Mode 0->1\00"
define void @Writer() {
%1 = alloca %struct.timespec
%2 = alloca [1024 x i8]
%3 = alloca [80 x i8]
%4 = alloca [120 x i8]
%5 = bitcast %struct.timespec* %1 to i8*
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [120 x i8], [120 x i8]* %4, i64 0, i64 0
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
%10 = tail call i32 (...) @getpid()
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = tail call i32 (...) @getppid()
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %12)
%14 = load i32, i32* @O_RDONLY
%15 = load i32, i32* @O_NDELAY
%16 = or i32 %15, %14
%17 = tail call i32 @open(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %16)
%18 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
br label %19
19: ; preds = %89, %0
%20 = phi i64 [ undef, %0 ], [ %76, %89 ]
%21 = phi i32 [ 0, %0 ], [ %90, %89 ]
%22 = phi i32* [ undef, %0 ], [ %78, %89 ]
%23 = phi i32 [ undef, %0 ], [ %79, %89 ]
switch i32 %21, label %75 [
i32 3, label %91
i32 0, label %24
i32 1, label %31
i32 2, label %43
]
24: ; preds = %19
%25 = call i32 @read(i32 %17, i8* %6, i32 1024)
%26 = load i32, i32* @F_OK
%27 = call i32 @access(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %26)
%28 = icmp eq i32 %27, -1
br i1 %28, label %75, label %29
29: ; preds = %24
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.22, i64 0, i64 0))
br label %31
31: ; preds = %19, %29
%32 = call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%33 = call i32 @fscanf(i32* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %7)
%34 = call i32 @fclose(i32* %32)
%35 = call i32 @remove(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%36 = load i32, i32* @CLOCK_REALTIME
%37 = call i32 @clock_gettime(i32 %36, %struct.timespec* %1)
%38 = load i32, i32* %18
%39 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i8* %7, i32 %38)
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0), i8* %8)
%41 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0))
%42 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.21, i64 0, i64 0))
br label %43
43: ; preds = %19, %31
%44 = phi i32 [ %38, %31 ], [ %23, %19 ]
%45 = phi i32* [ %41, %31 ], [ %22, %19 ]
%46 = phi i64 [ 0, %31 ], [ %20, %19 ]
%47 = load i32, i32* @F_OK
%48 = call i32 @access(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.12, i64 0, i64 0), i32 %47)
%49 = icmp eq i32 %48, -1
br i1 %49, label %54, label %50
50: ; preds = %43
%51 = call i32 @fclose(i32* %45)
%52 = call i32 @remove(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.12, i64 0, i64 0))
%53 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.20, i64 0, i64 0))
br label %75
54: ; preds = %43
%55 = load i32, i32* @CLOCK_REALTIME
%56 = call i32 @clock_gettime(i32 %55, %struct.timespec* %1)
%57 = load i32, i32* %18
%58 = icmp sgt i32 %57, %44
br i1 %58, label %59, label %65
59: ; preds = %54
%60 = call i32 @fclose(i32* %45)
%61 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i8* %7, i32 %57)
%62 = sdiv i64 %46, 1000000
%63 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.14, i64 0, i64 0), i8* %8, i64 %62)
%64 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0))
br label %65
65: ; preds = %59, %54
%66 = phi i64 [ 0, %59 ], [ %46, %54 ]
%67 = phi i32* [ %64, %59 ], [ %45, %54 ]
%68 = phi i32 [ %57, %59 ], [ %44, %54 ]
%69 = call i32 @read(i32 %17, i8* %6, i32 1024)
%70 = icmp sgt i32 %69, 0
br i1 %70, label %71, label %75
71: ; preds = %65
%72 = call i32 @fwrite(i8* %6, i32 1, i32 %69, i32* %67)
%73 = zext i32 %69 to i64
%74 = add nsw i64 %66, %73
br label %75
75: ; preds = %19, %24, %50, %71, %65
%76 = phi i64 [ %46, %50 ], [ %74, %71 ], [ %66, %65 ], [ %20, %24 ], [ %20, %19 ]
%77 = phi i32 [ 0, %50 ], [ 2, %71 ], [ 2, %65 ], [ 0, %24 ], [ %21, %19 ]
%78 = phi i32* [ %45, %50 ], [ %67, %71 ], [ %67, %65 ], [ %22, %24 ], [ %22, %19 ]
%79 = phi i32 [ %44, %50 ], [ %68, %71 ], [ %68, %65 ], [ %23, %24 ], [ %23, %19 ]
%80 = load i32, i32* @F_OK
%81 = call i32 @access(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.15, i64 0, i64 0), i32 %80)
%82 = icmp eq i32 %81, -1
br i1 %82, label %89, label %83
83: ; preds = %75
%84 = call i32 @fclose(i32* %78)
%85 = call i32 @remove(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%86 = call i32 @remove(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.12, i64 0, i64 0))
%87 = call i32 @remove(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.15, i64 0, i64 0))
%88 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.19, i64 0, i64 0))
br label %89
89: ; preds = %83, %75
%90 = phi i32 [ 3, %83 ], [ %77, %75 ]
br label %19
91: ; preds = %19
%92 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.18, i64 0, i64 0))
%93 = call i32 @close(i32 %17)
ret void
}