#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 */
scalar_t__ EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ printf(char *);
int main(int argc, char *argv[]) {
  FILE *fpIn;
  FILE *fpOut;
  char c1, c2;
  if (argc != 3) {
    printf("Usage: hex2ascii <infile> <outfile>\n");
    return 1;
  }
  fpIn = fopen(argv[1], "r");
  fpOut = fopen(argv[2], "w");
  while (1) {
    if (fscanf(fpIn, "%c", &c1) == EOF)
      break;
    fscanf(fpIn, "%c", &c2);
    if ((c1 >= 48) && (c1 <= 57))
      c1 -= 48;
    if ((c2 >= 48) && (c2 <= 57))
      c2 -= 48;
    if ((c1 >= 65) && (c1 <= 70))
      c1 -= 55;
    if ((c2 >= 65) && (c2 <= 70))
      c2 -= 55;
    fprintf(fpOut, "%c", 16 * c1 + c2);
  }
  fclose(fpIn);
  fclose(fpOut);
  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)
cmpl   $0x3,-0x8(%rbp)
je     1188 <main+0x38>
lea    0xe89(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c0 <main+0x170>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe8e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe78(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe66(%rip),%rsi
lea    -0x21(%rbp),%rdx
call   1050 <fscanf@plt>
mov    0x2e15(%rip),%rcx
cmp    (%rcx),%rax
jne    11e1 <main+0x91>
jmp    12a7 <main+0x157>
mov    -0x18(%rbp),%rdi
lea    0xe3d(%rip),%rsi
lea    -0x22(%rbp),%rdx
call   1050 <fscanf@plt>
movsbl -0x21(%rbp),%eax
cmp    $0x30,%eax
jl     1219 <main+0xc9>
movsbl -0x21(%rbp),%eax
cmp    $0x39,%eax
jg     1219 <main+0xc9>
movsbl -0x21(%rbp),%eax
sub    $0x30,%eax
mov    %al,-0x21(%rbp)
movsbl -0x22(%rbp),%eax
cmp    $0x30,%eax
jl     123d <main+0xed>
movsbl -0x22(%rbp),%eax
cmp    $0x39,%eax
jg     123d <main+0xed>
movsbl -0x22(%rbp),%eax
sub    $0x30,%eax
mov    %al,-0x22(%rbp)
movsbl -0x21(%rbp),%eax
cmp    $0x41,%eax
jl     1261 <main+0x111>
movsbl -0x21(%rbp),%eax
cmp    $0x46,%eax
jg     1261 <main+0x111>
movsbl -0x21(%rbp),%eax
sub    $0x37,%eax
mov    %al,-0x21(%rbp)
movsbl -0x22(%rbp),%eax
cmp    $0x41,%eax
jl     1285 <main+0x135>
movsbl -0x22(%rbp),%eax
cmp    $0x46,%eax
jg     1285 <main+0x135>
movsbl -0x22(%rbp),%eax
sub    $0x37,%eax
mov    %al,-0x22(%rbp)
mov    -0x20(%rbp),%rdi
movsbl -0x21(%rbp),%edx
shl    $0x4,%edx
movsbl -0x22(%rbp),%eax
add    %eax,%edx
lea    0xd8c(%rip),%rsi
call   1060 <fprintf@plt>
jmp    11b8 <main+0x68>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x3,%edi
jne    11be <main+0x6e>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
lea    0xe92(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    0x10(%r14),%rdi
lea    0xe81(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r14
lea    0xe74(%rip),%rsi
lea    0x6(%rsp),%rdx
mov    %rbx,%rdi
call   1050 <fscanf@plt>
mov    0x2e44(%rip),%rbp
cmp    0x0(%rbp),%rax
jne    11de <main+0x8e>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    11cf <main+0x7f>
lea    0xe42(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe1f(%rip),%r15
lea    0x7(%rsp),%r12
lea    0x6(%rsp),%r13
jmp    1227 <main+0xd7>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl %al,%eax
shl    $0x4,%eax
movsbl %cl,%edi
add    %eax,%edi
mov    %r14,%rsi
call   1060 <fputc@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   1050 <fscanf@plt>
cmp    0x0(%rbp),%rax
je     11aa <main+0x5a>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1050 <fscanf@plt>
movzbl 0x6(%rsp),%eax
lea    -0x30(%rax),%ecx
cmp    $0x9,%cl
ja     1248 <main+0xf8>
mov    %cl,0x6(%rsp)
mov    %ecx,%eax
movzbl 0x7(%rsp),%ecx
lea    -0x30(%rcx),%edx
cmp    $0x9,%dl
ja     125b <main+0x10b>
mov    %dl,0x7(%rsp)
mov    %edx,%ecx
lea    -0x41(%rax),%edx
cmp    $0x5,%dl
ja     1269 <main+0x119>
add    $0xc9,%al
mov    %al,0x6(%rsp)
lea    -0x41(%rcx),%edx
cmp    $0x5,%dl
ja     1200 <main+0xb0>
add    $0xc9,%cl
mov    %cl,0x7(%rsp)
jmp    1200 <main+0xb0>

LLVM IR (-O0):
@.str = [37 x i8] c"Usage: hex2ascii <infile> <outfile>\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [3 x i8] c"%c\00"
@EOF = global i64 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8
%9 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 3
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %97
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %6
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %22, i32** %7
br label %23
23: ; preds = %14, %83
%24 = load i32*, i32** %6
%25 = call i64 @fscanf(i32* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %8)
%26 = load i64, i64* @EOF
%27 = icmp eq i64 %25, %26
br i1 %27, label %28, label %29
28: ; preds = %23
br label %92
29: ; preds = %23
%30 = load i32*, i32** %6
%31 = call i64 @fscanf(i32* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %9)
%32 = load i8, i8* %8
%33 = sext i8 %32 to i32
%34 = icmp sge i32 %33, 48
br i1 %34, label %35, label %44
35: ; preds = %29
%36 = load i8, i8* %8
%37 = sext i8 %36 to i32
%38 = icmp sle i32 %37, 57
br i1 %38, label %39, label %44
39: ; preds = %35
%40 = load i8, i8* %8
%41 = sext i8 %40 to i32
%42 = sub nsw i32 %41, 48
%43 = trunc i32 %42 to i8
store i8 %43, i8* %8
br label %44
44: ; preds = %39, %35, %29
%45 = load i8, i8* %9
%46 = sext i8 %45 to i32
%47 = icmp sge i32 %46, 48
br i1 %47, label %48, label %57
48: ; preds = %44
%49 = load i8, i8* %9
%50 = sext i8 %49 to i32
%51 = icmp sle i32 %50, 57
br i1 %51, label %52, label %57
52: ; preds = %48
%53 = load i8, i8* %9
%54 = sext i8 %53 to i32
%55 = sub nsw i32 %54, 48
%56 = trunc i32 %55 to i8
store i8 %56, i8* %9
br label %57
57: ; preds = %52, %48, %44
%58 = load i8, i8* %8
%59 = sext i8 %58 to i32
%60 = icmp sge i32 %59, 65
br i1 %60, label %61, label %70
61: ; preds = %57
%62 = load i8, i8* %8
%63 = sext i8 %62 to i32
%64 = icmp sle i32 %63, 70
br i1 %64, label %65, label %70
65: ; preds = %61
%66 = load i8, i8* %8
%67 = sext i8 %66 to i32
%68 = sub nsw i32 %67, 55
%69 = trunc i32 %68 to i8
store i8 %69, i8* %8
br label %70
70: ; preds = %65, %61, %57
%71 = load i8, i8* %9
%72 = sext i8 %71 to i32
%73 = icmp sge i32 %72, 65
br i1 %73, label %74, label %83
74: ; preds = %70
%75 = load i8, i8* %9
%76 = sext i8 %75 to i32
%77 = icmp sle i32 %76, 70
br i1 %77, label %78, label %83
78: ; preds = %74
%79 = load i8, i8* %9
%80 = sext i8 %79 to i32
%81 = sub nsw i32 %80, 55
%82 = trunc i32 %81 to i8
store i8 %82, i8* %9
br label %83
83: ; preds = %78, %74, %70
%84 = load i32*, i32** %7
%85 = load i8, i8* %8
%86 = sext i8 %85 to i32
%87 = mul nsw i32 16, %86
%88 = load i8, i8* %9
%89 = sext i8 %88 to i32
%90 = add nsw i32 %87, %89
%91 = call i32 @fprintf(i32* %84, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %90)
br label %23
92: ; preds = %28
%93 = load i32*, i32** %6
%94 = call i32 @fclose(i32* %93)
%95 = load i32*, i32** %7
%96 = call i32 @fclose(i32* %95)
store i32 0, i32* %3
br label %97
97: ; preds = %92, %12
%98 = load i32, i32* %3
ret i32 %98
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [3 x i8] c"%c\00"
@EOF = global i64 0
@str = [36 x i8] c"Usage: hex2ascii <infile> <outfile>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = alloca i8
%5 = icmp eq i32 %0, 3
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
br label %55
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%15 = call i64 @fscanf(i32* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %3)
%16 = load i64, i64* @EOF
%17 = icmp eq i64 %15, %16
br i1 %17, label %52, label %18
18: ; preds = %8, %42
%19 = call i64 @fscanf(i32* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%20 = load i8, i8* %3
%21 = add i8 %20, -48
%22 = icmp ult i8 %21, 10
br i1 %22, label %23, label %24
23: ; preds = %18
store i8 %21, i8* %3
br label %24
24: ; preds = %23, %18
%25 = phi i8 [ %21, %23 ], [ %20, %18 ]
%26 = load i8, i8* %4
%27 = add i8 %26, -48
%28 = icmp ult i8 %27, 10
br i1 %28, label %29, label %30
29: ; preds = %24
store i8 %27, i8* %4
br label %30
30: ; preds = %29, %24
%31 = phi i8 [ %27, %29 ], [ %26, %24 ]
%32 = add i8 %25, -65
%33 = icmp ult i8 %32, 6
br i1 %33, label %34, label %36
34: ; preds = %30
%35 = add nsw i8 %25, -55
store i8 %35, i8* %3
br label %36
36: ; preds = %34, %30
%37 = phi i8 [ %35, %34 ], [ %25, %30 ]
%38 = add i8 %31, -65
%39 = icmp ult i8 %38, 6
br i1 %39, label %40, label %42
40: ; preds = %36
%41 = add nsw i8 %31, -55
store i8 %41, i8* %4
br label %42
42: ; preds = %40, %36
%43 = phi i8 [ %41, %40 ], [ %31, %36 ]
%44 = sext i8 %37 to i32
%45 = shl nsw i32 %44, 4
%46 = sext i8 %43 to i32
%47 = add nsw i32 %45, %46
%48 = call i32 @fputc(i32 %47, i32* %14)
%49 = call i64 @fscanf(i32* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %3)
%50 = load i64, i64* @EOF
%51 = icmp eq i64 %49, %50
br i1 %51, label %52, label %18
52: ; preds = %42, %8
%53 = call i32 @fclose(i32* %11)
%54 = call i32 @fclose(i32* %14)
br label %55
55: ; preds = %52, %6
%56 = phi i32 [ 1, %6 ], [ 0, %52 ]
ret i32 %56
}