#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 */
struct termios {
  int c_lflag;
  int *c_cc;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int ECHO;
int ICANON;
int ISIG;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ *gets(char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
int read(int, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int write(int, char *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  char buf[80];
  int x, y, mfd, sfd;
  struct termios tc;
  if (argc < 2) {
    fprintf(stderr, "Usage is: %s <index>\n");
    exit(1);
  }
  sprintf(buf, "//fs/pty:pty%s", argv[1]);
  mfd = open(buf, O_RDWR);
  if (mfd < 0) {
    perror(buf);
    exit(1);
  }
  sprintf(buf, "//fs/pty:tty%s", argv[1]);
  sfd = open(buf, O_RDWR);
  if (sfd < 0) {
    perror(buf);
    exit(1);
  }
  tcgetattr(mfd, &tc);
  tc.c_lflag &= ~(ICANON | ECHO | ISIG);
  tc.c_cc[VMIN] = 1;
  tc.c_cc[VTIME] = 0;
  tcsetattr(mfd, TCSANOW, &tc);
  tcsetattr(sfd, TCSANOW, &tc);
  for (;;) {
    printf("Cmd: ");
    if (gets(buf) == NULL) {
      break;
    }
    switch (buf[0]) {
    case 'r':
      x = read((buf[1] == 's') ? sfd : mfd, buf, sizeof(buf));
      printf("Got %d bytes: '", x);
      if (x > 0) {
        for (y = 0; y < x; ++y) {
          putchar(buf[y]);
        }
      }
      printf("'\n");
      break;
    case 'w':
      x = write((buf[1] == 's') ? sfd : mfd, buf + 1, strlen(buf + 1));
      printf("Wrote %d bytes\n", x);
      break;
    case 'q':
      break;
    }
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1212 <main+0x42>
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
lea    0xdfd(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdf1(%rip),%rsi
call   10e0 <sprintf@plt>
lea    -0x60(%rbp),%rdi
mov    0x2db3(%rip),%rax
mov    (%rax),%esi
call   10c0 <open@plt>
mov    %eax,-0x6c(%rbp)
cmpl   $0x0,-0x6c(%rbp)
jge    125c <main+0x8c>
lea    -0x60(%rbp),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdb6(%rip),%rsi
call   10e0 <sprintf@plt>
lea    -0x60(%rbp),%rdi
mov    0x2d69(%rip),%rax
mov    (%rax),%esi
call   10c0 <open@plt>
mov    %eax,-0x70(%rbp)
cmpl   $0x0,-0x70(%rbp)
jge    12a6 <main+0xd6>
lea    -0x60(%rbp),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x6c(%rbp),%edi
lea    -0x80(%rbp),%rsi
call   10a0 <tcgetattr@plt>
mov    0x2cef(%rip),%rax
mov    (%rax),%eax
mov    0x2d16(%rip),%rcx
or     (%rcx),%eax
mov    0x2d05(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x80(%rbp),%eax
mov    %eax,-0x80(%rbp)
mov    -0x78(%rbp),%rax
mov    0x2ce7(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x78(%rbp),%rax
mov    0x2cba(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x6c(%rbp),%edi
mov    0x2cd6(%rip),%rax
mov    (%rax),%esi
lea    -0x80(%rbp),%rdx
call   10b0 <tcsetattr@plt>
mov    -0x70(%rbp),%edi
mov    0x2cc1(%rip),%rax
mov    (%rax),%esi
lea    -0x80(%rbp),%rdx
call   10b0 <tcsetattr@plt>
lea    0xd03(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x60(%rbp),%rdi
call   1090 <gets@plt>
cmp    $0x0,%rax
jne    1350 <main+0x180>
jmp    14b0 <main+0x2e0>
movsbl -0x60(%rbp),%eax
mov    %eax,-0x84(%rbp)
sub    $0x71,%eax
je     14a6 <main+0x2d6>
jmp    1368 <main+0x198>
mov    -0x84(%rbp),%eax
sub    $0x72,%eax
je     1390 <main+0x1c0>
jmp    137c <main+0x1ac>
mov    -0x84(%rbp),%eax
sub    $0x77,%eax
je     142d <main+0x25d>
jmp    14ab <main+0x2db>
movsbl -0x5f(%rbp),%eax
cmp    $0x73,%eax
jne    13ab <main+0x1db>
mov    -0x70(%rbp),%eax
mov    %eax,-0x88(%rbp)
jmp    13b4 <main+0x1e4>
mov    -0x6c(%rbp),%eax
mov    %eax,-0x88(%rbp)
mov    -0x88(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x50,%edx
call   1070 <read@plt>
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%esi
lea    0xc65(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
cmpl   $0x0,-0x64(%rbp)
jle    141a <main+0x24a>
movl   $0x0,-0x68(%rbp)
mov    -0x68(%rbp),%eax
cmp    -0x64(%rbp),%eax
jge    1415 <main+0x245>
movslq -0x68(%rbp),%rax
movsbl -0x60(%rbp,%rax,1),%edi
call   1030 <putchar@plt>
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    13ed <main+0x21d>
jmp    141a <main+0x24a>
lea    0xc29(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    14ab <main+0x2db>
movsbl -0x5f(%rbp),%eax
cmp    $0x73,%eax
jne    1448 <main+0x278>
mov    -0x70(%rbp),%eax
mov    %eax,-0x8c(%rbp)
jmp    1451 <main+0x281>
mov    -0x6c(%rbp),%eax
mov    %eax,-0x8c(%rbp)
mov    -0x8c(%rbp),%eax
mov    %eax,-0x9c(%rbp)
lea    -0x60(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x98(%rbp)
lea    -0x60(%rbp),%rdi
add    $0x1,%rdi
call   1050 <strlen@plt>
mov    -0x9c(%rbp),%edi
mov    -0x98(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%esi
lea    0xbb3(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    14ab <main+0x2db>
jmp    14ab <main+0x2db>
jmp    132a <main+0x15a>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
cmp    $0x1,%edi
jle    1401 <main+0x221>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdx
lea    0xe11(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   10f0 <sprintf@plt>
mov    0x2dcf(%rip),%r14
mov    (%r14),%esi
mov    %rbx,%rdi
call   10d0 <open@plt>
test   %eax,%eax
js     13ed <main+0x20d>
mov    %eax,%r15d
mov    0x8(%rbp),%rdx
lea    0xdeb(%rip),%rsi
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
call   10f0 <sprintf@plt>
mov    (%r14),%esi
mov    %rbp,%rdi
call   10d0 <open@plt>
test   %eax,%eax
js     13ed <main+0x20d>
mov    %eax,%r14d
mov    %rsp,%rbx
mov    %r15d,%edi
mov    %rbx,%rsi
call   10b0 <tcgetattr@plt>
mov    0x2d36(%rip),%rax
mov    0x2d5f(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2d4c(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,(%rsp)
mov    0x8(%rsp),%rax
mov    0x2d31(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2d08(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2d27(%rip),%rbp
mov    0x0(%rbp),%esi
mov    %r15d,%edi
mov    %rbx,%rdx
call   10c0 <tcsetattr@plt>
mov    0x0(%rbp),%esi
mov    %r14d,%edi
mov    %rbx,%rdx
call   10c0 <tcsetattr@plt>
lea    0xd58(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0x10(%rsp),%rdi
call   10a0 <gets@plt>
test   %rax,%rax
je     13dc <main+0x1fc>
lea    0xd37(%rip),%r12
lea    0x10(%rsp),%rbx
jmp    1361 <main+0x181>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmpb   $0x73,0x11(%rsp)
mov    %r15d,%ebp
cmove  %r14d,%ebp
lea    0x11(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
lea    0x10(%rsp),%rbx
mov    %eax,%edx
call   1050 <write@plt>
lea    0xd09(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r12,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   10a0 <gets@plt>
test   %rax,%rax
je     13dc <main+0x1fc>
movsbl 0x10(%rsp),%eax
cmp    $0x77,%eax
je     1310 <main+0x130>
cmp    $0x72,%eax
jne    134a <main+0x16a>
cmpb   $0x73,0x11(%rsp)
mov    %r15d,%r13d
cmove  %r14d,%r15d
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x50,%edx
call   1080 <read@plt>
mov    %eax,%r15d
lea    0xca4(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
test   %r15d,%r15d
jle    13c3 <main+0x1e3>
mov    %r15d,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax)
movsbl 0x10(%rsp,%rbx,1),%edi
call   1030 <putchar@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    13b0 <main+0x1d0>
lea    0xc7e(%rip),%rdi
call   1040 <puts@plt>
mov    %r13d,%r15d
lea    0x10(%rsp),%rbx
jmp    134a <main+0x16a>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x10(%rsp),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    0x2bb0(%rip),%rax
mov    (%rax),%edi
lea    0xbef(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.termios = type { i32, i32* }
@stderr = global i32 0
@.str = [22 x i8] c"Usage is: %s <index>\0A\00"
@.str.1 = [15 x i8] c"//fs/pty:pty%s\00"
@O_RDWR = global i32 0
@.str.2 = [15 x i8] c"//fs/pty:tty%s\00"
@ICANON = global i32 0
@ECHO = global i32 0
@ISIG = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCSANOW = global i32 0
@.str.3 = [6 x i8] c"Cmd: \00"
@.str.4 = [16 x i8] c"Got %d bytes: '\00"
@.str.5 = [3 x i8] c"'\0A\00"
@.str.6 = [16 x i8] c"Wrote %d bytes\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [80 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.termios
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @sprintf(i8* %19, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%25 = load i32, i32* @O_RDWR
%26 = call i32 @open(i8* %24, i32 %25)
store i32 %26, i32* %9
%27 = load i32, i32* %9
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %18
%30 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%31 = call i32 @perror(i8* %30)
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %18
%34 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = call i32 @sprintf(i8* %34, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %37)
%39 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%40 = load i32, i32* @O_RDWR
%41 = call i32 @open(i8* %39, i32 %40)
store i32 %41, i32* %10
%42 = load i32, i32* %10
%43 = icmp slt i32 %42, 0
br i1 %43, label %44, label %48
44: ; preds = %33
%45 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%46 = call i32 @perror(i8* %45)
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %33
%49 = load i32, i32* %9
%50 = call i32 @tcgetattr(i32 %49, %struct.termios* %11)
%51 = load i32, i32* @ICANON
%52 = load i32, i32* @ECHO
%53 = or i32 %51, %52
%54 = load i32, i32* @ISIG
%55 = or i32 %53, %54
%56 = xor i32 %55, -1
%57 = getelementptr inbounds %struct.termios, %struct.termios* %11, i32 0, i32 0
%58 = load i32, i32* %57
%59 = and i32 %58, %56
store i32 %59, i32* %57
%60 = getelementptr inbounds %struct.termios, %struct.termios* %11, i32 0, i32 1
%61 = load i32*, i32** %60
%62 = load i64, i64* @VMIN
%63 = getelementptr inbounds i32, i32* %61, i64 %62
store i32 1, i32* %63
%64 = getelementptr inbounds %struct.termios, %struct.termios* %11, i32 0, i32 1
%65 = load i32*, i32** %64
%66 = load i64, i64* @VTIME
%67 = getelementptr inbounds i32, i32* %65, i64 %66
store i32 0, i32* %67
%68 = load i32, i32* %9
%69 = load i32, i32* @TCSANOW
%70 = call i32 @tcsetattr(i32 %68, i32 %69, %struct.termios* %11)
%71 = load i32, i32* %10
%72 = load i32, i32* @TCSANOW
%73 = call i32 @tcsetattr(i32 %71, i32 %72, %struct.termios* %11)
br label %74
74: ; preds = %138, %48
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%76 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%77 = call i32* @gets(i8* %76)
%78 = icmp eq i32* %77, null
br i1 %78, label %79, label %80
79: ; preds = %74
br label %139
80: ; preds = %74
%81 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%82 = load i8, i8* %81
%83 = sext i8 %82 to i32
switch i32 %83, label %138 [
i32 114, label %84
i32 119, label %118
i32 113, label %137
]
84: ; preds = %80
%85 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 1
%86 = load i8, i8* %85
%87 = sext i8 %86 to i32
%88 = icmp eq i32 %87, 115
br i1 %88, label %89, label %91
89: ; preds = %84
%90 = load i32, i32* %10
br label %93
91: ; preds = %84
%92 = load i32, i32* %9
br label %93
93: ; preds = %91, %89
%94 = phi i32 [ %90, %89 ], [ %92, %91 ]
%95 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%96 = call i32 @read(i32 %94, i8* %95, i32 80)
store i32 %96, i32* %7
%97 = load i32, i32* %7
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %97)
%99 = load i32, i32* %7
%100 = icmp sgt i32 %99, 0
br i1 %100, label %101, label %116
101: ; preds = %93
store i32 0, i32* %8
br label %102
102: ; preds = %112, %101
%103 = load i32, i32* %8
%104 = load i32, i32* %7
%105 = icmp slt i32 %103, %104
br i1 %105, label %106, label %115
106: ; preds = %102
%107 = load i32, i32* %8
%108 = sext i32 %107 to i64
%109 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 %108
%110 = load i8, i8* %109
%111 = call i32 @putchar(i8 signext %110)
br label %112
112: ; preds = %106
%113 = load i32, i32* %8
%114 = add nsw i32 %113, 1
store i32 %114, i32* %8
br label %102
115: ; preds = %102
br label %116
116: ; preds = %115, %93
%117 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %138
118: ; preds = %80
%119 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 1
%120 = load i8, i8* %119
%121 = sext i8 %120 to i32
%122 = icmp eq i32 %121, 115
br i1 %122, label %123, label %125
123: ; preds = %118
%124 = load i32, i32* %10
br label %127
125: ; preds = %118
%126 = load i32, i32* %9
br label %127
127: ; preds = %125, %123
%128 = phi i32 [ %124, %123 ], [ %126, %125 ]
%129 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%130 = getelementptr inbounds i8, i8* %129, i64 1
%131 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%132 = getelementptr inbounds i8, i8* %131, i64 1
%133 = call i32 @strlen(i8* %132)
%134 = call i32 @write(i32 %128, i8* %130, i32 %133)
store i32 %134, i32* %7
%135 = load i32, i32* %7
%136 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i32 %135)
br label %138
137: ; preds = %80
br label %138
138: ; preds = %80, %137, %127, %116
br label %74
139: ; preds = %79
ret i32 0
}

LLVM IR (-O2):
%struct.termios = type { i32, i32* }
@stderr = global i32 0
@.str = [22 x i8] c"Usage is: %s <index>\0A\00"
@.str.1 = [15 x i8] c"//fs/pty:pty%s\00"
@O_RDWR = global i32 0
@.str.2 = [15 x i8] c"//fs/pty:tty%s\00"
@ICANON = global i32 0
@ECHO = global i32 0
@ISIG = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCSANOW = global i32 0
@.str.3 = [6 x i8] c"Cmd: \00"
@.str.4 = [16 x i8] c"Got %d bytes: '\00"
@.str.6 = [16 x i8] c"Wrote %d bytes\0A\00"
@str = [2 x i8] c"'\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [80 x i8]
%4 = alloca %struct.termios
%5 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.termios* %4 to i8*
%7 = icmp slt i32 %0, 2
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @O_RDWR
%17 = call i32 @open(i8* %5, i32 %16)
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %12
%20 = call i32 @perror(i8* %5)
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %12
%23 = load i8*, i8** %13
%24 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%25 = load i32, i32* @O_RDWR
%26 = call i32 @open(i8* %5, i32 %25)
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %22
%29 = call i32 @perror(i8* %5)
%30 = tail call i32 @exit(i32 1)
unreachable
31: ; preds = %22
%32 = call i32 @tcgetattr(i32 %17, %struct.termios* %4)
%33 = load i32, i32* @ICANON
%34 = load i32, i32* @ECHO
%35 = or i32 %34, %33
%36 = load i32, i32* @ISIG
%37 = or i32 %35, %36
%38 = xor i32 %37, -1
%39 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 0
%40 = load i32, i32* %39
%41 = and i32 %40, %38
store i32 %41, i32* %39
%42 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 1
%43 = load i32*, i32** %42
%44 = load i64, i64* @VMIN
%45 = getelementptr inbounds i32, i32* %43, i64 %44
store i32 1, i32* %45
%46 = load i64, i64* @VTIME
%47 = getelementptr inbounds i32, i32* %43, i64 %46
store i32 0, i32* %47
%48 = load i32, i32* @TCSANOW
%49 = call i32 @tcsetattr(i32 %17, i32 %48, %struct.termios* %4)
%50 = load i32, i32* @TCSANOW
%51 = call i32 @tcsetattr(i32 %26, i32 %50, %struct.termios* %4)
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%53 = call i32* @gets(i8* %5)
%54 = icmp eq i32* %53, null
br i1 %54, label %89, label %55
55: ; preds = %31
%56 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 1
br label %57
57: ; preds = %55, %85
%58 = load i8, i8* %5
%59 = sext i8 %58 to i32
switch i32 %59, label %85 [
i32 114, label %60
i32 119, label %78
]
60: ; preds = %57
%61 = load i8, i8* %56
%62 = icmp eq i8 %61, 115
%63 = select i1 %62, i32 %26, i32 %17
%64 = call i32 @read(i32 %63, i8* %5, i32 80)
%65 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %64)
%66 = icmp sgt i32 %64, 0
br i1 %66, label %67, label %76
67: ; preds = %60
%68 = zext i32 %64 to i64
br label %69
69: ; preds = %67, %69
%70 = phi i64 [ 0, %67 ], [ %74, %69 ]
%71 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 %70
%72 = load i8, i8* %71
%73 = call i32 @putchar(i8 signext %72)
%74 = add nuw nsw i64 %70, 1
%75 = icmp eq i64 %74, %68
br i1 %75, label %76, label %69
76: ; preds = %69, %60
%77 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
br label %85
78: ; preds = %57
%79 = load i8, i8* %56
%80 = icmp eq i8 %79, 115
%81 = select i1 %80, i32 %26, i32 %17
%82 = call i32 @strlen(i8* %56)
%83 = call i32 @write(i32 %81, i8* %56, i32 %82)
%84 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i32 %83)
br label %85
85: ; preds = %57, %78, %76
%86 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%87 = call i32* @gets(i8* %5)
%88 = icmp eq i32* %87, null
br i1 %88, label %89, label %57
89: ; preds = %85, %31
ret i32 0
}