#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 */

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ execlp(char *, char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ memset(char *, int, char);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ sleep(double);
int /*<<< orphan*/ sprintf(char *, char *, char const *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ wait();
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char const *argv[]) {
  if (argc == 1) {
    printf("%s\n", "Usage: ./service <fifo-prefix>");
    exit(1);
  };
  char buf[1024], tmp[128];
  sprintf(buf, "%sr.dat", argv[1]);
  int fd_w = open(buf, O_WRONLY);
  if (fd_w == -1) {
    printf("%s\n", "WERROR !!");
    exit(1);
  };
  sprintf(tmp, "%sw.dat", argv[1]);
  int fd_r = open(tmp, O_RDONLY);
  if (fd_r == -1) {
    printf("%s\n", "RERROR !!");
    exit(1);
  };
  printf("You are good to go.\n");
  while (1) {
    memset(buf, 128, '\0');
    if (read(fd_r, buf, 128) == 0) {
      sleep(0.5);
      continue;
    }
    if (strcmp(buf, "exit") == 0) {
      printf("Service 1 Exiting . . .\n");
      exit(127);
    }
    if (fork() > 0) {
      wait();
    } else {
      memset(buf, 1024, '\0');
      write(fd_w, buf, 1024);
      execlp("ls", "ls", buf, NULL);
      {
        printf("%s\n", "execlp error");
        exit(1);
      };
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4a0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1202 <main+0x42>
lea    0xe1e(%rip),%rdi
lea    0xe1b(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe13(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x410(%rbp),%rdi
mov    0x2da5(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x494(%rbp)
cmpl   $0xffffffff,-0x494(%rbp)
jne    1264 <main+0xa4>
lea    0xdbc(%rip),%rdi
lea    0xde0(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    -0x490(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdc3(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x490(%rbp),%rdi
mov    0x2d5b(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x498(%rbp)
cmpl   $0xffffffff,-0x498(%rbp)
jne    12c6 <main+0x106>
lea    0xd5a(%rip),%rdi
lea    0xd90(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xd82(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x410(%rbp),%rdi
mov    $0x80,%esi
xor    %edx,%edx
call   1050 <memset@plt>
mov    -0x498(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x80,%edx
call   1060 <read@plt>
cmp    $0x0,%rax
jne    131a <main+0x15a>
movsd  0xcf0(%rip),%xmm0
call   10c0 <sleep@plt>
jmp    12d4 <main+0x114>
lea    -0x410(%rbp),%rdi
lea    0xd3c(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    134f <main+0x18f>
lea    0xd2b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x7f,%edi
call   10a0 <exit@plt>
mov    $0x0,%al
call   10e0 <fork@plt>
cmp    $0x0,%rax
jle    136c <main+0x1ac>
mov    $0x0,%al
call   10d0 <wait@plt>
jmp    13cf <main+0x20f>
lea    -0x410(%rbp),%rdi
mov    $0x400,%esi
xor    %edx,%edx
call   1050 <memset@plt>
mov    -0x494(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1030 <write@plt>
lea    -0x410(%rbp),%rdx
lea    0xcde(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rsi,%rdi
call   10b0 <execlp@plt>
lea    0xc51(%rip),%rdi
lea    0xcc7(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    12d4 <main+0x114>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x488,%rsp
cmp    $0x1,%edi
jne    11de <main+0x1e>
lea    0xe2f(%rip),%rdi
jmp    132d <main+0x16d>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdx
lea    0xe3b(%rip),%rsi
lea    0x80(%rsp),%rbp
mov    %rbp,%rdi
call   1090 <sprintf@plt>
mov    0x2dcd(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1080 <open@plt>
cmp    $0xffffffff,%eax
jne    121e <main+0x5e>
lea    0xe16(%rip),%rdi
jmp    132d <main+0x16d>
mov    %eax,%r14d
mov    0x8(%rbx),%rdx
lea    0xe0d(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1090 <sprintf@plt>
mov    0x2daa(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1080 <open@plt>
cmp    $0xffffffff,%eax
jne    1259 <main+0x99>
lea    0xded(%rip),%rdi
jmp    132d <main+0x16d>
mov    %eax,%ebp
lea    0xdfe(%rip),%rdi
call   1030 <puts@plt>
lea    0x80(%rsp),%rbx
lea    0xdd5(%rip),%r15
jmp    128d <main+0xcd>
nopl   0x0(%rax,%rax,1)
movsd  0xd78(%rip),%xmm0
call   10c0 <sleep@plt>
mov    %rbx,%rdi
mov    $0x80,%esi
xor    %edx,%edx
call   1050 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x80,%edx
call   1060 <read@plt>
test   %rax,%rax
je     1280 <main+0xc0>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     12d5 <main+0x115>
xor    %eax,%eax
call   10e0 <fork@plt>
test   %rax,%rax
jle    12eb <main+0x12b>
xor    %eax,%eax
call   10d0 <wait@plt>
jmp    128d <main+0xcd>
lea    0xd98(%rip),%rdi
call   1030 <puts@plt>
mov    $0x7f,%edi
call   10a0 <exit@plt>
lea    0x80(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
xor    %edx,%edx
call   1050 <memset@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1040 <write@plt>
lea    0xd37(%rip),%rdi
mov    %rdi,%rsi
mov    %rbx,%rdx
xor    %ecx,%ecx
call   10b0 <execlp@plt>
lea    0xd26(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [31 x i8] c"Usage: ./service <fifo-prefix>\00"
@.str.2 = [8 x i8] c"%sr.dat\00"
@O_WRONLY = global i32 0
@.str.3 = [10 x i8] c"WERROR !!\00"
@.str.4 = [8 x i8] c"%sw.dat\00"
@O_RDONLY = global i32 0
@.str.5 = [10 x i8] c"RERROR !!\00"
@.str.6 = [21 x i8] c"You are good to go.\0A\00"
@.str.7 = [5 x i8] c"exit\00"
@.str.8 = [25 x i8] c"Service 1 Exiting . . .\0A\00"
@.str.9 = [3 x i8] c"ls\00"
@.str.10 = [13 x i8] c"execlp error\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
%7 = alloca [128 x i8]
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @sprintf(i8* %16, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %19)
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%22 = load i32, i32* @O_WRONLY
%23 = call i32 @open(i8* %21, i32 %22)
store i32 %23, i32* %8
%24 = load i32, i32* %8
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %29
26: ; preds = %15
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %15
%30 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i32 @sprintf(i8* %30, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* %33)
%35 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%36 = load i32, i32* @O_RDONLY
%37 = call i32 @open(i8* %35, i32 %36)
store i32 %37, i32* %9
%38 = load i32, i32* %9
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %43
40: ; preds = %29
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %29
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
br label %45
45: ; preds = %43, %52, %76
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%47 = call i32 @memset(i8* %46, i32 128, i8 signext 0)
%48 = load i32, i32* %9
%49 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%50 = call i64 @read(i32 %48, i8* %49, i32 128)
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %45
%53 = call i32 @sleep(double 5.000000e-01)
br label %45
54: ; preds = %45
%55 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%56 = call i64 @strcmp(i8* %55, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%57 = icmp eq i64 %56, 0
br i1 %57, label %58, label %61
58: ; preds = %54
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0))
%60 = call i32 @exit(i32 127)
unreachable
61: ; preds = %54
%62 = call i64 (...) @fork()
%63 = icmp sgt i64 %62, 0
br i1 %63, label %64, label %66
64: ; preds = %61
%65 = call i32 (...) @wait()
br label %76
66: ; preds = %61
%67 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%68 = call i32 @memset(i8* %67, i32 1024, i8 signext 0)
%69 = load i32, i32* %8
%70 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%71 = call i32 @write(i32 %69, i8* %70, i32 1024)
%72 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%73 = call i32 @execlp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i8* %72, i32* null)
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0))
%75 = call i32 @exit(i32 1)
unreachable
76: ; preds = %64
br label %45
}

LLVM IR (-O2):
@.str.1 = [31 x i8] c"Usage: ./service <fifo-prefix>\00"
@.str.2 = [8 x i8] c"%sr.dat\00"
@O_WRONLY = global i32 0
@.str.3 = [10 x i8] c"WERROR !!\00"
@.str.4 = [8 x i8] c"%sw.dat\00"
@O_RDONLY = global i32 0
@.str.5 = [10 x i8] c"RERROR !!\00"
@.str.7 = [5 x i8] c"exit\00"
@.str.9 = [3 x i8] c"ls\00"
@.str.10 = [13 x i8] c"execlp error\00"
@str = [20 x i8] c"You are good to go.\00"
@str.11 = [24 x i8] c"Service 1 Exiting . . .\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca [128 x i8]
%5 = icmp eq i32 %0, 1
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @sprintf(i8* %10, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %13)
%15 = load i32, i32* @O_WRONLY
%16 = call i32 @open(i8* %10, i32 %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %21
18: ; preds = %9
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %9
%22 = load i8*, i8** %12
%23 = call i32 @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* %22)
%24 = load i32, i32* @O_RDONLY
%25 = call i32 @open(i8* %11, i32 %24)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %30
27: ; preds = %21
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
%29 = tail call i32 @exit(i32 1)
unreachable
30: ; preds = %21
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %32
32: ; preds = %38, %30
%33 = call i32 @memset(i8* %10, i32 128, i8 signext 0)
%34 = call i64 @read(i32 %25, i8* %10, i32 128)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %32
%37 = call i32 @sleep(double 5.000000e-01)
br label %38
38: ; preds = %36, %48
br label %32
39: ; preds = %32
%40 = call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %39
%43 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.11, i64 0, i64 0))
%44 = call i32 @exit(i32 127)
unreachable
45: ; preds = %39
%46 = call i64 (...) @fork()
%47 = icmp sgt i64 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %45
%49 = call i32 (...) @wait()
br label %38
50: ; preds = %45
%51 = call i32 @memset(i8* %10, i32 1024, i8 signext 0)
%52 = call i32 @write(i32 %16, i8* %10, i32 1024)
%53 = call i32 @execlp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i8* %10, i32* null)
%54 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0))
%55 = call i32 @exit(i32 1)
unreachable
}