#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
char EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ move(int *, char);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  char c;
  int pos[2] = {2, 0};
  FILE *fp = fopen("input", "r");
  char keys[5][5] = {{'0', '0', '1', '0', '0'},
                     {'0', '2', '3', '4', '0'},
                     {'5', '6', '7', '8', '9'},
                     {'0', 'A', 'B', 'C', '0'},
                     {'0', '0', 'D', '0', '0'}};
  if (fp == NULL) {
    printf("could not open input file\n");
    return -1;
  }
  while ((c = fgetc(fp)) != EOF) {
    move(pos, c);
    if (c == 10) {
      printf("%c", keys[pos[0]][pos[1]]);
    }
  }
  printf("\n");
  fclose(fp);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe9a(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xe97(%rip),%rdi
lea    0xe96(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    0xea8(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xea5(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xea2(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xea0(%rip),%al
mov    %al,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d0 <main+0x80>
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1258 <main+0x108>
jmp    11d5 <main+0x85>
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x5(%rbp)
movsbl %al,%eax
mov    0x2dfd(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     123a <main+0xea>
lea    -0x10(%rbp),%rdi
movsbl -0x5(%rbp),%esi
call   1070 <move@plt>
movsbl -0x5(%rbp),%eax
cmp    $0xa,%eax
jne    1235 <main+0xe5>
movslq -0x10(%rbp),%rcx
lea    -0x40(%rbp),%rax
imul   $0x5,%rcx,%rcx
add    %rcx,%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11d5 <main+0x85>
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
movq   $0x2,0x8(%rsp)
lea    0xe84(%rip),%rdi
lea    0xe83(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11ba <main+0x5a>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <fgetc@plt>
mov    0x2e49(%rip),%r15
cmp    (%r15),%al
jne    11d8 <main+0x78>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
jmp    11cb <main+0x6b>
lea    0xe47(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x8(%rsp),%r14
lea    0xe4c(%rip),%r12
jmp    11fd <main+0x9d>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1060 <fgetc@plt>
cmp    (%r15),%al
je     11a4 <main+0x44>
movsbl %al,%ebp
mov    %r14,%rdi
mov    %ebp,%esi
call   1080 <move@plt>
cmp    $0xa,%bpl
jne    11f0 <main+0x90>
movslq 0x8(%rsp),%rax
movslq 0xc(%rsp),%rcx
lea    (%rax,%rax,4),%rax
add    %r12,%rax
movsbl (%rcx,%rax,1),%edi
call   1030 <putchar@plt>
jmp    11f0 <main+0x90>

LLVM IR (-O0):
@__const.main.pos = [2 x i32] [i32 2, i32 0]
@.str = [6 x i8] c"input\00"
@.str.1 = [2 x i8] c"r\00"
@__const.main.keys = [5 x [5 x i8]] [[5 x i8] c"00100", [5 x i8] c"02340", [5 x i8] c"56789", [5 x i8] c"0ABC0", [5 x i8] c"00D00"]
@.str.2 = [27 x i8] c"could not open input file\0A\00"
@EOF = global i8 0
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca [2 x i32]
%4 = alloca i32*
%5 = alloca [5 x [5 x i8]]
store i32 0, i32* %1
%6 = bitcast [2 x i32]* %3 to i8*
%7 = call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %4
%8 = bitcast [5 x [5 x i8]]* %5 to i8*
%9 = load i32*, i32** %4
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %45
13: ; preds = %0
br label %14
14: ; preds = %40, %13
%15 = load i32*, i32** %4
%16 = call signext i8 @fgetc(i32* %15)
store i8 %16, i8* %2
%17 = sext i8 %16 to i32
%18 = load i8, i8* @EOF
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %17, %19
br i1 %20, label %21, label %41
21: ; preds = %14
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%23 = load i8, i8* %2
%24 = call i32 @move(i32* %22, i8 signext %23)
%25 = load i8, i8* %2
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 10
br i1 %27, label %28, label %40
28: ; preds = %21
%29 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%30 = load i32, i32* %29
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [5 x [5 x i8]], [5 x [5 x i8]]* %5, i64 0, i64 %31
%33 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%34 = load i32, i32* %33
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [5 x i8], [5 x i8]* %32, i64 0, i64 %35
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %38)
br label %40
40: ; preds = %28, %21
br label %14
41: ; preds = %14
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%43 = load i32*, i32** %4
%44 = call i32 @fclose(i32* %43)
store i32 0, i32* %1
br label %45
45: ; preds = %41, %11
%46 = load i32, i32* %1
ret i32 %46
}

LLVM IR (-O2):
@.str = [6 x i8] c"input\00"
@.str.1 = [2 x i8] c"r\00"
@__const.main.keys = [5 x [5 x i8]] [[5 x i8] c"00100", [5 x i8] c"02340", [5 x i8] c"56789", [5 x i8] c"0ABC0", [5 x i8] c"00D00"]
@EOF = global i8 0
@str = [26 x i8] c"could not open input file\00"
define i32 @main() {
%1 = alloca i64
%2 = bitcast i64* %1 to [2 x i32]*
%3 = bitcast i64* %1 to i8*
store i64 2, i64* %1
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %13, label %6
6: ; preds = %0
%7 = call signext i8 @fgetc(i32* %4)
%8 = load i8, i8* @EOF
%9 = icmp eq i8 %7, %8
br i1 %9, label %32, label %10
10: ; preds = %6
%11 = bitcast i64* %1 to i32*
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
br label %15
13: ; preds = %0
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %35
15: ; preds = %10, %28
%16 = phi i8 [ %7, %10 ], [ %29, %28 ]
%17 = call i32 @move(i32* %11, i8 signext %16)
%18 = icmp eq i8 %16, 10
br i1 %18, label %19, label %28
19: ; preds = %15
%20 = load i32, i32* %11
%21 = sext i32 %20 to i64
%22 = load i32, i32* %12
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [5 x [5 x i8]], [5 x [5 x i8]]* @__const.main.keys, i64 0, i64 %21, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = call i32 @putchar(i32 %26)
br label %28
28: ; preds = %19, %15
%29 = call signext i8 @fgetc(i32* %4)
%30 = load i8, i8* @EOF
%31 = icmp eq i8 %29, %30
br i1 %31, label %32, label %15
32: ; preds = %28, %6
%33 = call i32 @putchar(i32 10)
%34 = call i32 @fclose(i32* %4)
br label %35
35: ; preds = %32, %13
%36 = phi i32 [ -1, %13 ], [ 0, %32 ]
ret i32 %36
}