#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 EOF;
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
void *getchar();
int /*<<< orphan*/ putchar(unsigned char);
int /*<<< orphan*/ stdout;
int main() {
  int c;
  unsigned char convertTable[65536], conv = 0;
  unsigned char grayScale, maxGray = 0, minGray = 255;
  unsigned long i, convIndex;
  for (i = 0; i < 65536; i++)
    convertTable[i] = getchar();
  while (EOF != (c = getchar())) {
    if (0 == conv) {
      convIndex = c & 0xFF;
      conv = 1;
    } else {
      convIndex <<= 8;
      convIndex += c & 0xFF;
      conv = 0;
      grayScale = convertTable[convIndex & (65536 - 1)];
      if (grayScale > maxGray)
        maxGray = grayScale;
      if (grayScale < minGray)
        minGray = grayScale;
      putchar(grayScale);
    };
  };
  putchar(maxGray);
  putchar(minGray);
  fflush(stdout);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10030,%rsp
movl   $0x0,-0x4(%rbp)
movb   $0x0,-0x10011(%rbp)
movb   $0x0,-0x10013(%rbp)
movb   $0xff,-0x10014(%rbp)
movq   $0x0,-0x10020(%rbp)
cmpq   $0x10000,-0x10020(%rbp)
jae    11a1 <main+0x71>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,%cl
mov    -0x10020(%rbp),%rax
mov    %cl,-0x10010(%rbp,%rax,1)
mov    -0x10020(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10020(%rbp)
jmp    1162 <main+0x32>
jmp    11a6 <main+0x76>
mov    0x2e3b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1002c(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %rax,%rcx
mov    -0x1002c(%rbp),%eax
mov    %ecx,-0x8(%rbp)
cmp    %ecx,%eax
je     129e <main+0x16e>
movzbl -0x10011(%rbp),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
jne    11fe <main+0xce>
mov    -0x8(%rbp),%eax
and    $0xff,%eax
cltq
mov    %rax,-0x10028(%rbp)
movb   $0x1,-0x10011(%rbp)
jmp    1299 <main+0x169>
mov    -0x10028(%rbp),%rax
shl    $0x8,%rax
mov    %rax,-0x10028(%rbp)
mov    -0x8(%rbp),%eax
and    $0xff,%eax
cltq
add    -0x10028(%rbp),%rax
mov    %rax,-0x10028(%rbp)
movb   $0x0,-0x10011(%rbp)
mov    -0x10028(%rbp),%rax
and    $0xffff,%rax
mov    -0x10010(%rbp,%rax,1),%al
mov    %al,-0x10012(%rbp)
movzbl -0x10012(%rbp),%eax
movzbl -0x10013(%rbp),%ecx
cmp    %ecx,%eax
jle    126b <main+0x13b>
mov    -0x10012(%rbp),%al
mov    %al,-0x10013(%rbp)
movzbl -0x10012(%rbp),%eax
movzbl -0x10014(%rbp),%ecx
cmp    %ecx,%eax
jge    128d <main+0x15d>
mov    -0x10012(%rbp),%al
mov    %al,-0x10014(%rbp)
movzbl -0x10012(%rbp),%edi
call   1030 <putchar@plt>
jmp    11a6 <main+0x76>
movzbl -0x10013(%rbp),%edi
call   1030 <putchar@plt>
movzbl -0x10014(%rbp),%edi
call   1030 <putchar@plt>
mov    0x2d1b(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
xor    %eax,%eax
add    $0x10030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10008,%rsp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %al,(%rsp,%rbx,1)
add    $0x1,%rbx
cmp    $0x10000,%rbx
jne    1150 <main+0x20>
mov    0x2e7a(%rip),%r14
mov    (%r14),%ebx
xor    %eax,%eax
call   1040 <getchar@plt>
mov    $0xff,%r15b
mov    $0x0,%r12d
cmp    %eax,%ebx
jne    11b9 <main+0x89>
movzbl %r12b,%edi
call   1030 <putchar@plt>
movzbl %r15b,%edi
call   1030 <putchar@plt>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
xor    %eax,%eax
add    $0x10008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xff,%r15b
xor    %r12d,%r12d
xor    %ebx,%ebx
jmp    1211 <main+0xe1>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
shl    $0x8,%r13
movzbl %al,%eax
or     %rax,%r13
movzwl %r13w,%eax
movzbl (%rsp,%rax,1),%edi
cmp    %r12b,%dil
movzbl %r12b,%r12d
cmova  %edi,%r12d
cmp    %r15b,%dil
movzbl %r15b,%r15d
cmovb  %edi,%r15d
call   1030 <putchar@plt>
xor    %ebx,%ebx
mov    (%r14),%ebp
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    %eax,%ebp
je     1185 <main+0x55>
test   %ebx,%ebx
jne    11d0 <main+0xa0>
movzbl %al,%r13d
mov    $0x1,%ebx
jmp    11ff <main+0xcf>

LLVM IR (-O0):
@EOF = global i32 0
@stdout = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [65536 x i8]
%4 = alloca i8
%5 = alloca i8
%6 = alloca i8
%7 = alloca i8
%8 = alloca i64
%9 = alloca i64
store i32 0, i32* %1
store i8 0, i8* %4
store i8 0, i8* %6
store i8 -1, i8* %7
store i64 0, i64* %8
br label %10
10: ; preds = %18, %0
%11 = load i64, i64* %8
%12 = icmp ult i64 %11, 65536
br i1 %12, label %13, label %21
13: ; preds = %10
%14 = call i8* (...) @getchar()
%15 = ptrtoint i8* %14 to i8
%16 = load i64, i64* %8
%17 = getelementptr inbounds [65536 x i8], [65536 x i8]* %3, i64 0, i64 %16
store i8 %15, i8* %17
br label %18
18: ; preds = %13
%19 = load i64, i64* %8
%20 = add i64 %19, 1
store i64 %20, i64* %8
br label %10
21: ; preds = %10
br label %22
22: ; preds = %65, %21
%23 = load i32, i32* @EOF
%24 = call i8* (...) @getchar()
%25 = ptrtoint i8* %24 to i32
store i32 %25, i32* %2
%26 = icmp ne i32 %23, %25
br i1 %26, label %27, label %66
27: ; preds = %22
%28 = load i8, i8* %4
%29 = zext i8 %28 to i32
%30 = icmp eq i32 0, %29
br i1 %30, label %31, label %35
31: ; preds = %27
%32 = load i32, i32* %2
%33 = and i32 %32, 255
%34 = sext i32 %33 to i64
store i64 %34, i64* %9
store i8 1, i8* %4
br label %65
35: ; preds = %27
%36 = load i64, i64* %9
%37 = shl i64 %36, 8
store i64 %37, i64* %9
%38 = load i32, i32* %2
%39 = and i32 %38, 255
%40 = sext i32 %39 to i64
%41 = load i64, i64* %9
%42 = add i64 %41, %40
store i64 %42, i64* %9
store i8 0, i8* %4
%43 = load i64, i64* %9
%44 = and i64 %43, 65535
%45 = getelementptr inbounds [65536 x i8], [65536 x i8]* %3, i64 0, i64 %44
%46 = load i8, i8* %45
store i8 %46, i8* %5
%47 = load i8, i8* %5
%48 = zext i8 %47 to i32
%49 = load i8, i8* %6
%50 = zext i8 %49 to i32
%51 = icmp sgt i32 %48, %50
br i1 %51, label %52, label %54
52: ; preds = %35
%53 = load i8, i8* %5
store i8 %53, i8* %6
br label %54
54: ; preds = %52, %35
%55 = load i8, i8* %5
%56 = zext i8 %55 to i32
%57 = load i8, i8* %7
%58 = zext i8 %57 to i32
%59 = icmp slt i32 %56, %58
br i1 %59, label %60, label %62
60: ; preds = %54
%61 = load i8, i8* %5
store i8 %61, i8* %7
br label %62
62: ; preds = %60, %54
%63 = load i8, i8* %5
%64 = call i32 @putchar(i8 zeroext %63)
br label %65
65: ; preds = %62, %31
br label %22
66: ; preds = %22
%67 = load i8, i8* %6
%68 = call i32 @putchar(i8 zeroext %67)
%69 = load i8, i8* %7
%70 = call i32 @putchar(i8 zeroext %69)
%71 = load i32, i32* @stdout
%72 = call i32 @fflush(i32 %71)
ret i32 0
}

LLVM IR (-O2):
@EOF = global i32 0
@stdout = global i32 0
define i32 @main() {
%1 = alloca [65536 x i8]
%2 = getelementptr inbounds [65536 x i8], [65536 x i8]* %1, i64 0, i64 0
br label %9
3: ; preds = %9
%4 = load i32, i32* @EOF
%5 = tail call i8* (...) @getchar()
%6 = ptrtoint i8* %5 to i64
%7 = trunc i64 %6 to i32
%8 = icmp eq i32 %4, %7
br i1 %8, label %48, label %17
9: ; preds = %0, %9
%10 = phi i64 [ 0, %0 ], [ %15, %9 ]
%11 = tail call i8* (...) @getchar()
%12 = ptrtoint i8* %11 to i64
%13 = trunc i64 %12 to i8
%14 = getelementptr inbounds [65536 x i8], [65536 x i8]* %1, i64 0, i64 %10
store i8 %13, i8* %14
%15 = add nuw nsw i64 %10, 1
%16 = icmp eq i64 %15, 65536
br i1 %16, label %3, label %9
17: ; preds = %3, %38
%18 = phi i64 [ %45, %38 ], [ %6, %3 ]
%19 = phi i64 [ %42, %38 ], [ undef, %3 ]
%20 = phi i8 [ %41, %38 ], [ -1, %3 ]
%21 = phi i8 [ %40, %38 ], [ 0, %3 ]
%22 = phi i32 [ %39, %38 ], [ 0, %3 ]
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %17
%25 = and i64 %18, 255
br label %38
26: ; preds = %17
%27 = shl i64 %19, 8
%28 = and i64 %18, 255
%29 = or i64 %28, %27
%30 = and i64 %29, 65535
%31 = getelementptr inbounds [65536 x i8], [65536 x i8]* %1, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = icmp ugt i8 %32, %21
%34 = select i1 %33, i8 %32, i8 %21
%35 = icmp ult i8 %32, %20
%36 = select i1 %35, i8 %32, i8 %20
%37 = tail call i32 @putchar(i8 zeroext %32)
br label %38
38: ; preds = %26, %24
%39 = phi i32 [ 1, %24 ], [ 0, %26 ]
%40 = phi i8 [ %21, %24 ], [ %34, %26 ]
%41 = phi i8 [ %20, %24 ], [ %36, %26 ]
%42 = phi i64 [ %25, %24 ], [ %29, %26 ]
%43 = load i32, i32* @EOF
%44 = tail call i8* (...) @getchar()
%45 = ptrtoint i8* %44 to i64
%46 = trunc i64 %45 to i32
%47 = icmp eq i32 %43, %46
br i1 %47, label %48, label %17
48: ; preds = %38, %3
%49 = phi i8 [ 0, %3 ], [ %40, %38 ]
%50 = phi i8 [ -1, %3 ], [ %41, %38 ]
%51 = tail call i32 @putchar(i8 zeroext %49)
%52 = tail call i32 @putchar(i8 zeroext %50)
%53 = load i32, i32* @stdout
%54 = tail call i32 @fflush(i32 %53)
ret i32 0
}