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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, unsigned int *);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ *stdout;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ usage(char *);
int main(int argc, char **argv) {
  unsigned char byte;
  unsigned temp;
  int count;
  FILE *infp = stdin;
  FILE *outfp = stdout;
  if (argc == 1) {
    ;
  } else if (argc == 3) {
    if (strcmp(argv[1], "-") != 0)
      infp = fopen(argv[1], "r");
    if (strcmp(argv[2], "-") != 0)
      outfp = fopen(argv[2], "w");
  } else {
    usage(argv[0]);
  }
  if (infp == NULL) {
    fprintf(stderr, "Couldn't open input file \"%s\"; aborting.\n", argv[1]);
    exit(1);
  }
  if (outfp == NULL) {
    fprintf(stderr, "Couldn't open output file \"%s\"; aborting.\n", argv[2]);
    exit(1);
  }
  while ((count = fscanf(infp, "%x", &temp)) > 0) {
    byte = temp;
    fwrite(&byte, sizeof(byte), 1, outfp);
  }
  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    0x2e5b(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e35(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11b1 <main+0x41>
jmp    123d <main+0xcd>
cmpl   $0x3,-0x8(%rbp)
jne    122c <main+0xbc>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe36(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     11f1 <main+0x81>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe1a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe00(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     1227 <main+0xb7>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xde6(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x30(%rbp)
jmp    1238 <main+0xc8>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <usage@plt>
jmp    123d <main+0xcd>
cmpq   $0x0,-0x28(%rbp)
jne    126f <main+0xff>
mov    0x2d89(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xda6(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
cmpq   $0x0,-0x30(%rbp)
jne    12a1 <main+0x131>
mov    0x2d57(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xd9e(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    12a6 <main+0x136>
mov    -0x28(%rbp),%rdi
lea    0xdaa(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1030 <fscanf@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jle    12e5 <main+0x175>
mov    -0x18(%rbp),%eax
mov    %al,-0x11(%rbp)
mov    -0x30(%rbp),%rcx
lea    -0x11(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1090 <fwrite@plt>
jmp    12a6 <main+0x136>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    0x2e66(%rip),%rax
mov    (%rax),%r12
mov    0x2e44(%rip),%rax
mov    (%rax),%r14
cmp    $0x1,%edi
je     11f3 <main+0x83>
cmp    $0x3,%edi
jne    11eb <main+0x7b>
mov    0x8(%r15),%rdi
lea    0xe5c(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11c1 <main+0x51>
mov    0x8(%r15),%rdi
lea    0xe49(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r12
mov    0x10(%r15),%rdi
lea    0xe34(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11f3 <main+0x83>
mov    0x10(%r15),%rdi
lea    0xe23(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r14
jmp    11f3 <main+0x83>
mov    (%r15),%rdi
call   1070 <usage@plt>
test   %r12,%r12
je     125d <main+0xed>
test   %r14,%r14
je     1273 <main+0x103>
lea    0xe57(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %r12,%rdi
call   1030 <fscanf@plt>
test   %eax,%eax
jle    124f <main+0xdf>
lea    0xe3f(%rip),%r15
lea    0x4(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl 0x4(%rsp),%edi
mov    %r14,%rsi
call   1040 <fputc@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1030 <fscanf@plt>
test   %eax,%eax
jg     1230 <main+0xc0>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2d74(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r15),%rdx
lea    0xd95(%rip),%rsi
jmp    1287 <main+0x117>
mov    0x2d5e(%rip),%rax
mov    (%rax),%edi
mov    0x10(%r15),%rdx
lea    0xda9(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stdin = global i32* null
@stdout = global i32* null
@.str = [2 x i8] c"-\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.3 = [42 x i8] c"Couldn't open input file \22%s\22; aborting.\0A\00"
@.str.4 = [43 x i8] c"Couldn't open output file \22%s\22; aborting.\0A\00"
@.str.5 = [3 x i8] c"%x\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32*, i32** @stdin
store i32* %11, i32** %9
%12 = load i32*, i32** @stdout
store i32* %12, i32** %10
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %16
15: ; preds = %2
br label %48
16: ; preds = %2
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, 3
br i1 %18, label %19, label %42
19: ; preds = %16
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %19
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %29, i32** %9
br label %30
30: ; preds = %25, %19
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = call i64 @strcmp(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %41
36: ; preds = %30
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 2
%39 = load i8*, i8** %38
%40 = call i32* @fopen(i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %40, i32** %10
br label %41
41: ; preds = %36, %30
br label %47
42: ; preds = %16
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 0
%45 = load i8*, i8** %44
%46 = call i32 @usage(i8* %45)
br label %47
47: ; preds = %42, %41
br label %48
48: ; preds = %47, %15
%49 = load i32*, i32** %9
%50 = icmp eq i32* %49, null
br i1 %50, label %51, label %58
51: ; preds = %48
%52 = load i32, i32* @stderr
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i64 1
%55 = load i8*, i8** %54
%56 = call i32 @fprintf(i32 %52, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i8* %55)
%57 = call i32 @exit(i32 1)
unreachable
58: ; preds = %48
%59 = load i32*, i32** %10
%60 = icmp eq i32* %59, null
br i1 %60, label %61, label %68
61: ; preds = %58
%62 = load i32, i32* @stderr
%63 = load i8**, i8*** %5
%64 = getelementptr inbounds i8*, i8** %63, i64 2
%65 = load i8*, i8** %64
%66 = call i32 @fprintf(i32 %62, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i8* %65)
%67 = call i32 @exit(i32 1)
unreachable
68: ; preds = %58
br label %69
69: ; preds = %73, %68
%70 = load i32*, i32** %9
%71 = call i32 @fscanf(i32* %70, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %7)
store i32 %71, i32* %8
%72 = icmp sgt i32 %71, 0
br i1 %72, label %73, label %78
73: ; preds = %69
%74 = load i32, i32* %7
%75 = trunc i32 %74 to i8
store i8 %75, i8* %6
%76 = load i32*, i32** %10
%77 = call i32 @fwrite(i8* %6, i32 1, i32 1, i32* %76)
br label %69
78: ; preds = %69
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32* null
@stdout = global i32* null
@.str = [2 x i8] c"-\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.3 = [42 x i8] c"Couldn't open input file \22%s\22; aborting.\0A\00"
@.str.4 = [43 x i8] c"Couldn't open output file \22%s\22; aborting.\0A\00"
@.str.5 = [3 x i8] c"%x\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = load i32*, i32** @stdin
%6 = load i32*, i32** @stdout
switch i32 %0, label %24 [
i32 1, label %27
i32 3, label %7
]
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %7
%13 = load i8*, i8** %8
%14 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %12, %7
%16 = phi i32* [ %14, %12 ], [ %5, %7 ]
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = tail call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %27, label %21
21: ; preds = %15
%22 = load i8*, i8** %17
%23 = tail call i32* @fopen(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %27
24: ; preds = %2
%25 = load i8*, i8** %1
%26 = tail call i32 @usage(i8* %25)
br label %27
27: ; preds = %2, %24, %21, %15
%28 = phi i32* [ %5, %2 ], [ %16, %21 ], [ %16, %15 ], [ %5, %24 ]
%29 = phi i32* [ %6, %2 ], [ %23, %21 ], [ %6, %15 ], [ %6, %24 ]
%30 = icmp eq i32* %28, null
br i1 %30, label %31, label %37
31: ; preds = %27
%32 = load i32, i32* @stderr
%33 = getelementptr inbounds i8*, i8** %1, i64 1
%34 = load i8*, i8** %33
%35 = tail call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i8* %34)
%36 = tail call i32 @exit(i32 1)
unreachable
37: ; preds = %27
%38 = icmp eq i32* %29, null
br i1 %38, label %42, label %39
39: ; preds = %37
%40 = call i32 @fscanf(i32* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %3)
%41 = icmp sgt i32 %40, 0
br i1 %41, label %48, label %55
42: ; preds = %37
%43 = load i32, i32* @stderr
%44 = getelementptr inbounds i8*, i8** %1, i64 2
%45 = load i8*, i8** %44
%46 = tail call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i8* %45)
%47 = tail call i32 @exit(i32 1)
unreachable
48: ; preds = %39, %48
%49 = load i32, i32* %3
%50 = shl i32 %49, 24
%51 = ashr exact i32 %50, 24
%52 = call i32 @fputc(i32 %51, i32* %29)
%53 = call i32 @fscanf(i32* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %3)
%54 = icmp sgt i32 %53, 0
br i1 %54, label %48, label %55
55: ; preds = %48, %39
ret i32 0
}