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

/* Variables and functions */
int ECHO;
int /*<<< orphan*/ F_SETFL;
int ICANON;
int IEXTEN;
int ISIG;
int /*<<< orphan*/ O_NONBLOCK;
int /*<<< orphan*/ O_RDWR;
int STDOUT_FILENO;
int /*<<< orphan*/ TCIOFLUSH;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ TIOCPKT;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ grantpt(int);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, int *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
char *ptsname(int);
int read(int, char *, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ tcflush(int, int /*<<< orphan*/);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ unlockpt(int);
int write(int, ...);
int main() {
  int next_char[16] = {'a', '\n'};
  int master_fd = open("/dev/ptmx", O_RDWR);
  grantpt(master_fd);
  unlockpt(master_fd);
  char *slave_pty = ptsname(master_fd);
  int slave_fd = open(slave_pty, O_RDWR);
  struct termios term;
  tcgetattr(slave_fd, &term);
  term.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);
  tcsetattr(slave_fd, TCSANOW, &term);
  fcntl(master_fd, F_SETFL, O_NONBLOCK);
  int packetMode = 1;
  ioctl(master_fd, TIOCPKT, &packetMode);
  tcflush(master_fd, TCIOFLUSH);
  if (fork()) {
    close(slave_fd);
    while (1) {
      char in_buffer[100];
      int len;
      len = write(master_fd, next_char, 2);
      next_char[0] = (next_char[0] >= 'z' ? 'a' : next_char[0] + 1);
      sleep(1);
      do {
        len = read(master_fd, in_buffer, 100);
        if (in_buffer[0] == '\000') {
          int i;
          printf("packet mode character seen\n");
          for (i = 1; i < len; i++) {
            in_buffer[i - 1] = in_buffer[i];
          }
          len--;
        }
      } while (len <= 0);
      if (len == -1) {
        perror("read on ptmx");
        sleep(2);
      }
      len = write(STDOUT_FILENO, in_buffer, len);
    }
  } else {
    close(master_fd);
    while (1) {
      char in_buffer[100];
      if (read(slave_fd, in_buffer, 2) != 2) {
        perror("read");
        exit(1);
      }
      if (in_buffer[0] == next_char[0]) {
        next_char[0] = (next_char[0] >= 'z' ? 'a' : next_char[0] + 1);
      } else {
        exit(100);
      }
      in_buffer[0] -= 32;
      if (write(slave_fd, in_buffer, 2) != 2) {
        perror("write");
        exit(1);
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1080 <memset@plt>
movl   $0x61,-0x50(%rbp)
movl   $0xa,-0x4c(%rbp)
mov    0x2d89(%rip),%rax
mov    (%rax),%esi
lea    0xda0(%rip),%rdi
call   10f0 <open@plt>
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%edi
call   1110 <grantpt@plt>
mov    -0x54(%rbp),%edi
call   10c0 <unlockpt@plt>
mov    -0x54(%rbp),%edi
call   1030 <ptsname@plt>
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rdi
mov    0x2d51(%rip),%rax
mov    (%rax),%esi
call   10f0 <open@plt>
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%edi
lea    -0x68(%rbp),%rsi
call   10d0 <tcgetattr@plt>
mov    0x2d1c(%rip),%rax
mov    (%rax),%eax
mov    0x2cdb(%rip),%rcx
or     (%rcx),%eax
mov    0x2cfa(%rip),%rcx
or     (%rcx),%eax
mov    0x2cf9(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x68(%rbp),%eax
mov    %eax,-0x68(%rbp)
mov    -0x64(%rbp),%edi
mov    0x2cf4(%rip),%rax
mov    (%rax),%esi
lea    -0x68(%rbp),%rdx
call   10e0 <tcsetattr@plt>
mov    -0x54(%rbp),%edi
mov    0x2cb7(%rip),%rax
mov    (%rax),%esi
mov    0x2cde(%rip),%rax
mov    (%rax),%edx
call   1040 <fcntl@plt>
movl   $0x1,-0x6c(%rbp)
mov    -0x54(%rbp),%edi
mov    0x2c86(%rip),%rax
mov    (%rax),%esi
lea    -0x6c(%rbp),%rdx
call   1090 <ioctl@plt>
mov    -0x54(%rbp),%edi
mov    0x2c79(%rip),%rax
mov    (%rax),%esi
call   1060 <tcflush@plt>
mov    $0x0,%al
call   1140 <fork@plt>
cmp    $0x0,%rax
je     148b <main+0x26b>
mov    -0x64(%rbp),%edi
call   10a0 <close@plt>
mov    -0x54(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x2,%edx
mov    $0x0,%al
call   1050 <write@plt>
mov    %eax,-0xd4(%rbp)
cmpl   $0x7a,-0x50(%rbp)
jl     137a <main+0x15a>
mov    $0x61,%eax
mov    %eax,-0x144(%rbp)
jmp    1386 <main+0x166>
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x144(%rbp)
mov    -0x144(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    $0x1,%edi
call   1130 <sleep@plt>
mov    -0x54(%rbp),%edi
lea    -0xd0(%rbp),%rsi
mov    $0x64,%edx
call   10b0 <read@plt>
mov    %eax,-0xd4(%rbp)
movsbl -0xd0(%rbp),%eax
cmp    $0x0,%eax
jne    142e <main+0x20e>
lea    0xc40(%rip),%rdi
call   1070 <printf@plt>
movl   $0x1,-0xd8(%rbp)
mov    -0xd8(%rbp),%eax
cmp    -0xd4(%rbp),%eax
jge    141f <main+0x1ff>
movslq -0xd8(%rbp),%rax
mov    -0xd0(%rbp,%rax,1),%cl
mov    -0xd8(%rbp),%eax
sub    $0x1,%eax
cltq
mov    %cl,-0xd0(%rbp,%rax,1)
mov    -0xd8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xd8(%rbp)
jmp    13d9 <main+0x1b9>
mov    -0xd4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xd4(%rbp)
jmp    1433 <main+0x213>
cmpl   $0x0,-0xd4(%rbp)
jle    1399 <main+0x179>
cmpl   $0xffffffff,-0xd4(%rbp)
jne    1463 <main+0x243>
lea    0xbd2(%rip),%rdi
call   1100 <perror@plt>
mov    $0x2,%edi
call   1130 <sleep@plt>
mov    0x2b86(%rip),%rax
mov    (%rax),%edi
lea    -0xd0(%rbp),%rsi
mov    -0xd4(%rbp),%edx
mov    $0x0,%al
call   1050 <write@plt>
mov    %eax,-0xd4(%rbp)
jmp    1347 <main+0x127>
mov    -0x54(%rbp),%edi
call   10a0 <close@plt>
mov    -0x64(%rbp),%edi
lea    -0x140(%rbp),%rsi
mov    $0x2,%edx
call   10b0 <read@plt>
cmp    $0x2,%eax
je     14c6 <main+0x2a6>
lea    0xb7c(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
movsbl -0x140(%rbp),%eax
cmp    -0x50(%rbp),%eax
jne    150a <main+0x2ea>
cmpl   $0x7a,-0x50(%rbp)
jl     14f0 <main+0x2d0>
mov    $0x61,%eax
mov    %eax,-0x148(%rbp)
jmp    14fc <main+0x2dc>
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x148(%rbp)
mov    -0x148(%rbp),%eax
mov    %eax,-0x50(%rbp)
jmp    1514 <main+0x2f4>
mov    $0x64,%edi
call   1120 <exit@plt>
movsbl -0x140(%rbp),%eax
sub    $0x20,%eax
mov    %al,-0x140(%rbp)
mov    -0x64(%rbp),%edi
lea    -0x140(%rbp),%rsi
mov    $0x2,%edx
mov    $0x0,%al
call   1050 <write@plt>
cmp    $0x2,%eax
je     1559 <main+0x339>
lea    0xaee(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
jmp    1493 <main+0x273>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xb8,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movabs $0xa00000061,%rax
mov    %rax,0x10(%rsp)
mov    0x2d82(%rip),%rbx
mov    (%rbx),%esi
lea    0xd99(%rip),%rdi
call   10f0 <open@plt>
mov    %eax,%r13d
mov    %eax,%edi
call   1110 <grantpt@plt>
mov    %r13d,%edi
call   10b0 <unlockpt@plt>
mov    %r13d,%edi
call   1030 <ptsname@plt>
mov    (%rbx),%esi
mov    %rax,%rdi
call   10f0 <open@plt>
mov    %eax,%ebp
lea    0x8(%rsp),%rbx
mov    %eax,%edi
mov    %rbx,%rsi
call   10d0 <tcgetattr@plt>
mov    0x2d20(%rip),%rax
mov    0x2ce1(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2cfe(%rip),%rax
or     (%rax),%ecx
mov    0x2cfd(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0x8(%rsp)
mov    0x2cfe(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %rbx,%rdx
call   10e0 <tcsetattr@plt>
mov    0x2cc3(%rip),%rax
mov    (%rax),%esi
mov    0x2cea(%rip),%rax
mov    (%rax),%edx
mov    %r13d,%edi
call   1050 <fcntl@plt>
movl   $0x1,0xc(%rsp)
mov    0x2c91(%rip),%rax
mov    (%rax),%esi
lea    0xc(%rsp),%rdx
mov    %r13d,%edi
call   1080 <ioctl@plt>
mov    0x2c83(%rip),%rax
mov    (%rax),%esi
mov    %r13d,%edi
call   1070 <tcflush@plt>
xor    %eax,%eax
call   1140 <fork@plt>
test   %rax,%rax
je     13f6 <main+0x1d6>
mov    %ebp,%edi
call   1090 <close@plt>
lea    0x50(%rsp),%rbp
lea    0xccb(%rip),%r12
mov    0x2c9f(%rip),%r15
jmp    136f <main+0x14f>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r15),%edi
mov    %rbp,%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1060 <write@plt>
mov    %r13d,%edi
lea    0x10(%rsp),%rsi
mov    $0x2,%edx
xor    %eax,%eax
call   1060 <write@plt>
mov    0x10(%rsp),%eax
lea    0x1(%rax),%ecx
cmp    $0x7a,%eax
mov    $0x61,%eax
cmovge %eax,%ecx
mov    %ecx,0x10(%rsp)
mov    $0x1,%edi
call   1130 <sleep@plt>
jmp    13b4 <main+0x194>
cs nopw 0x0(%rax,%rax,1)
nop
test   %ebx,%ebx
jg     1360 <main+0x140>
mov    %r13d,%edi
mov    %rbp,%rsi
mov    $0x64,%edx
call   10a0 <read@plt>
cmpb   $0x0,0x50(%rsp)
mov    %eax,%ebx
jne    13b0 <main+0x190>
mov    %eax,%r14d
mov    %r12,%rdi
call   1040 <puts@plt>
lea    -0x1(%r14),%ebx
cmp    $0x2,%r14d
jl     13b0 <main+0x190>
mov    %ebx,%edx
mov    %rbp,%rdi
lea    0x51(%rsp),%rsi
call   10c0 <memmove@plt>
jmp    1360 <main+0x140>
mov    %r13d,%edi
call   1090 <close@plt>
lea    0x50(%rsp),%rsi
mov    %ebp,%edi
mov    $0x2,%edx
call   10a0 <read@plt>
cmp    $0x2,%eax
jne    146d <main+0x24d>
mov    $0x61,%r14d
lea    0x50(%rsp),%r15
mov    $0x61,%ebx
movsbl 0x50(%rsp),%eax
cmp    %eax,%ebx
jne    1476 <main+0x256>
cmp    $0x7a,%ebx
lea    0x1(%rbx),%ecx
mov    %ecx,%ebx
cmovge %r14d,%ebx
mov    %ebx,0x10(%rsp)
add    $0xe0,%al
mov    %al,0x50(%rsp)
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x2,%edx
xor    %eax,%eax
call   1060 <write@plt>
cmp    $0x2,%eax
jne    1480 <main+0x260>
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x2,%edx
call   10a0 <read@plt>
cmp    $0x2,%eax
je     1424 <main+0x204>
lea    0xb96(%rip),%rdi
jmp    1487 <main+0x267>
mov    $0x64,%edi
call   1120 <exit@plt>
lea    0xb88(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>

LLVM IR (-O0):
%struct.termios = type { i32 }
@.str = [10 x i8] c"/dev/ptmx\00"
@O_RDWR = global i32 0
@ECHO = global i32 0
@ICANON = global i32 0
@IEXTEN = global i32 0
@ISIG = global i32 0
@TCSANOW = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@TIOCPKT = global i32 0
@TCIOFLUSH = global i32 0
@.str.1 = [28 x i8] c"packet mode character seen\0A\00"
@.str.2 = [13 x i8] c"read on ptmx\00"
@STDOUT_FILENO = global i32 0
@.str.3 = [5 x i8] c"read\00"
@.str.4 = [6 x i8] c"write\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [16 x i32]
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca %struct.termios
%7 = alloca i32
%8 = alloca [100 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca [100 x i8]
store i32 0, i32* %1
%12 = bitcast [16 x i32]* %2 to i8*
%13 = bitcast i8* %12 to <{ i32, i32, [14 x i32] }>*
%14 = getelementptr inbounds <{ i32, i32, [14 x i32] }>, <{ i32, i32, [14 x i32] }>* %13, i32 0, i32 0
store i32 97, i32* %14
%15 = getelementptr inbounds <{ i32, i32, [14 x i32] }>, <{ i32, i32, [14 x i32] }>* %13, i32 0, i32 1
store i32 10, i32* %15
%16 = load i32, i32* @O_RDWR
%17 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %16)
store i32 %17, i32* %3
%18 = load i32, i32* %3
%19 = call i32 @grantpt(i32 %18)
%20 = load i32, i32* %3
%21 = call i32 @unlockpt(i32 %20)
%22 = load i32, i32* %3
%23 = call i8* @ptsname(i32 %22)
store i8* %23, i8** %4
%24 = load i8*, i8** %4
%25 = load i32, i32* @O_RDWR
%26 = call i32 @open(i8* %24, i32 %25)
store i32 %26, i32* %5
%27 = load i32, i32* %5
%28 = call i32 @tcgetattr(i32 %27, %struct.termios* %6)
%29 = load i32, i32* @ECHO
%30 = load i32, i32* @ICANON
%31 = or i32 %29, %30
%32 = load i32, i32* @IEXTEN
%33 = or i32 %31, %32
%34 = load i32, i32* @ISIG
%35 = or i32 %33, %34
%36 = xor i32 %35, -1
%37 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%38 = load i32, i32* %37
%39 = and i32 %38, %36
store i32 %39, i32* %37
%40 = load i32, i32* %5
%41 = load i32, i32* @TCSANOW
%42 = call i32 @tcsetattr(i32 %40, i32 %41, %struct.termios* %6)
%43 = load i32, i32* %3
%44 = load i32, i32* @F_SETFL
%45 = load i32, i32* @O_NONBLOCK
%46 = call i32 @fcntl(i32 %43, i32 %44, i32 %45)
store i32 1, i32* %7
%47 = load i32, i32* %3
%48 = load i32, i32* @TIOCPKT
%49 = call i32 @ioctl(i32 %47, i32 %48, i32* %7)
%50 = load i32, i32* %3
%51 = load i32, i32* @TCIOFLUSH
%52 = call i32 @tcflush(i32 %50, i32 %51)
%53 = call i64 (...) @fork()
%54 = icmp ne i64 %53, 0
br i1 %54, label %55, label %118
55: ; preds = %0
%56 = load i32, i32* %5
%57 = call i32 @close(i32 %56)
br label %58
58: ; preds = %55, %113
%59 = load i32, i32* %3
%60 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 0
%61 = call i32 (i32, ...) @write(i32 %59, i32* %60, i32 2)
store i32 %61, i32* %9
%62 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 0
%63 = load i32, i32* %62
%64 = icmp sge i32 %63, 122
br i1 %64, label %65, label %66
65: ; preds = %58
br label %70
66: ; preds = %58
%67 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 0
%68 = load i32, i32* %67
%69 = add nsw i32 %68, 1
br label %70
70: ; preds = %66, %65
%71 = phi i32 [ 97, %65 ], [ %69, %66 ]
%72 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 0
store i32 %71, i32* %72
%73 = call i32 @sleep(i32 1)
br label %74
74: ; preds = %104, %70
%75 = load i32, i32* %3
%76 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%77 = call i32 @read(i32 %75, i8* %76, i32 100)
store i32 %77, i32* %9
%78 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%79 = load i8, i8* %78
%80 = sext i8 %79 to i32
%81 = icmp eq i32 %80, 0
br i1 %81, label %82, label %103
82: ; preds = %74
%83 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %10
br label %84
84: ; preds = %97, %82
%85 = load i32, i32* %10
%86 = load i32, i32* %9
%87 = icmp slt i32 %85, %86
br i1 %87, label %88, label %100
88: ; preds = %84
%89 = load i32, i32* %10
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 %90
%92 = load i8, i8* %91
%93 = load i32, i32* %10
%94 = sub nsw i32 %93, 1
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 %95
store i8 %92, i8* %96
br label %97
97: ; preds = %88
%98 = load i32, i32* %10
%99 = add nsw i32 %98, 1
store i32 %99, i32* %10
br label %84
100: ; preds = %84
%101 = load i32, i32* %9
%102 = add nsw i32 %101, -1
store i32 %102, i32* %9
br label %103
103: ; preds = %100, %74
br label %104
104: ; preds = %103
%105 = load i32, i32* %9
%106 = icmp sle i32 %105, 0
br i1 %106, label %74, label %107
107: ; preds = %104
%108 = load i32, i32* %9
%109 = icmp eq i32 %108, -1
br i1 %109, label %110, label %113
110: ; preds = %107
%111 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%112 = call i32 @sleep(i32 2)
br label %113
113: ; preds = %110, %107
%114 = load i32, i32* @STDOUT_FILENO
%115 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%116 = load i32, i32* %9
%117 = call i32 (i32, ...) @write(i32 %114, i8* %115, i32 %116)
store i32 %117, i32* %9
br label %58
118: ; preds = %0
%119 = load i32, i32* %3
%120 = call i32 @close(i32 %119)
br label %121
121: ; preds = %118, %163
%122 = load i32, i32* %5
%123 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%124 = call i32 @read(i32 %122, i8* %123, i32 2)
%125 = icmp ne i32 %124, 2
br i1 %125, label %126, label %129
126: ; preds = %121
%127 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%128 = call i32 @exit(i32 1)
unreachable
129: ; preds = %121
%130 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%131 = load i8, i8* %130
%132 = sext i8 %131 to i32
%133 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 0
%134 = load i32, i32* %133
%135 = icmp eq i32 %132, %134
br i1 %135, label %136, label %148
136: ; preds = %129
%137 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 0
%138 = load i32, i32* %137
%139 = icmp sge i32 %138, 122
br i1 %139, label %140, label %141
140: ; preds = %136
br label %145
141: ; preds = %136
%142 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 0
%143 = load i32, i32* %142
%144 = add nsw i32 %143, 1
br label %145
145: ; preds = %141, %140
%146 = phi i32 [ 97, %140 ], [ %144, %141 ]
%147 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 0
store i32 %146, i32* %147
br label %150
148: ; preds = %129
%149 = call i32 @exit(i32 100)
unreachable
150: ; preds = %145
%151 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%152 = load i8, i8* %151
%153 = sext i8 %152 to i32
%154 = sub nsw i32 %153, 32
%155 = trunc i32 %154 to i8
store i8 %155, i8* %151
%156 = load i32, i32* %5
%157 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%158 = call i32 (i32, ...) @write(i32 %156, i8* %157, i32 2)
%159 = icmp ne i32 %158, 2
br i1 %159, label %160, label %163
160: ; preds = %150
%161 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%162 = call i32 @exit(i32 1)
unreachable
163: ; preds = %150
br label %121
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@.str = [10 x i8] c"/dev/ptmx\00"
@O_RDWR = global i32 0
@ECHO = global i32 0
@ICANON = global i32 0
@IEXTEN = global i32 0
@ISIG = global i32 0
@TCSANOW = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@TIOCPKT = global i32 0
@TCIOFLUSH = global i32 0
@STDOUT_FILENO = global i32 0
@.str.3 = [5 x i8] c"read\00"
@.str.4 = [6 x i8] c"write\00"
@str = [27 x i8] c"packet mode character seen\00"
define i32 @main() {
%1 = alloca [16 x i32]
%2 = alloca %struct.termios
%3 = alloca i32
%4 = alloca [100 x i8]
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%6 = alloca [100 x i8]
%7 = bitcast [16 x i32]* %1 to i8*
%8 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 0
store i32 97, i32* %8
%9 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 1
store i32 10, i32* %9
%10 = load i32, i32* @O_RDWR
%11 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = tail call i32 @grantpt(i32 %11)
%13 = tail call i32 @unlockpt(i32 %11)
%14 = tail call i8* @ptsname(i32 %11)
%15 = load i32, i32* @O_RDWR
%16 = tail call i32 @open(i8* %14, i32 %15)
%17 = bitcast %struct.termios* %2 to i8*
%18 = call i32 @tcgetattr(i32 %16, %struct.termios* %2)
%19 = load i32, i32* @ECHO
%20 = load i32, i32* @ICANON
%21 = or i32 %20, %19
%22 = load i32, i32* @IEXTEN
%23 = or i32 %21, %22
%24 = load i32, i32* @ISIG
%25 = or i32 %23, %24
%26 = xor i32 %25, -1
%27 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%28 = load i32, i32* %27
%29 = and i32 %28, %26
store i32 %29, i32* %27
%30 = load i32, i32* @TCSANOW
%31 = call i32 @tcsetattr(i32 %16, i32 %30, %struct.termios* %2)
%32 = load i32, i32* @F_SETFL
%33 = load i32, i32* @O_NONBLOCK
%34 = call i32 @fcntl(i32 %11, i32 %32, i32 %33)
%35 = bitcast i32* %3 to i8*
store i32 1, i32* %3
%36 = load i32, i32* @TIOCPKT
%37 = call i32 @ioctl(i32 %11, i32 %36, i32* %3)
%38 = load i32, i32* @TCIOFLUSH
%39 = call i32 @tcflush(i32 %11, i32 %38)
%40 = call i64 (...) @fork()
%41 = icmp eq i64 %40, 0
br i1 %41, label %70, label %42
42: ; preds = %0
%43 = call i32 @close(i32 %16)
%44 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%45 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 1
br label %46
46: ; preds = %66, %42
%47 = call i32 (i32, ...) @write(i32 %11, i32* %8, i32 2)
%48 = load i32, i32* %8
%49 = icmp sgt i32 %48, 121
%50 = add nsw i32 %48, 1
%51 = select i1 %49, i32 97, i32 %50
store i32 %51, i32* %8
%52 = call i32 @sleep(i32 1)
br label %53
53: ; preds = %63, %46
%54 = call i32 @read(i32 %11, i8* %44, i32 100)
%55 = load i8, i8* %44
%56 = icmp eq i8 %55, 0
br i1 %56, label %57, label %63
57: ; preds = %53
%58 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%59 = icmp sgt i32 %54, 1
%60 = add nsw i32 %54, -1
br i1 %59, label %61, label %63
61: ; preds = %57
%62 = zext i32 %60 to i64
br label %66
63: ; preds = %57, %53
%64 = phi i32 [ %54, %53 ], [ %60, %57 ]
%65 = icmp slt i32 %64, 1
br i1 %65, label %53, label %66
66: ; preds = %63, %61
%67 = phi i32 [ %60, %61 ], [ %64, %63 ]
%68 = load i32, i32* @STDOUT_FILENO
%69 = call i32 (i32, ...) @write(i32 %68, i8* %44, i32 %67)
br label %46
70: ; preds = %0
%71 = call i32 @close(i32 %11)
%72 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%73 = call i32 @read(i32 %16, i8* %72, i32 2)
%74 = icmp eq i32 %73, 2
br i1 %74, label %78, label %75
75: ; preds = %95, %70
%76 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%77 = call i32 @exit(i32 1)
unreachable
78: ; preds = %70, %95
%79 = phi i32 [ %86, %95 ], [ 97, %70 ]
%80 = load i8, i8* %72
%81 = sext i8 %80 to i32
%82 = icmp eq i32 %79, %81
br i1 %82, label %83, label %90
83: ; preds = %78
%84 = icmp sgt i32 %79, 121
%85 = add nsw i32 %79, 1
%86 = select i1 %84, i32 97, i32 %85
store i32 %86, i32* %8
%87 = add i8 %80, -32
store i8 %87, i8* %72
%88 = call i32 (i32, ...) @write(i32 %16, i8* %72, i32 2)
%89 = icmp eq i32 %88, 2
br i1 %89, label %95, label %92
90: ; preds = %78
%91 = call i32 @exit(i32 100)
unreachable
92: ; preds = %83
%93 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%94 = call i32 @exit(i32 1)
unreachable
95: ; preds = %83
%96 = call i32 @read(i32 %16, i8* %72, i32 2)
%97 = icmp eq i32 %96, 2
br i1 %97, label %78, label %75
}