#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*/ printf(char *, char);
scalar_t__ scanf(char *, char *);
int main(void) {
  char nextChar;
  const char sbox[] = {8, 6, 7, 9, 3, 12, 10, 15, 13, 1, 14, 4, 0, 11, 5, 2};
  while (scanf("%c", &nextChar)) {
    switch (nextChar) {
    case '0':
    case '1':
    case '2':
    case '3':
    case '4':
    case '5':
    case '6':
    case '7':
    case '8':
    case '9':
      nextChar -= 48;
      break;
    case 'a':
    case 'A':
      nextChar = 10;
      break;
    case 'b':
    case 'B':
      nextChar = 11;
      break;
    case 'c':
    case 'C':
      nextChar = 12;
      break;
    case 'd':
    case 'D':
      nextChar = 13;
      break;
    case 'e':
    case 'E':
      nextChar = 14;
      break;
    case 'f':
    case 'F':
      nextChar = 15;
      break;
    default:
      while (1)
        ;
    }
    nextChar = sbox[nextChar];
    switch (nextChar) {
    case 0:
    case 1:
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
    case 7:
    case 8:
    case 9:
      nextChar += 48;
      break;
    case 10:
    case 11:
    case 12:
    case 13:
    case 14:
    case 15:
      nextChar += 87;
      break;
    default:
      while (1)
        ;
    }
    printf("%c", nextChar);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xfaa(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xfa7(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xfa4(%rip),%rdi
lea    -0x5(%rbp),%rsi
call   1040 <scanf@plt>
cmp    $0x0,%rax
je     124a <main+0x12a>
movsbl -0x5(%rbp),%eax
add    $0xffffffd0,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x36,%eax
ja     11ce <main+0xae>
mov    -0x28(%rbp),%rax
lea    0xe80(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movsbl -0x5(%rbp),%eax
sub    $0x30,%eax
mov    %al,-0x5(%rbp)
jmp    11d8 <main+0xb8>
movb   $0xa,-0x5(%rbp)
jmp    11d8 <main+0xb8>
movb   $0xb,-0x5(%rbp)
jmp    11d8 <main+0xb8>
movb   $0xc,-0x5(%rbp)
jmp    11d8 <main+0xb8>
movb   $0xd,-0x5(%rbp)
jmp    11d8 <main+0xb8>
movb   $0xe,-0x5(%rbp)
jmp    11d8 <main+0xb8>
movb   $0xf,-0x5(%rbp)
jmp    11d8 <main+0xb8>
jmp    11d3 <main+0xb3>
jmp    11d3 <main+0xb3>
movsbq -0x5(%rbp),%rax
mov    -0x20(%rbp,%rax,1),%al
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%eax
mov    %eax,-0x2c(%rbp)
sub    $0xa,%eax
jb     120d <main+0xed>
jmp    11f9 <main+0xd9>
mov    -0x2c(%rbp),%eax
add    $0xfffffff6,%eax
sub    $0x6,%eax
jb     121c <main+0xfc>
jmp    122b <main+0x10b>
movsbl -0x5(%rbp),%eax
add    $0x30,%eax
mov    %al,-0x5(%rbp)
jmp    1235 <main+0x115>
movsbl -0x5(%rbp),%eax
add    $0x57,%eax
mov    %al,-0x5(%rbp)
jmp    1235 <main+0x115>
jmp    1230 <main+0x110>
jmp    1230 <main+0x110>
lea    0xeb4(%rip),%rdi
movsbl -0x5(%rbp),%esi
call   1030 <printf@plt>
jmp    1145 <main+0x25>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xfcc(%rip),%rdi
lea    0xf(%rsp),%rsi
call   1040 <scanf@plt>
test   %rax,%rax
je     11d2 <main+0xb2>
lea    0xeb2(%rip),%r15
lea    0xf8b(%rip),%r12
lea    0xf94(%rip),%r13
lea    0xf9d(%rip),%rbx
lea    0xf(%rsp),%r14
jmp    11a4 <main+0x84>
nopw   0x0(%rax,%rax,1)
add    $0xd0,%cl
mov    %ecx,%eax
movsbq %al,%rax
movsbq (%rax,%r12,1),%rax
movzbl (%rax,%r13,1),%ecx
add    %al,%cl
mov    %cl,0xf(%rsp)
movsbl %cl,%esi
mov    %rbx,%rdi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <scanf@plt>
test   %rax,%rax
je     11d2 <main+0xb2>
movsbl 0xf(%rsp),%ecx
lea    -0x30(%rcx),%edx
cmp    $0x36,%edx
ja     11d0 <main+0xb0>
mov    $0xa,%al
movslq (%r15,%rdx,4),%rdx
add    %r15,%rdx
jmp    *%rdx
mov    $0xb,%al
jmp    1175 <main+0x55>
mov    $0xc,%al
jmp    1175 <main+0x55>
mov    $0xd,%al
jmp    1175 <main+0x55>
mov    $0xe,%al
jmp    1175 <main+0x55>
mov    $0xf,%al
jmp    1175 <main+0x55>
jmp    11d0 <main+0xb0>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.sbox = [16 x i8] c"\08\06\07\09\03\0C\0A\0F\0D\01\0E\04\00\0B\05\02"
@.str = [3 x i8] c"%c\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca [16 x i8]
store i32 0, i32* %1
%4 = bitcast [16 x i8]* %3 to i8*
br label %5
5: ; preds = %43, %0
%6 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %46
8: ; preds = %5
%9 = load i8, i8* %2
%10 = sext i8 %9 to i32
switch i32 %10, label %22 [
i32 48, label %11
i32 49, label %11
i32 50, label %11
i32 51, label %11
i32 52, label %11
i32 53, label %11
i32 54, label %11
i32 55, label %11
i32 56, label %11
i32 57, label %11
i32 97, label %16
i32 65, label %16
i32 98, label %17
i32 66, label %17
i32 99, label %18
i32 67, label %18
i32 100, label %19
i32 68, label %19
i32 101, label %20
i32 69, label %20
i32 102, label %21
i32 70, label %21
]
11: ; preds = %8, %8, %8, %8, %8, %8, %8, %8, %8, %8
%12 = load i8, i8* %2
%13 = sext i8 %12 to i32
%14 = sub nsw i32 %13, 48
%15 = trunc i32 %14 to i8
store i8 %15, i8* %2
br label %24
16: ; preds = %8, %8
store i8 10, i8* %2
br label %24
17: ; preds = %8, %8
store i8 11, i8* %2
br label %24
18: ; preds = %8, %8
store i8 12, i8* %2
br label %24
19: ; preds = %8, %8
store i8 13, i8* %2
br label %24
20: ; preds = %8, %8
store i8 14, i8* %2
br label %24
21: ; preds = %8, %8
store i8 15, i8* %2
br label %24
22: ; preds = %8
br label %23
23: ; preds = %22, %23
br label %23
24: ; preds = %21, %20, %19, %18, %17, %16, %11
%25 = load i8, i8* %2
%26 = sext i8 %25 to i64
%27 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 %26
%28 = load i8, i8* %27
store i8 %28, i8* %2
%29 = load i8, i8* %2
%30 = sext i8 %29 to i32
switch i32 %30, label %41 [
i32 0, label %31
i32 1, label %31
i32 2, label %31
i32 3, label %31
i32 4, label %31
i32 5, label %31
i32 6, label %31
i32 7, label %31
i32 8, label %31
i32 9, label %31
i32 10, label %36
i32 11, label %36
i32 12, label %36
i32 13, label %36
i32 14, label %36
i32 15, label %36
]
31: ; preds = %24, %24, %24, %24, %24, %24, %24, %24, %24, %24
%32 = load i8, i8* %2
%33 = sext i8 %32 to i32
%34 = add nsw i32 %33, 48
%35 = trunc i32 %34 to i8
store i8 %35, i8* %2
br label %43
36: ; preds = %24, %24, %24, %24, %24, %24
%37 = load i8, i8* %2
%38 = sext i8 %37 to i32
%39 = add nsw i32 %38, 87
%40 = trunc i32 %39 to i8
store i8 %40, i8* %2
br label %43
41: ; preds = %24
br label %42
42: ; preds = %41, %42
br label %42
43: ; preds = %36, %31
%44 = load i8, i8* %2
%45 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %44)
br label %5
46: ; preds = %5
ret i32 0
}

LLVM IR (-O2):
@__const.main.sbox = [16 x i8] c"\08\06\07\09\03\0C\0A\0F\0D\01\0E\04\00\0B\05\02"
@.str = [3 x i8] c"%c\00"
@switch.table.main = [16 x i8] c"0000000000WWWWWW"
define i32 @main() {
%1 = alloca i8
%2 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %1)
%3 = icmp eq i64 %2, 0
br i1 %3, label %27, label %4
4: ; preds = %0, %15
%5 = load i8, i8* %1
%6 = sext i8 %5 to i32
switch i32 %6, label %14 [
i32 48, label %7
i32 49, label %7
i32 50, label %7
i32 51, label %7
i32 52, label %7
i32 53, label %7
i32 54, label %7
i32 55, label %7
i32 56, label %7
i32 57, label %7
i32 97, label %15
i32 65, label %15
i32 98, label %9
i32 66, label %9
i32 99, label %10
i32 67, label %10
i32 100, label %11
i32 68, label %11
i32 101, label %12
i32 69, label %12
i32 102, label %13
i32 70, label %13
]
7: ; preds = %4, %4, %4, %4, %4, %4, %4, %4, %4, %4
%8 = add i8 %5, -48
br label %15
9: ; preds = %4, %4
br label %15
10: ; preds = %4, %4
br label %15
11: ; preds = %4, %4
br label %15
12: ; preds = %4, %4
br label %15
13: ; preds = %4, %4
br label %15
14: ; preds = %4, %14
br label %14
15: ; preds = %4, %4, %13, %12, %11, %10, %9, %7
%16 = phi i8 [ 15, %13 ], [ 14, %12 ], [ 13, %11 ], [ 12, %10 ], [ 11, %9 ], [ %8, %7 ], [ 10, %4 ], [ 10, %4 ]
%17 = sext i8 %16 to i64
%18 = getelementptr inbounds [16 x i8], [16 x i8]* @__const.main.sbox, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i64
%21 = getelementptr inbounds [16 x i8], [16 x i8]* @switch.table.main, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = add i8 %19, %22
store i8 %23, i8* %1
%24 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %23)
%25 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %1)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %4
27: ; preds = %15, %0
ret i32 0
}