#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int getVal(char);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, int, int);
int main(int argc, char *argv[]) {
  FILE *fp;
  fp = fopen(argv[1], "r");
  if (fp == NULL) {
    perror("Error while opening the file.\n");
    exit(EXIT_FAILURE);
  }
  char c;
  int i = 0;
  while ((c = fgetc(fp)) != EOF) {
    int val = getVal(c) * 16 + getVal(fgetc(fp));
    printf("%3d - %c [%d]\n", i, val, val);
    i++;
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe6b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c3 <main+0x53>
lea    0xe52(%rip),%rdi
call   1080 <perror@plt>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x19(%rbp)
movsbl %al,%eax
mov    0x2e08(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1238 <main+0xc8>
movsbl -0x19(%rbp),%edi
call   1060 <getVal@plt>
shl    $0x4,%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
movsbl %al,%edi
call   1060 <getVal@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    -0x24(%rbp),%ecx
lea    0xdfc(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11ca <main+0x5a>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    0x8(%rsi),%rdi
lea    0xe7d(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1201 <main+0x91>
mov    %rax,%r15
mov    %rax,%rdi
call   1050 <fgetc@plt>
mov    0x2e49(%rip),%r12
cmp    (%r12),%al
je     11ee <main+0x7e>
xor    %ebp,%ebp
lea    0xe73(%rip),%r14
xchg   %ax,%ax
movsbl %al,%edi
call   1060 <getVal@plt>
mov    %eax,%ebx
shl    $0x4,%ebx
mov    %r15,%rdi
call   1050 <fgetc@plt>
movsbl %al,%edi
call   1060 <getVal@plt>
add    %eax,%ebx
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %ebx,%ecx
call   1040 <printf@plt>
add    $0x1,%ebp
mov    %r15,%rdi
call   1050 <fgetc@plt>
cmp    (%r12),%al
jne    11b0 <main+0x40>
mov    %r15,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdfa(%rip),%rdi
call   1080 <perror@plt>
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [31 x i8] c"Error while opening the file.\0A\00"
@EXIT_FAILURE = global i32 0
@EOF = global i8 0
@.str.2 = [15 x i8] c"%3d - %c [%d]\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %6
%14 = load i32*, i32** %6
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %2
store i32 0, i32* %8
br label %21
21: ; preds = %28, %20
%22 = load i32*, i32** %6
%23 = call signext i8 @fgetc(i32* %22)
store i8 %23, i8* %7
%24 = sext i8 %23 to i32
%25 = load i8, i8* @EOF
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %24, %26
br i1 %27, label %28, label %42
28: ; preds = %21
%29 = load i8, i8* %7
%30 = call i32 @getVal(i8 signext %29)
%31 = mul nsw i32 %30, 16
%32 = load i32*, i32** %6
%33 = call signext i8 @fgetc(i32* %32)
%34 = call i32 @getVal(i8 signext %33)
%35 = add nsw i32 %31, %34
store i32 %35, i32* %9
%36 = load i32, i32* %8
%37 = load i32, i32* %9
%38 = load i32, i32* %9
%39 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %36, i32 %37, i32 %38)
%40 = load i32, i32* %8
%41 = add nsw i32 %40, 1
store i32 %41, i32* %8
br label %21
42: ; preds = %21
%43 = load i32*, i32** %6
%44 = call i32 @fclose(i32* %43)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [31 x i8] c"Error while opening the file.\0A\00"
@EXIT_FAILURE = global i32 0
@EOF = global i8 0
@.str.2 = [15 x i8] c"%3d - %c [%d]\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = tail call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %11, label %7
7: ; preds = %2
%8 = tail call signext i8 @fgetc(i32* %5)
%9 = load i8, i8* @EOF
%10 = icmp eq i8 %8, %9
br i1 %10, label %28, label %15
11: ; preds = %2
%12 = tail call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %7, %15
%16 = phi i8 [ %25, %15 ], [ %8, %7 ]
%17 = phi i32 [ %24, %15 ], [ 0, %7 ]
%18 = tail call i32 @getVal(i8 signext %16)
%19 = shl nsw i32 %18, 4
%20 = tail call signext i8 @fgetc(i32* %5)
%21 = tail call i32 @getVal(i8 signext %20)
%22 = add nsw i32 %21, %19
%23 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %17, i32 %22, i32 %22)
%24 = add nuw nsw i32 %17, 1
%25 = tail call signext i8 @fgetc(i32* %5)
%26 = load i8, i8* @EOF
%27 = icmp eq i8 %25, %26
br i1 %27, label %28, label %15
28: ; preds = %15, %7
%29 = tail call i32 @fclose(i32* %5)
ret i32 0
}