#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 ssize_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ lcase(char *, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ unlink(char *);
int usage(char *);
int main(int argc, char *argv[]) {
  char buff[256];
  ssize_t len;
  int fd;
  if (argc != 2) {
    return usage(argv[0]);
  }
  int nr = atoi(argv[1]);
  if (nr <= 0 || nr >= 3) {
    return usage(argv[0]);
  }
  char *pipename;
  if (nr == 1) {
    pipename = "/tmp/is141315lc";
  } else {
    pipename = "/tmp/is141315uc";
  }
  printf("%s open pipe\n", pipename);
  if ((fd = open(pipename, O_RDONLY)) == -1) {
    perror("open");
    return 1;
  }
  printf("%s  opend pipe\n", pipename);
  do {
    if ((len = read(fd, buff, 256)) == -1) {
      perror("read");
      break;
    }
    buff[256 - 1] = '\0';
    printf("%s\n", buff);
    lcase(buff, strlen(buff));
  } while (strcmp("quit", buff));
  close(fd);
  unlink(pipename);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11e7 <main+0x37>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10a0 <usage@plt>
mov    %eax,-0x4(%rbp)
jmp    1369 <main+0x1b9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10d0 <atoi@plt>
mov    %eax,-0x11c(%rbp)
cmpl   $0x0,-0x11c(%rbp)
jle    1214 <main+0x64>
cmpl   $0x3,-0x11c(%rbp)
jl     1228 <main+0x78>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10a0 <usage@plt>
mov    %eax,-0x4(%rbp)
jmp    1369 <main+0x1b9>
cmpl   $0x1,-0x11c(%rbp)
jne    1248 <main+0x98>
lea    0xdc4(%rip),%rax
mov    %rax,-0x128(%rbp)
jmp    1256 <main+0xa6>
lea    0xdc1(%rip),%rax
mov    %rax,-0x128(%rbp)
mov    -0x128(%rbp),%rsi
lea    0xdbc(%rip),%rdi
call   1050 <printf@plt>
mov    -0x128(%rbp),%rdi
mov    0x2d71(%rip),%rax
mov    (%rax),%esi
call   10b0 <open@plt>
mov    %eax,-0x118(%rbp)
cmp    $0xffffffff,%eax
jne    12a5 <main+0xf5>
lea    0xd9a(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1369 <main+0x1b9>
mov    -0x128(%rbp),%rsi
lea    0xd80(%rip),%rdi
call   1050 <printf@plt>
mov    -0x118(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
call   1070 <read@plt>
mov    %eax,-0x114(%rbp)
cmp    $0xffffffff,%eax
jne    12ef <main+0x13f>
lea    0xd5e(%rip),%rdi
call   10c0 <perror@plt>
jmp    134b <main+0x19b>
movb   $0x0,-0x11(%rbp)
lea    -0x110(%rbp),%rsi
lea    0xd47(%rip),%rdi
call   1050 <printf@plt>
lea    -0x110(%rbp),%rax
mov    %rax,-0x130(%rbp)
lea    -0x110(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x130(%rbp),%rdi
mov    %eax,%esi
call   1080 <lcase@plt>
lea    -0x110(%rbp),%rsi
lea    0xd10(%rip),%rdi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    12b8 <main+0x108>
mov    -0x118(%rbp),%edi
call   1060 <close@plt>
mov    -0x128(%rbp),%rdi
call   1030 <unlink@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x100,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    11d8 <main+0x28>
mov    0x8(%rbx),%rdi
call   10d0 <atoi@plt>
lea    -0x3(%rax),%ecx
cmp    $0xfffffffd,%ecx
ja     11ef <main+0x3f>
mov    (%rbx),%rdi
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    10a0 <usage@plt>
cmp    $0x1,%eax
lea    0xe07(%rip),%rax
lea    0xe10(%rip),%r14
cmove  %rax,%r14
lea    0xe15(%rip),%rdi
mov    %r14,%rsi
call   1050 <printf@plt>
mov    0x2dce(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   10b0 <open@plt>
cmp    $0xffffffff,%eax
je     12ba <main+0x10a>
mov    %eax,%ebp
lea    0xdfd(%rip),%rdi
mov    %r14,%rsi
call   1050 <printf@plt>
mov    %rsp,%rbx
lea    0xe00(%rip),%r15
lea    0xdfd(%rip),%r12
nop
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x100,%edx
call   1070 <read@plt>
cmp    $0xffffffff,%eax
je     12cd <main+0x11d>
movb   $0x0,0xff(%rsp)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1080 <lcase@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
jne    1250 <main+0xa0>
mov    %ebp,%edi
call   1060 <close@plt>
mov    %r14,%rdi
call   1030 <unlink@plt>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd6d(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%eax
jmp    12aa <main+0xfa>
lea    0xd6f(%rip),%rdi
call   10c0 <perror@plt>
jmp    1299 <main+0xe9>

LLVM IR (-O0):
@.str = [16 x i8] c"/tmp/is141315lc\00"
@.str.1 = [16 x i8] c"/tmp/is141315uc\00"
@.str.2 = [14 x i8] c"%s open pipe\0A\00"
@O_RDONLY = global i32 0
@.str.3 = [5 x i8] c"open\00"
@.str.4 = [16 x i8] c"%s opend pipe\0A\00"
@.str.5 = [5 x i8] c"read\00"
@.str.6 = [4 x i8] c"%s\0A\00"
@.str.7 = [5 x i8] c"quit\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [256 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 @usage(i8* %16)
store i32 %17, i32* %3
br label %74
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %9
%23 = load i32, i32* %9
%24 = icmp sle i32 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %18
%26 = load i32, i32* %9
%27 = icmp sge i32 %26, 3
br i1 %27, label %28, label %33
28: ; preds = %25, %18
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 0
%31 = load i8*, i8** %30
%32 = call i32 @usage(i8* %31)
store i32 %32, i32* %3
br label %74
33: ; preds = %25
%34 = load i32, i32* %9
%35 = icmp eq i32 %34, 1
br i1 %35, label %36, label %37
36: ; preds = %33
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8** %10
br label %38
37: ; preds = %33
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8** %10
br label %38
38: ; preds = %37, %36
%39 = load i8*, i8** %10
%40 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %39)
%41 = load i8*, i8** %10
%42 = load i32, i32* @O_RDONLY
%43 = call i32 @open(i8* %41, i32 %42)
store i32 %43, i32* %8
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %47
45: ; preds = %38
%46 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %74
47: ; preds = %38
%48 = load i8*, i8** %10
%49 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* %48)
br label %50
50: ; preds = %65, %47
%51 = load i32, i32* %8
%52 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%53 = call i32 @read(i32 %51, i8* %52, i32 256)
store i32 %53, i32* %7
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %57
55: ; preds = %50
%56 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %69
57: ; preds = %50
%58 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 255
store i8 0, i8* %58
%59 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%60 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %59)
%61 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%62 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%63 = call i32 @strlen(i8* %62)
%64 = call i32 @lcase(i8* %61, i32 %63)
br label %65
65: ; preds = %57
%66 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%67 = call i64 @strcmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* %66)
%68 = icmp ne i64 %67, 0
br i1 %68, label %50, label %69
69: ; preds = %65, %55
%70 = load i32, i32* %8
%71 = call i32 @close(i32 %70)
%72 = load i8*, i8** %10
%73 = call i32 @unlink(i8* %72)
store i32 0, i32* %3
br label %74
74: ; preds = %69, %45, %28, %13
%75 = load i32, i32* %3
ret i32 %75
}

LLVM IR (-O2):
@.str = [16 x i8] c"/tmp/is141315lc\00"
@.str.1 = [16 x i8] c"/tmp/is141315uc\00"
@.str.2 = [14 x i8] c"%s open pipe\0A\00"
@O_RDONLY = global i32 0
@.str.3 = [5 x i8] c"open\00"
@.str.4 = [16 x i8] c"%s opend pipe\0A\00"
@.str.5 = [5 x i8] c"read\00"
@.str.6 = [4 x i8] c"%s\0A\00"
@.str.7 = [5 x i8] c"quit\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 @usage(i8* %7)
br label %44
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = add i32 %12, -3
%14 = icmp ult i32 %13, -2
br i1 %14, label %15, label %18
15: ; preds = %9
%16 = load i8*, i8** %1
%17 = tail call i32 @usage(i8* %16)
br label %44
18: ; preds = %9
%19 = icmp eq i32 %12, 1
%20 = select i1 %19, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0)
%21 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %20)
%22 = load i32, i32* @O_RDONLY
%23 = tail call i32 @open(i8* %20, i32 %22)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %18
%26 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %44
27: ; preds = %18
%28 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* %20)
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 255
br label %30
30: ; preds = %35, %27
%31 = call i32 @read(i32 %23, i8* %4, i32 256)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %41
35: ; preds = %30
store i8 0, i8* %29
%36 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %4)
%37 = call i32 @strlen(i8* %4)
%38 = call i32 @lcase(i8* %4, i32 %37)
%39 = call i64 @strcmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* %4)
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %30
41: ; preds = %35, %33
%42 = call i32 @close(i32 %23)
%43 = call i32 @unlink(i8* %20)
br label %44
44: ; preds = %15, %41, %25, %6
%45 = phi i32 [ %8, %6 ], [ %17, %15 ], [ 1, %25 ], [ 0, %41 ]
ret i32 %45
}