#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char);
int /*<<< orphan*/ read_port(char *, char *);
int main() {
  char current_char = 0;
  char ascii_char = 's';
  int skip_output = 0;
  while (1) {
    skip_output = 0;
    read_port((char *)0x060, &current_char);
    if (!(current_char & 0x80)) {
      switch (current_char) {
      case 0x1f:
        ascii_char = 's';
        break;
      case 0x17:
        ascii_char = 'i';
        break;
      case 0x20:
        ascii_char = 'd';
        break;
      case 0x10:
        exit(0);
        break;
      default:
        skip_output = 1;
        break;
      }
      if (!skip_output) {
        printf("%c\n", ascii_char);
      }
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movb   $0x0,-0x5(%rbp)
movb   $0x73,-0x6(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0xc(%rbp)
mov    $0x60,%edi
lea    -0x5(%rbp),%rsi
call   1030 <read_port@plt>
movsbl -0x5(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
jne    11e7 <main+0xb7>
movsbl -0x5(%rbp),%eax
add    $0xfffffff0,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x10,%eax
ja     11c1 <main+0x91>
mov    -0x18(%rbp),%rax
lea    0xe6a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movb   $0x73,-0x6(%rbp)
jmp    11c8 <main+0x98>
movb   $0x69,-0x6(%rbp)
jmp    11c8 <main+0x98>
movb   $0x64,-0x6(%rbp)
jmp    11c8 <main+0x98>
xor    %edi,%edi
call   1050 <exit@plt>
movl   $0x1,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    11e2 <main+0xb2>
lea    0xe6b(%rip),%rdi
movsbl -0x6(%rbp),%esi
call   1040 <printf@plt>
jmp    11e7 <main+0xb7>
jmp    114e <main+0x1e>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movb   $0x0,0xf(%rsp)
lea    0xf(%rsp),%rbx
lea    0xeb6(%rip),%r15
lea    0xef3(%rip),%r14
jmp    1160 <main+0x30>
mov    $0x69,%al
movzbl %al,%esi
mov    %r14,%rdi
call   1040 <printf@plt>
mov    $0x60,%edi
mov    %rbx,%rsi
call   1030 <read_port@plt>
movsbl 0xf(%rsp),%ecx
test   $0x80,%cl
jne    1160 <main+0x30>
add    $0xfffffff0,%ecx
cmp    $0x10,%ecx
ja     1160 <main+0x30>
mov    $0x73,%al
movslq (%r15,%rcx,4),%rcx
add    %r15,%rcx
jmp    *%rcx
mov    $0x64,%al
jmp    1155 <main+0x25>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"%c\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i8
%4 = alloca i32
store i32 0, i32* %1
store i8 0, i8* %2
store i8 115, i8* %3
store i32 0, i32* %4
br label %5
5: ; preds = %0, %27
store i32 0, i32* %4
%6 = call i32 @read_port(i8* inttoptr (i64 96 to i8*), i8* %2)
%7 = load i8, i8* %2
%8 = sext i8 %7 to i32
%9 = and i32 %8, 128
%10 = icmp ne i32 %9, 0
br i1 %10, label %27, label %11
11: ; preds = %5
%12 = load i8, i8* %2
%13 = sext i8 %12 to i32
switch i32 %13, label %19 [
i32 31, label %14
i32 23, label %15
i32 32, label %16
i32 16, label %17
]
14: ; preds = %11
store i8 115, i8* %3
br label %20
15: ; preds = %11
store i8 105, i8* %3
br label %20
16: ; preds = %11
store i8 100, i8* %3
br label %20
17: ; preds = %11
%18 = call i32 @exit(i32 0)
unreachable
19: ; preds = %11
store i32 1, i32* %4
br label %20
20: ; preds = %19, %16, %15, %14
%21 = load i32, i32* %4
%22 = icmp ne i32 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = load i8, i8* %3
%25 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8 signext %24)
br label %26
26: ; preds = %23, %20
br label %27
27: ; preds = %26, %5
br label %5
}

LLVM IR (-O2):
@.str = [4 x i8] c"%c\0A\00"
define i32 @main() {
%1 = alloca i8
store i8 0, i8* %1
br label %2
2: ; preds = %9, %0
%3 = call i32 @read_port(i8* inttoptr (i64 96 to i8*), i8* %1)
%4 = load i8, i8* %1
%5 = sext i8 %4 to i32
%6 = and i32 %5, 128
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %2
switch i32 %5, label %9 [
i32 31, label %14
i32 23, label %10
i32 32, label %11
i32 16, label %12
]
9: ; preds = %8, %14, %2
br label %2
10: ; preds = %8
br label %14
11: ; preds = %8
br label %14
12: ; preds = %8
%13 = call i32 @exit(i32 0)
unreachable
14: ; preds = %11, %10, %8
%15 = phi i8 [ 115, %8 ], [ 105, %10 ], [ 100, %11 ]
%16 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8 signext %15)
br label %9
}