int in2tty(ttyfd, outpid)
int ttyfd, outpid;
{
  unsigned char c;
  for (;;) {
    if (read(0, &c, 1) < 0)
      return (-1);
    if (c == 033) {
      if (read(0, &c, 1) < 0)
        return (-1);
      switch (c) {
      case 031:
      case 0177:
        goto done;
      case 033:
        break;
      case '!':
        if (callshell(ttyfd, outpid) != 0)
          return (-1);
        continue;
      default:
        continue;
      }
    }
    if (write(ttyfd, &c, 1) < 0)
      return (-1);
  }
done:
  return (0);
}


x86 assembly (clang, -O0):
<in2tty>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
xor    %edi,%edi
lea    -0xd(%rbp),%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1040 <read@plt>
cmp    $0x0,%eax
jge    1165 <in2tty+0x35>
movl   $0xffffffff,-0x4(%rbp)
jmp    1250 <in2tty+0x120>
movzbl -0xd(%rbp),%eax
cmp    $0x1b,%eax
jne    121c <in2tty+0xec>
xor    %edi,%edi
lea    -0xd(%rbp),%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1040 <read@plt>
cmp    $0x0,%eax
jge    1199 <in2tty+0x69>
movl   $0xffffffff,-0x4(%rbp)
jmp    1250 <in2tty+0x120>
movzbl -0xd(%rbp),%eax
mov    %eax,-0x14(%rbp)
sub    $0x19,%eax
je     11e1 <in2tty+0xb1>
jmp    11ae <in2tty+0x7e>
mov    -0x14(%rbp),%eax
sub    $0x1b,%eax
je     11e6 <in2tty+0xb6>
jmp    11bf <in2tty+0x8f>
mov    -0x14(%rbp),%eax
sub    $0x21,%eax
je     11eb <in2tty+0xbb>
jmp    11d0 <in2tty+0xa0>
mov    -0x14(%rbp),%eax
sub    $0x7f,%eax
jne    1212 <in2tty+0xe2>
jmp    11e1 <in2tty+0xb1>
jmp    1249 <in2tty+0x119>
jmp    1217 <in2tty+0xe7>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    $0x0,%al
call   1050 <callshell@plt>
cmp    $0x0,%eax
je     120d <in2tty+0xdd>
movl   $0xffffffff,-0x4(%rbp)
jmp    1250 <in2tty+0x120>
jmp    113e <in2tty+0xe>
jmp    113e <in2tty+0xe>
jmp    121c <in2tty+0xec>
mov    -0x8(%rbp),%edi
lea    -0xd(%rbp),%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1030 <write@plt>
cmp    $0x0,%eax
jge    1244 <in2tty+0x114>
movl   $0xffffffff,-0x4(%rbp)
jmp    1250 <in2tty+0x120>
jmp    113e <in2tty+0xe>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<in2tty>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r14d
mov    %edi,%ebp
lea    0xf(%rsp),%rsi
xor    %edi,%edi
mov    $0x1,%edx
xor    %eax,%eax
call   1040 <read@plt>
test   %eax,%eax
js     11dc <in2tty+0xac>
lea    0xf(%rsp),%rbx
jmp    118f <in2tty+0x5f>
nop
cmp    $0x1b,%cl
jne    11ce <in2tty+0x9e>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1030 <write@plt>
test   %eax,%eax
js     11dc <in2tty+0xac>
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1040 <read@plt>
test   %eax,%eax
js     11dc <in2tty+0xac>
cmpb   $0x1b,0xf(%rsp)
jne    1165 <in2tty+0x35>
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1040 <read@plt>
test   %eax,%eax
js     11dc <in2tty+0xac>
xor    %eax,%eax
movzbl 0xf(%rsp),%ecx
cmp    $0x20,%cl
jle    1160 <in2tty+0x30>
cmp    $0x21,%cl
jne    11d5 <in2tty+0xa5>
mov    %ebp,%edi
mov    %r14d,%esi
xor    %eax,%eax
call   1050 <callshell@plt>
test   %eax,%eax
je     117a <in2tty+0x4a>
jmp    11dc <in2tty+0xac>
cmp    $0x19,%cl
jne    117a <in2tty+0x4a>
jmp    11e1 <in2tty+0xb1>
cmp    $0x7f,%cl
jne    117a <in2tty+0x4a>
jmp    11e1 <in2tty+0xb1>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @in2tty(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
store i32 %0, i32* %4
store i32 %1, i32* %5
br label %7
7: ; preds = %38, %31, %30, %2
%8 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @read to i32 (i32, i8*, i32, ...)*)(i32 0, i8* %6, i32 1)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %7
store i32 -1, i32* %3
br label %40
11: ; preds = %7
%12 = load i8, i8* %6
%13 = zext i8 %12 to i32
%14 = icmp eq i32 %13, 27
br i1 %14, label %15, label %33
15: ; preds = %11
%16 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @read to i32 (i32, i8*, i32, ...)*)(i32 0, i8* %6, i32 1)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %15
store i32 -1, i32* %3
br label %40
19: ; preds = %15
%20 = load i8, i8* %6
%21 = zext i8 %20 to i32
switch i32 %21, label %31 [
i32 25, label %22
i32 127, label %22
i32 27, label %23
i32 33, label %24
]
22: ; preds = %19, %19
br label %39
23: ; preds = %19
br label %32
24: ; preds = %19
%25 = load i32, i32* %4
%26 = load i32, i32* %5
%27 = call i32 (i32, i32, ...) bitcast (i32 (...)* @callshell to i32 (i32, i32, ...)*)(i32 %25, i32 %26)
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %24
store i32 -1, i32* %3
br label %40
30: ; preds = %24
br label %7
31: ; preds = %19
br label %7
32: ; preds = %23
br label %33
33: ; preds = %32, %11
%34 = load i32, i32* %4
%35 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i32, ...)*)(i32 %34, i8* %6, i32 1)
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %33
store i32 -1, i32* %3
br label %40
38: ; preds = %33
br label %7
39: ; preds = %22
store i32 0, i32* %3
br label %40
40: ; preds = %39, %37, %29, %18, %10
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
define i32 @in2tty(i32 %0, i32 %1) {
%3 = alloca i8
%4 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @read to i32 (i32, i8*, i32, ...)*)(i32 0, i8* %3, i32 1)
%5 = icmp slt i32 %4, 0
br i1 %5, label %23, label %6
6: ; preds = %2, %17
%7 = load i8, i8* %3
%8 = icmp eq i8 %7, 27
br i1 %8, label %9, label %20
9: ; preds = %6
%10 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @read to i32 (i32, i8*, i32, ...)*)(i32 0, i8* %3, i32 1)
%11 = icmp slt i32 %10, 0
br i1 %11, label %23, label %12
12: ; preds = %9
%13 = load i8, i8* %3
switch i8 %13, label %17 [
i8 25, label %23
i8 127, label %23
i8 27, label %20
i8 33, label %14
]
14: ; preds = %12
%15 = call i32 (i32, i32, ...) bitcast (i32 (...)* @callshell to i32 (i32, i32, ...)*)(i32 %0, i32 %1)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %14, %12, %20
%18 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @read to i32 (i32, i8*, i32, ...)*)(i32 0, i8* %3, i32 1)
%19 = icmp slt i32 %18, 0
br i1 %19, label %23, label %6
20: ; preds = %12, %6
%21 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i32, ...)*)(i32 %0, i8* %3, i32 1)
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %17
23: ; preds = %17, %9, %14, %20, %12, %12, %2
%24 = phi i32 [ -1, %2 ], [ 0, %12 ], [ 0, %12 ], [ -1, %20 ], [ -1, %14 ], [ -1, %9 ], [ -1, %17 ]
ret i32 %24
}