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

/* Variables and functions */
scalar_t__ EOF;
int /*<<< orphan*/ ShowUsage();
scalar_t__ char2num(char, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *wrap_fopen(char *, char *);
int main(int argc, char *argv[]) {
  FILE *in_file;
  FILE *out_file;
  char ch;
  char i;
  char data8;
  int count;
  if (argc != 3) {
    ShowUsage();
    exit(-1);
  }
  in_file = wrap_fopen(argv[1], "r");
  out_file = wrap_fopen(argv[2], "wb");
  count = 0;
  data8 = 0;
  i = 0;
  while (fscanf(in_file, "%c", &ch) != EOF) {
    if (char2num(ch, &i) == 0) {
      count++;
      data8 = (data8 * 16) + i;
      if (count == 2) {
        fwrite(&data8, sizeof(data8), 1, out_file);
        count = 0;
        data8 = 0;
      }
    }
  }
  fclose(in_file);
  fclose(out_file);
  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     11a1 <main+0x31>
mov    $0x0,%al
call   1070 <ShowUsage@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe50(%rip),%rsi
call   1050 <wrap_fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe3a(%rip),%rsi
call   1050 <wrap_fopen@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
movb   $0x0,-0x23(%rbp)
movb   $0x0,-0x22(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe1a(%rip),%rsi
lea    -0x21(%rbp),%rdx
call   1060 <fscanf@plt>
mov    0x2ded(%rip),%rcx
cmp    (%rcx),%rax
je     1267 <main+0xf7>
lea    -0x22(%rbp),%rsi
movsbl -0x21(%rbp),%edi
call   1040 <char2num@plt>
cmp    $0x0,%rax
jne    1262 <main+0xf2>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
movsbl -0x23(%rbp),%eax
shl    $0x4,%eax
movsbl -0x22(%rbp),%ecx
add    %ecx,%eax
mov    %al,-0x23(%rbp)
cmpl   $0x2,-0x28(%rbp)
jne    125d <main+0xed>
mov    -0x20(%rbp),%rcx
lea    -0x23(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1090 <fwrite@plt>
movl   $0x0,-0x28(%rbp)
movb   $0x0,-0x23(%rbp)
jmp    1262 <main+0xf2>
jmp    11e0 <main+0x70>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%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   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x3,%edi
jne    1274 <main+0x104>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
lea    0xe6b(%rip),%rsi
call   1050 <wrap_fopen@plt>
mov    %rax,%rbx
mov    0x10(%r14),%rdi
lea    0xe5a(%rip),%rsi
call   1050 <wrap_fopen@plt>
mov    %rax,0x10(%rsp)
movb   $0x0,0xe(%rsp)
lea    0xe47(%rip),%rsi
lea    0xf(%rsp),%rdx
mov    %rbx,%rdi
call   1060 <fscanf@plt>
mov    0x2e16(%rip),%rcx
cmp    (%rcx),%rax
jne    11fa <main+0x8a>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x10(%rsp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebp,%ebp
lea    0xe(%rsp),%r15
lea    0xdfd(%rip),%r12
lea    0xf(%rsp),%r13
xor    %r14d,%r14d
jmp    123f <main+0xcf>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x1,%ebp
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1060 <fscanf@plt>
mov    0x2dae(%rip),%rcx
cmp    (%rcx),%rax
je     11d7 <main+0x67>
movsbl 0xf(%rsp),%edi
mov    %r15,%rsi
call   1040 <char2num@plt>
test   %rax,%rax
jne    1225 <main+0xb5>
shl    $0x4,%r14b
add    0xe(%rsp),%r14b
cmp    $0x1,%ebp
jne    1220 <main+0xb0>
movsbl %r14b,%edi
mov    0x10(%rsp),%rsi
call   1070 <fputc@plt>
xor    %r14d,%r14d
xor    %ebp,%ebp
jmp    1225 <main+0xb5>
xor    %eax,%eax
call   1080 <ShowUsage@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [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
%10 = alloca i8
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 3
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = call i32 (...) @ShowUsage()
%16 = call i32 @exit(i32 -1)
unreachable
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32* @wrap_fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %21, i32** %6
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
%25 = call i32* @wrap_fopen(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %25, i32** %7
store i32 0, i32* %11
store i8 0, i8* %10
store i8 0, i8* %9
br label %26
26: ; preds = %51, %17
%27 = load i32*, i32** %6
%28 = call i64 @fscanf(i32* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%29 = load i64, i64* @EOF
%30 = icmp ne i64 %28, %29
br i1 %30, label %31, label %52
31: ; preds = %26
%32 = load i8, i8* %8
%33 = call i64 @char2num(i8 signext %32, i8* %9)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %51
35: ; preds = %31
%36 = load i32, i32* %11
%37 = add nsw i32 %36, 1
store i32 %37, i32* %11
%38 = load i8, i8* %10
%39 = sext i8 %38 to i32
%40 = mul nsw i32 %39, 16
%41 = load i8, i8* %9
%42 = sext i8 %41 to i32
%43 = add nsw i32 %40, %42
%44 = trunc i32 %43 to i8
store i8 %44, i8* %10
%45 = load i32, i32* %11
%46 = icmp eq i32 %45, 2
br i1 %46, label %47, label %50
47: ; preds = %35
%48 = load i32*, i32** %7
%49 = call i32 @fwrite(i8* %10, i32 1, i32 1, i32* %48)
store i32 0, i32* %11
store i8 0, i8* %10
br label %50
50: ; preds = %47, %35
br label %51
51: ; preds = %50, %31
br label %26
52: ; preds = %26
%53 = load i32*, i32** %6
%54 = call i32 @fclose(i32* %53)
%55 = load i32*, i32** %7
%56 = call i32 @fclose(i32* %55)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [3 x i8] c"%c\00"
@EOF = global i64 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = alloca i8
%5 = icmp eq i32 %0, 3
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = tail call i32 (...) @ShowUsage()
%8 = tail call i32 @exit(i32 -1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32* @wrap_fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = tail call i32* @wrap_fopen(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i8 0, i8* %4
%16 = call i64 @fscanf(i32* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%17 = load i64, i64* @EOF
%18 = icmp eq i64 %16, %17
br i1 %18, label %39, label %19
19: ; preds = %9, %33
%20 = phi i32 [ %35, %33 ], [ 0, %9 ]
%21 = phi i8 [ %34, %33 ], [ 0, %9 ]
%22 = load i8, i8* %3
%23 = call i64 @char2num(i8 signext %22, i8* %4)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %33
25: ; preds = %19
%26 = shl i8 %21, 4
%27 = load i8, i8* %4
%28 = add i8 %27, %26
%29 = icmp eq i32 %20, 1
br i1 %29, label %30, label %33
30: ; preds = %25
%31 = sext i8 %28 to i32
%32 = call i32 @fputc(i32 %31, i32* %15)
br label %33
33: ; preds = %25, %30, %19
%34 = phi i8 [ 0, %30 ], [ %28, %25 ], [ %21, %19 ]
%35 = phi i32 [ 0, %30 ], [ 1, %25 ], [ %20, %19 ]
%36 = call i64 @fscanf(i32* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%37 = load i64, i64* @EOF
%38 = icmp eq i64 %36, %37
br i1 %38, label %39, label %19
39: ; preds = %33, %9
%40 = call i32 @fclose(i32* %12)
%41 = call i32 @fclose(i32* %15)
ret i32 0
}