#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 */
unsigned int EOF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
unsigned int get_hex(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, unsigned int);
int /*<<< orphan*/ sscanf(char *, char *, unsigned int *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  FILE *input_file;
  unsigned int hex;
  unsigned int c;
  char data_string[2];
  char *filename = argv[1];
  if (!(input_file = fopen(filename, "r"))) {
    fprintf(stderr, "Usage: ascii2bin <filename>\nConvert hex code into "
                    "binary. Pierre Dejoue 2001.\n");
    exit(1);
  }
  while (1) {
    if ((hex = get_hex(input_file)) == EOF)
      break;
    data_string[0] = hex;
    if ((hex = get_hex(input_file)) == EOF)
      break;
    data_string[1] = hex;
    sscanf(data_string, "%02x", &c);
    printf("%c", c);
  }
  fclose(input_file);
  exit(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),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xe63(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11cf <main+0x5f>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
lea    0xe42(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    11d4 <main+0x64>
mov    -0x18(%rbp),%rdi
call   1060 <get_hex@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e01(%rip),%rcx
cmp    (%rcx),%eax
jne    11f4 <main+0x84>
jmp    1248 <main+0xd8>
mov    -0x1c(%rbp),%eax
mov    %al,-0x22(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <get_hex@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2ddb(%rip),%rcx
cmp    (%rcx),%eax
jne    121a <main+0xaa>
jmp    1248 <main+0xd8>
mov    -0x1c(%rbp),%eax
mov    %al,-0x21(%rbp)
lea    -0x22(%rbp),%rdi
lea    0xe26(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1070 <sscanf@plt>
mov    -0x20(%rbp),%esi
lea    0xe18(%rip),%rdi
call   1040 <printf@plt>
jmp    11d4 <main+0x64>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x8(%rsi),%rdi
lea    0xe7a(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
jne    11af <main+0x3f>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
lea    0xe62(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <get_hex@plt>
mov    0x2e27(%rip),%rbp
cmp    0x0(%rbp),%eax
je     121c <main+0xac>
lea    0xe84(%rip),%r14
lea    0x2(%rsp),%r15
lea    0x4(%rsp),%r12
lea    0xe78(%rip),%r13
xchg   %ax,%ax
mov    %al,0x2(%rsp)
mov    %rbx,%rdi
call   1060 <get_hex@plt>
cmp    0x0(%rbp),%eax
je     121c <main+0xac>
mov    %al,0x3(%rsp)
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1070 <sscanf@plt>
mov    0x4(%rsp),%esi
mov    %r13,%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1060 <get_hex@plt>
cmp    0x0(%rbp),%eax
jne    11e0 <main+0x70>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [79 x i8] c"Usage: ascii2bin <filename>\0AConvert hex code into binary. Pierre Dejoue 2001.\0A\00"
@EOF = global i32 0
@.str.2 = [5 x i8] c"%02x\00"
@.str.3 = [3 x i8] c"%c\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [2 x i8]
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
store i8* %13, i8** %10
%14 = load i8*, i8** %10
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %6
%16 = icmp ne i32* %15, null
br i1 %16, label %21, label %17
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
br label %22
22: ; preds = %21, %37
%23 = load i32*, i32** %6
%24 = call i32 @get_hex(i32* %23)
store i32 %24, i32* %7
%25 = load i32, i32* @EOF
%26 = icmp eq i32 %24, %25
br i1 %26, label %27, label %28
27: ; preds = %22
br label %45
28: ; preds = %22
%29 = load i32, i32* %7
%30 = trunc i32 %29 to i8
%31 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 0
store i8 %30, i8* %31
%32 = load i32*, i32** %6
%33 = call i32 @get_hex(i32* %32)
store i32 %33, i32* %7
%34 = load i32, i32* @EOF
%35 = icmp eq i32 %33, %34
br i1 %35, label %36, label %37
36: ; preds = %28
br label %45
37: ; preds = %28
%38 = load i32, i32* %7
%39 = trunc i32 %38 to i8
%40 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 1
store i8 %39, i8* %40
%41 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 0
%42 = call i32 @sscanf(i8* %41, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32* %8)
%43 = load i32, i32* %8
%44 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %43)
br label %22
45: ; preds = %36, %27
%46 = load i32*, i32** %6
%47 = call i32 @fclose(i32* %46)
%48 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [79 x i8] c"Usage: ascii2bin <filename>\0AConvert hex code into binary. Pierre Dejoue 2001.\0A\00"
@EOF = global i32 0
@.str.2 = [5 x i8] c"%02x\00"
@.str.3 = [3 x i8] c"%c\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [2 x i8]
%5 = bitcast i32* %3 to i8*
%6 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %17, label %11
11: ; preds = %2
%12 = call i32 @get_hex(i32* %9)
%13 = load i32, i32* @EOF
%14 = icmp eq i32 %12, %13
br i1 %14, label %35, label %15
15: ; preds = %11
%16 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 1
br label %21
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str.1, i64 0, i64 0))
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %15, %27
%22 = phi i32 [ %12, %15 ], [ %32, %27 ]
%23 = trunc i32 %22 to i8
store i8 %23, i8* %6
%24 = call i32 @get_hex(i32* %9)
%25 = load i32, i32* @EOF
%26 = icmp eq i32 %24, %25
br i1 %26, label %35, label %27
27: ; preds = %21
%28 = trunc i32 %24 to i8
store i8 %28, i8* %16
%29 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%30 = load i32, i32* %3
%31 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %30)
%32 = call i32 @get_hex(i32* %9)
%33 = load i32, i32* @EOF
%34 = icmp eq i32 %32, %33
br i1 %34, label %35, label %21
35: ; preds = %27, %21, %11
%36 = call i32 @fclose(i32* %9)
%37 = call i32 @exit(i32 0)
unreachable
}