#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 access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
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 /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, int);
void Writer(int pfds[2]) {
  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;
  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());
  while (mode != 3) {
    if (mode == 0) {
      br = read(pfds[0], 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(pfds[0], 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");
    }
  }
  return;
}


x86 assembly (clang, -O0):
<Writer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x530,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x34(%rbp)
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x0,%al
call   1050 <getpid@plt>
mov    %eax,%esi
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x0,%al
call   10d0 <getppid@plt>
mov    %eax,%esi
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
cmpl   $0x3,-0x34(%rbp)
je     1503 <Writer+0x343>
cmpl   $0x0,-0x34(%rbp)
jne    1243 <Writer+0x83>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
lea    -0x450(%rbp),%rsi
mov    $0x400,%edx
call   1090 <read@plt>
mov    %eax,-0x524(%rbp)
cmpl   $0x0,-0x34(%rbp)
jne    1280 <Writer+0xc0>
mov    0x2d7c(%rip),%rax
mov    (%rax),%esi
lea    0xe03(%rip),%rdi
call   10a0 <access@plt>
cmp    $0xffffffff,%eax
je     1280 <Writer+0xc0>
movl   $0x1,-0x34(%rbp)
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
cmpl   $0x1,-0x34(%rbp)
jne    1351 <Writer+0x191>
lea    0xdcf(%rip),%rdi
lea    0xde6(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
lea    -0x4a0(%rbp),%rdx
lea    0xdcd(%rip),%rsi
call   1080 <fscanf@plt>
mov    -0x48(%rbp),%rdi
call   1060 <fclose@plt>
lea    0xd98(%rip),%rdi
call   1030 <remove@plt>
mov    0x2d0c(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1040 <clock_gettime@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
lea    -0x520(%rbp),%rdi
lea    -0x4a0(%rbp),%rdx
mov    -0x14(%rbp),%ecx
lea    0xd80(%rip),%rsi
call   10c0 <sprintf@plt>
lea    -0x520(%rbp),%rsi
lea    0xd77(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x520(%rbp),%rdi
lea    0xd71(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x40(%rbp)
movl   $0x2,-0x34(%rbp)
movq   $0x0,-0x30(%rbp)
lea    0xd55(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
cmpl   $0x2,-0x34(%rbp)
jne    149e <Writer+0x2de>
mov    0x2c6e(%rip),%rax
mov    (%rax),%esi
lea    0xd3f(%rip),%rdi
call   10a0 <access@plt>
cmp    $0xffffffff,%eax
je     13a8 <Writer+0x1e8>
mov    -0x40(%rbp),%rdi
call   1060 <fclose@plt>
lea    0xd21(%rip),%rdi
call   1030 <remove@plt>
movl   $0x0,-0x34(%rbp)
lea    0xd20(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1499 <Writer+0x2d9>
mov    0x2c31(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1040 <clock_gettime@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
sub    -0x18(%rbp),%eax
cmp    $0x1,%eax
jl     1440 <Writer+0x280>
mov    -0x40(%rbp),%rdi
call   1060 <fclose@plt>
lea    -0x520(%rbp),%rdi
lea    -0x4a0(%rbp),%rdx
mov    -0x14(%rbp),%ecx
lea    0xc93(%rip),%rsi
call   10c0 <sprintf@plt>
lea    -0x520(%rbp),%rsi
mov    -0x30(%rbp),%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
mov    %rax,%rdx
lea    0xcb3(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x520(%rbp),%rdi
lea    0xc73(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x40(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
lea    -0x450(%rbp),%rsi
mov    $0x400,%edx
call   1090 <read@plt>
mov    %eax,-0x524(%rbp)
cmpl   $0x0,-0x524(%rbp)
jle    1494 <Writer+0x2d4>
lea    -0x450(%rbp),%rdi
mov    -0x524(%rbp),%edx
mov    -0x40(%rbp),%rcx
mov    $0x1,%esi
call   10e0 <fwrite@plt>
movslq -0x524(%rbp),%rax
add    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    1499 <Writer+0x2d9>
jmp    149e <Writer+0x2de>
mov    0x2b2b(%rip),%rax
mov    (%rax),%esi
lea    0xc47(%rip),%rdi
call   10a0 <access@plt>
cmp    $0xffffffff,%eax
je     14fe <Writer+0x33e>
mov    -0x40(%rbp),%rdi
call   1060 <fclose@plt>
lea    0xb94(%rip),%rdi
call   1030 <remove@plt>
lea    0xbd2(%rip),%rdi
call   1030 <remove@plt>
lea    0xc11(%rip),%rdi
call   1030 <remove@plt>
movl   $0x3,-0x34(%rbp)
lea    0xc10(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1212 <Writer+0x52>
add    $0x530,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Writer>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x4e8,%rsp
mov    %rdi,0x8(%rsp)
lea    0xee0(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1060 <getpid@plt>
lea    0xe10(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
xor    %eax,%eax
call   10e0 <getppid@plt>
lea    0xe10(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x2da9(%rip),%r12
lea    0xe8d(%rip),%r15
xor    %ebx,%ebx
cmp    $0x3,%ebx
ja     1446 <Writer+0x276>
mov    %ebx,%eax
lea    0xdbe(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x8(%rsp),%rax
mov    (%rax),%edi
lea    0xe0(%rsp),%rsi
mov    $0x400,%edx
call   10a0 <read@plt>
mov    (%r12),%esi
lea    0xdd8(%rip),%rdi
call   10b0 <access@plt>
cmp    $0xffffffff,%eax
je     135c <Writer+0x18c>
lea    0xe8c(%rip),%rdi
call   1040 <puts@plt>
lea    0xdb7(%rip),%rbx
mov    %rbx,%rdi
lea    0xdc0(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%rbp
mov    %rax,%rdi
lea    0xdb0(%rip),%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdx
call   1090 <fscanf@plt>
mov    %rbp,%rdi
call   1070 <fclose@plt>
mov    %rbx,%rdi
call   1030 <remove@plt>
mov    0x2d10(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
call   1050 <clock_gettime@plt>
mov    (%rsp),%ebp
lea    0x60(%rsp),%rbx
mov    %rbx,%rdi
lea    0xd73(%rip),%rsi
mov    %r14,%rdx
mov    %ebp,%ecx
call   10d0 <sprintf@plt>
lea    0xd6c(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %rbx,%rdi
lea    0xd67(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%r13
lea    0xde6(%rip),%rdi
call   1040 <puts@plt>
xor    %r14d,%r14d
mov    (%r12),%esi
lea    0xd48(%rip),%rbx
mov    %rbx,%rdi
call   10b0 <access@plt>
cmp    $0xffffffff,%eax
je     1370 <Writer+0x1a0>
mov    %r13,%rdi
call   1070 <fclose@plt>
mov    %rbx,%rdi
call   1030 <remove@plt>
lea    0xda5(%rip),%rdi
call   1040 <puts@plt>
xor    %ebx,%ebx
jmp    1446 <Writer+0x276>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x2c69(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
call   1050 <clock_gettime@plt>
mov    (%rsp),%r15d
cmp    %ebp,%r15d
jle    13f4 <Writer+0x224>
mov    %r13,%rdi
call   1070 <fclose@plt>
lea    0x60(%rsp),%rbx
mov    %rbx,%rdi
lea    0xcbe(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %r15d,%ecx
call   10d0 <sprintf@plt>
mov    %r14,%rax
movabs $0x431bde82d7b634db,%rcx
de 1b 43
imul   %rcx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x12,%rdx
add    %rax,%rdx
lea    0xcba(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %rbx,%rdi
lea    0xc91(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%r13
xor    %r14d,%r14d
jmp    13f7 <Writer+0x227>
mov    %ebp,%r15d
lea    0xe0(%rsp),%r12
mov    0x8(%rsp),%rax
mov    (%rax),%edi
mov    %r12,%rsi
mov    $0x400,%edx
call   10a0 <read@plt>
mov    $0x2,%ebx
test   %eax,%eax
jle    1435 <Writer+0x265>
mov    %eax,%ebp
mov    %r12,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %r13,%rcx
call   10f0 <fwrite@plt>
mov    %ebp,%eax
add    %rax,%r14
mov    %r15d,%ebp
lea    0xc7c(%rip),%r15
mov    0x2b8a(%rip),%r12
mov    (%r12),%esi
mov    %r15,%rdi
call   10b0 <access@plt>
cmp    $0xffffffff,%eax
je     1230 <Writer+0x60>
mov    %r13,%rdi
call   1070 <fclose@plt>
lea    0xbdd(%rip),%rdi
call   1030 <remove@plt>
lea    0xc05(%rip),%rdi
call   1030 <remove@plt>
mov    %r15,%rdi
call   1030 <remove@plt>
lea    0xc6b(%rip),%rdi
call   1040 <puts@plt>
mov    $0x3,%ebx
jmp    1230 <Writer+0x60>
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 = [19 x i8] c"/mnt/ramdisk/START\00"
@F_OK = global i32 0
@.str.4 = [11 x i8] c"Mode 0->1\0A\00"
@.str.5 = [2 x i8] c"r\00"
@.str.6 = [3 x i8] c"%s\00"
@CLOCK_REALTIME = global i32 0
@.str.7 = [10 x i8] c"%s/%d.bin\00"
@.str.8 = [15 x i8] c"Writing to %s\0A\00"
@.str.9 = [3 x i8] c"wb\00"
@.str.10 = [11 x i8] c"Mode 1->2\0A\00"
@.str.11 = [18 x i8] c"/mnt/ramdisk/STOP\00"
@.str.12 = [11 x i8] c"Mode 2->0\0A\00"
@.str.13 = [46 x i8] c"WRITER: Writing to %s, rate = %ld MBytes/sec\0A\00"
@.str.14 = [18 x i8] c"/mnt/ramdisk/QUIT\00"
@.str.15 = [8 x i8] c"Mode 3\0A\00"
define void @Writer(i32* %0) {
%2 = alloca i32*
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.timespec
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca [1024 x i8]
%13 = alloca [80 x i8]
%14 = alloca [120 x i8]
%15 = alloca i32
store i32* %0, i32** %2
store i32 0, i32* %9
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%17 = call i32 (...) @getpid()
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%19 = call i32 (...) @getppid()
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %132, %1
%22 = load i32, i32* %9
%23 = icmp ne i32 %22, 3
br i1 %23, label %24, label %133
24: ; preds = %21
%25 = load i32, i32* %9
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %24
%28 = load i32*, i32** %2
%29 = getelementptr inbounds i32, i32* %28, i64 0
%30 = load i32, i32* %29
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%32 = call i32 @read(i32 %30, i8* %31, i32 1024)
store i32 %32, i32* %15
br label %33
33: ; preds = %27, %24
%34 = load i32, i32* %9
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %42
36: ; preds = %33
%37 = load i32, i32* @F_OK
%38 = call i32 @access(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %37)
%39 = icmp ne i32 %38, -1
br i1 %39, label %40, label %42
40: ; preds = %36
store i32 1, i32* %9
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
br label %42
42: ; preds = %40, %36, %33
%43 = load i32, i32* %9
%44 = icmp eq i32 %43, 1
br i1 %44, label %45, label %67
45: ; preds = %42
%46 = call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %46, i32** %11
%47 = load i32*, i32** %11
%48 = getelementptr inbounds [80 x i8], [80 x i8]* %13, i64 0, i64 0
%49 = call i32 @fscanf(i32* %47, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %48)
%50 = load i32*, i32** %11
%51 = call i32 @fclose(i32* %50)
%52 = call i32 @remove(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%53 = load i32, i32* @CLOCK_REALTIME
%54 = call i32 @clock_gettime(i32 %53, %struct.timespec* %6)
%55 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 0
%56 = load i32, i32* %55
store i32 %56, i32* %4
%57 = load i32, i32* %4
store i32 %57, i32* %5
%58 = getelementptr inbounds [120 x i8], [120 x i8]* %14, i64 0, i64 0
%59 = getelementptr inbounds [80 x i8], [80 x i8]* %13, i64 0, i64 0
%60 = load i32, i32* %4
%61 = call i32 @sprintf(i8* %58, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8* %59, i32 %60)
%62 = getelementptr inbounds [120 x i8], [120 x i8]* %14, i64 0, i64 0
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0), i8* %62)
%64 = getelementptr inbounds [120 x i8], [120 x i8]* %14, i64 0, i64 0
%65 = call i32* @fopen(i8* %64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
store i32* %65, i32** %10
store i32 2, i32* %9
store i64 0, i64* %8
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0))
br label %67
67: ; preds = %45, %42
%68 = load i32, i32* %9
%69 = icmp eq i32 %68, 2
br i1 %69, label %70, label %121
70: ; preds = %67
%71 = load i32, i32* @F_OK
%72 = call i32 @access(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.11, i64 0, i64 0), i32 %71)
%73 = icmp ne i32 %72, -1
br i1 %73, label %74, label %79
74: ; preds = %70
%75 = load i32*, i32** %10
%76 = call i32 @fclose(i32* %75)
%77 = call i32 @remove(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.11, i64 0, i64 0))
store i32 0, i32* %9
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.12, i64 0, i64 0))
br label %120
79: ; preds = %70
%80 = load i32, i32* @CLOCK_REALTIME
%81 = call i32 @clock_gettime(i32 %80, %struct.timespec* %6)
%82 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 0
%83 = load i32, i32* %82
store i32 %83, i32* %4
%84 = load i32, i32* %4
%85 = load i32, i32* %5
%86 = sub nsw i32 %84, %85
%87 = icmp sge i32 %86, 1
br i1 %87, label %88, label %102
88: ; preds = %79
%89 = load i32*, i32** %10
%90 = call i32 @fclose(i32* %89)
%91 = getelementptr inbounds [120 x i8], [120 x i8]* %14, i64 0, i64 0
%92 = getelementptr inbounds [80 x i8], [80 x i8]* %13, i64 0, i64 0
%93 = load i32, i32* %4
%94 = call i32 @sprintf(i8* %91, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8* %92, i32 %93)
%95 = getelementptr inbounds [120 x i8], [120 x i8]* %14, i64 0, i64 0
%96 = load i64, i64* %8
%97 = sdiv i64 %96, 1000000
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.13, i64 0, i64 0), i8* %95, i64 %97)
%99 = getelementptr inbounds [120 x i8], [120 x i8]* %14, i64 0, i64 0
%100 = call i32* @fopen(i8* %99, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
store i32* %100, i32** %10
%101 = load i32, i32* %4
store i32 %101, i32* %5
store i64 0, i64* %8
br label %102
102: ; preds = %88, %79
%103 = load i32*, i32** %2
%104 = getelementptr inbounds i32, i32* %103, i64 0
%105 = load i32, i32* %104
%106 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%107 = call i32 @read(i32 %105, i8* %106, i32 1024)
store i32 %107, i32* %15
%108 = load i32, i32* %15
%109 = icmp sgt i32 %108, 0
br i1 %109, label %110, label %119
110: ; preds = %102
%111 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%112 = load i32, i32* %15
%113 = load i32*, i32** %10
%114 = call i32 @fwrite(i8* %111, i32 1, i32 %112, i32* %113)
%115 = load i32, i32* %15
%116 = sext i32 %115 to i64
%117 = load i64, i64* %8
%118 = add nsw i64 %117, %116
store i64 %118, i64* %8
br label %119
119: ; preds = %110, %102
br label %120
120: ; preds = %119, %74
br label %121
121: ; preds = %120, %67
%122 = load i32, i32* @F_OK
%123 = call i32 @access(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.14, i64 0, i64 0), i32 %122)
%124 = icmp ne i32 %123, -1
br i1 %124, label %125, label %132
125: ; preds = %121
%126 = load i32*, i32** %10
%127 = call i32 @fclose(i32* %126)
%128 = call i32 @remove(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%129 = call i32 @remove(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.11, i64 0, i64 0))
%130 = call i32 @remove(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.14, i64 0, i64 0))
store i32 3, i32* %9
%131 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.15, i64 0, i64 0))
br label %132
132: ; preds = %125, %121
br label %21
133: ; preds = %21
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 = [19 x i8] c"/mnt/ramdisk/START\00"
@F_OK = global i32 0
@.str.5 = [2 x i8] c"r\00"
@.str.6 = [3 x i8] c"%s\00"
@CLOCK_REALTIME = global i32 0
@.str.7 = [10 x i8] c"%s/%d.bin\00"
@.str.8 = [15 x i8] c"Writing to %s\0A\00"
@.str.9 = [3 x i8] c"wb\00"
@.str.11 = [18 x i8] c"/mnt/ramdisk/STOP\00"
@.str.13 = [46 x i8] c"WRITER: Writing to %s, rate = %ld MBytes/sec\0A\00"
@.str.14 = [18 x i8] c"/mnt/ramdisk/QUIT\00"
@str = [40 x i8] c"Rev up the RAID array,WRITER is active!\00"
@str.16 = [7 x i8] c"Mode 3\00"
@str.17 = [10 x i8] c"Mode 2->0\00"
@str.18 = [10 x i8] c"Mode 1->2\00"
@str.19 = [10 x i8] c"Mode 0->1\00"
define void @Writer(i32* nocapture %0) {
%2 = alloca %struct.timespec
%3 = alloca [1024 x i8]
%4 = alloca [80 x i8]
%5 = alloca [120 x i8]
%6 = bitcast %struct.timespec* %2 to i8*
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [120 x i8], [120 x i8]* %5, i64 0, i64 0
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
%11 = tail call i32 (...) @getpid()
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = tail call i32 (...) @getppid()
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
br label %16
16: ; preds = %88, %1
%17 = phi i32 [ undef, %1 ], [ %75, %88 ]
%18 = phi i64 [ undef, %1 ], [ %76, %88 ]
%19 = phi i32 [ 0, %1 ], [ %89, %88 ]
%20 = phi i32* [ undef, %1 ], [ %78, %88 ]
switch i32 %19, label %74 [
i32 3, label %90
i32 0, label %21
i32 1, label %29
i32 2, label %41
]
21: ; preds = %16
%22 = load i32, i32* %0
%23 = call i32 @read(i32 %22, i8* %7, i32 1024)
%24 = load i32, i32* @F_OK
%25 = call i32 @access(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %24)
%26 = icmp eq i32 %25, -1
br i1 %26, label %74, label %27
27: ; preds = %21
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.19, i64 0, i64 0))
br label %29
29: ; preds = %16, %27
%30 = call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%31 = call i32 @fscanf(i32* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %8)
%32 = call i32 @fclose(i32* %30)
%33 = call i32 @remove(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%34 = load i32, i32* @CLOCK_REALTIME
%35 = call i32 @clock_gettime(i32 %34, %struct.timespec* %2)
%36 = load i32, i32* %15
%37 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8* %8, i32 %36)
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0), i8* %9)
%39 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.18, i64 0, i64 0))
br label %41
41: ; preds = %16, %29
%42 = phi i32* [ %39, %29 ], [ %20, %16 ]
%43 = phi i64 [ 0, %29 ], [ %18, %16 ]
%44 = phi i32 [ %36, %29 ], [ %17, %16 ]
%45 = load i32, i32* @F_OK
%46 = call i32 @access(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.11, i64 0, i64 0), i32 %45)
%47 = icmp eq i32 %46, -1
br i1 %47, label %52, label %48
48: ; preds = %41
%49 = call i32 @fclose(i32* %42)
%50 = call i32 @remove(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.11, i64 0, i64 0))
%51 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.17, i64 0, i64 0))
br label %74
52: ; preds = %41
%53 = load i32, i32* @CLOCK_REALTIME
%54 = call i32 @clock_gettime(i32 %53, %struct.timespec* %2)
%55 = load i32, i32* %15
%56 = icmp sgt i32 %55, %44
br i1 %56, label %57, label %63
57: ; preds = %52
%58 = call i32 @fclose(i32* %42)
%59 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8* %8, i32 %55)
%60 = sdiv i64 %43, 1000000
%61 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.13, i64 0, i64 0), i8* %9, i64 %60)
%62 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
br label %63
63: ; preds = %57, %52
%64 = phi i32 [ %55, %57 ], [ %44, %52 ]
%65 = phi i64 [ 0, %57 ], [ %43, %52 ]
%66 = phi i32* [ %62, %57 ], [ %42, %52 ]
%67 = load i32, i32* %0
%68 = call i32 @read(i32 %67, i8* %7, i32 1024)
%69 = icmp sgt i32 %68, 0
br i1 %69, label %70, label %74
70: ; preds = %63
%71 = call i32 @fwrite(i8* %7, i32 1, i32 %68, i32* %66)
%72 = zext i32 %68 to i64
%73 = add nsw i64 %65, %72
br label %74
74: ; preds = %16, %21, %48, %70, %63
%75 = phi i32 [ %44, %48 ], [ %64, %70 ], [ %64, %63 ], [ %17, %21 ], [ %17, %16 ]
%76 = phi i64 [ %43, %48 ], [ %73, %70 ], [ %65, %63 ], [ %18, %21 ], [ %18, %16 ]
%77 = phi i32 [ 0, %48 ], [ 2, %70 ], [ 2, %63 ], [ 0, %21 ], [ %19, %16 ]
%78 = phi i32* [ %42, %48 ], [ %66, %70 ], [ %66, %63 ], [ %20, %21 ], [ %20, %16 ]
%79 = load i32, i32* @F_OK
%80 = call i32 @access(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.14, i64 0, i64 0), i32 %79)
%81 = icmp eq i32 %80, -1
br i1 %81, label %88, label %82
82: ; preds = %74
%83 = call i32 @fclose(i32* %78)
%84 = call i32 @remove(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%85 = call i32 @remove(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.11, i64 0, i64 0))
%86 = call i32 @remove(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.14, i64 0, i64 0))
%87 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.16, i64 0, i64 0))
br label %88
88: ; preds = %82, %74
%89 = phi i32 [ 3, %82 ], [ %77, %74 ]
br label %16
90: ; preds = %16
ret void
}