#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 */

/* Variables and functions */
int /*<<< orphan*/ abort();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ isprint(unsigned char);
scalar_t__ isxdigit(unsigned char);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(unsigned char);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
unsigned char unhex(unsigned char, unsigned char);
int main(int argc, char *argv[]) {
  int i;
  unsigned char *s;
  unsigned char c;
  unsigned char d;
  int raw = 0;
  for (i = 1; i < argc; i++) {
    s = (unsigned char *)argv[i];
    if (s[0] == '-') {
      if (s[1] == 'r') {
        raw = 1;
      }
      if ((s[1] == 'h') || (s[1] == '?')) {
        fprintf(stderr, "hexecho -r 01 02 03: produces raw binary output of "
                        "hex bytes 01 02 03\n");
        fprintf(stderr, "hexecho 01 02 03: produces human readable binary "
                        "output of hex bytes like '\\x01\\x02\\x03'\n");
        exit(0);
      }
      if (s[1] == 'v') {
        fprintf(stderr, "hexecho version 1.1. Copyright 2011 Andreas Fink "
                        "(andreas@fink.org). Source on "
                        "https://github.com/andreasfink/hexecho.git\n");
        exit(0);
      }
      continue;
    }
    while (*s) {
      if (isxdigit(*s)) {
        c = *s++;
        d = *s++;
        if (d == '\0') {
          fprintf(stderr,
                  "expected a hex pair but only got a single hex number\n");
          abort();
        }
        c = unhex(c, d);
        if (raw) {
          putchar(c);
        } else {
          if (isprint(c)) {
            putchar(c);
          } else {
            printf("\\x%02X", c);
          }
        }
      } else
        s++;
    }
  }
  if (raw == 0) {
    printf("\n");
  }
  fflush(stdout);
}


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)
movl   $0x0,-0x28(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1381 <main+0x1f1>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x2d,%eax
jne    127d <main+0xed>
mov    -0x20(%rbp),%rax
movzbl 0x1(%rax),%eax
cmp    $0x72,%eax
jne    11f8 <main+0x68>
movl   $0x1,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movzbl 0x1(%rax),%eax
cmp    $0x68,%eax
je     121a <main+0x8a>
mov    -0x20(%rbp),%rax
movzbl 0x1(%rax),%eax
cmp    $0x3f,%eax
jne    124b <main+0xbb>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
lea    0xdd6(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
lea    0xe08(%rip),%rsi
call   1060 <fprintf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    -0x20(%rbp),%rax
movzbl 0x1(%rax),%eax
cmp    $0x76,%eax
jne    1278 <main+0xe8>
mov    0x2d7d(%rip),%rax
mov    (%rax),%edi
lea    0xe35(%rip),%rsi
call   1060 <fprintf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
jmp    1373 <main+0x1e3>
jmp    1282 <main+0xf2>
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     136e <main+0x1de>
mov    -0x20(%rbp),%rax
movzbl (%rax),%edi
call   10b0 <isxdigit@plt>
cmp    $0x0,%rax
je     135d <main+0x1cd>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%al
mov    %al,-0x21(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%al
mov    %al,-0x22(%rbp)
movzbl -0x22(%rbp),%eax
cmp    $0x0,%eax
jne    12f6 <main+0x166>
mov    0x2cff(%rip),%rax
mov    (%rax),%edi
lea    0xe32(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x0,%al
call   1040 <abort@plt>
mov    -0x21(%rbp),%al
movzbl %al,%edi
movzbl -0x22(%rbp),%esi
call   1080 <unhex@plt>
mov    %al,-0x21(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     1320 <main+0x190>
movzbl -0x21(%rbp),%edi
call   1030 <putchar@plt>
jmp    1358 <main+0x1c8>
movzbl -0x21(%rbp),%edi
call   1090 <isprint@plt>
cmp    $0x0,%rax
je     1341 <main+0x1b1>
movzbl -0x21(%rbp),%edi
call   1030 <putchar@plt>
jmp    1353 <main+0x1c3>
movzbl -0x21(%rbp),%esi
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1358 <main+0x1c8>
jmp    1369 <main+0x1d9>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1282 <main+0xf2>
jmp    1373 <main+0x1e3>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b4 <main+0x24>
cmpl   $0x0,-0x28(%rbp)
jne    1399 <main+0x209>
lea    0xd0d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2c38(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
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    $0x2,%edi
jl     127b <main+0xeb>
mov    %rsi,%r12
mov    %edi,%r15d
mov    $0x1,%ebx
xor    %r13d,%r13d
jmp    11cd <main+0x3d>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%rbx
cmp    %r15,%rbx
je     1276 <main+0xe6>
mov    (%r12,%rbx,8),%r14
mov    (%r14),%al
test   %al,%al
je     11c0 <main+0x30>
cmp    $0x2d,%al
jne    121f <main+0x8f>
mov    0x1(%r14),%al
cmp    $0x72,%al
mov    $0x1,%ecx
cmove  %ecx,%r13d
cmp    $0x3f,%al
je     12c0 <main+0x130>
cmp    $0x76,%al
je     12e0 <main+0x150>
cmp    $0x68,%al
jne    11c0 <main+0x30>
jmp    12c0 <main+0x130>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebp,%edi
call   1030 <putchar@plt>
movzbl (%r14),%eax
test   %al,%al
je     11c0 <main+0x30>
movzbl %al,%edi
call   10b0 <isxdigit@plt>
test   %rax,%rax
je     1270 <main+0xe0>
movzbl 0x1(%r14),%eax
test   %al,%al
je     12a4 <main+0x114>
movzbl (%r14),%edi
add    $0x2,%r14
movzbl %al,%esi
call   1080 <unhex@plt>
movzbl %al,%ebp
test   %r13d,%r13d
jne    1210 <main+0x80>
mov    %ebp,%edi
call   1090 <isprint@plt>
test   %rax,%rax
jne    1210 <main+0x80>
lea    0xef2(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1217 <main+0x87>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r14
jmp    1217 <main+0x87>
test   %r13d,%r13d
jne    1285 <main+0xf5>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x2d4c(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d35(%rip),%rax
mov    (%rax),%edi
lea    0xe68(%rip),%rsi
call   1060 <fprintf@plt>
xor    %eax,%eax
call   1040 <abort@plt>
mov    0x2d19(%rip),%rbx
mov    (%rbx),%edi
lea    0xd30(%rip),%rsi
call   1060 <fprintf@plt>
mov    (%rbx),%edi
lea    0xd69(%rip),%rsi
jmp    12f0 <main+0x160>
mov    0x2cf9(%rip),%rax
mov    (%rax),%edi
lea    0xdb1(%rip),%rsi
call   1060 <fprintf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [71 x i8] c"hexecho -r 01 02 03: produces raw binary output of hex bytes 01 02 03\0A\00"
@.str.1 = [90 x i8] c"hexecho 01 02 03: produces human readable binary output of hex bytes like '\\x01\\x02\\x03'\0A\00"
@.str.2 = [123 x i8] c"hexecho version 1.1. Copyright 2011 Andreas Fink (andreas@fink.org). Source on https://github.com/andreasfink/hexecho.git\0A\00"
@.str.3 = [54 x i8] c"expected a hex pair but only got a single hex number\0A\00"
@.str.4 = [7 x i8] c"\\x%02X\00"
@.str.5 = [2 x i8] c"\0A\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8
%9 = alloca i8
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %10
store i32 1, i32* %6
br label %11
11: ; preds = %113, %2
%12 = load i32, i32* %6
%13 = load i32, i32* %4
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %116
15: ; preds = %11
%16 = load i8**, i8*** %5
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8*, i8** %16, i64 %18
%20 = load i8*, i8** %19
store i8* %20, i8** %7
%21 = load i8*, i8** %7
%22 = getelementptr inbounds i8, i8* %21, i64 0
%23 = load i8, i8* %22
%24 = zext i8 %23 to i32
%25 = icmp eq i32 %24, 45
br i1 %25, label %26, label %62
26: ; preds = %15
%27 = load i8*, i8** %7
%28 = getelementptr inbounds i8, i8* %27, i64 1
%29 = load i8, i8* %28
%30 = zext i8 %29 to i32
%31 = icmp eq i32 %30, 114
br i1 %31, label %32, label %33
32: ; preds = %26
store i32 1, i32* %10
br label %33
33: ; preds = %32, %26
%34 = load i8*, i8** %7
%35 = getelementptr inbounds i8, i8* %34, i64 1
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = icmp eq i32 %37, 104
br i1 %38, label %45, label %39
39: ; preds = %33
%40 = load i8*, i8** %7
%41 = getelementptr inbounds i8, i8* %40, i64 1
%42 = load i8, i8* %41
%43 = zext i8 %42 to i32
%44 = icmp eq i32 %43, 63
br i1 %44, label %45, label %51
45: ; preds = %39, %33
%46 = load i32, i32* @stderr
%47 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str, i64 0, i64 0))
%48 = load i32, i32* @stderr
%49 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([90 x i8], [90 x i8]* @.str.1, i64 0, i64 0))
%50 = call i32 @exit(i32 0)
unreachable
51: ; preds = %39
%52 = load i8*, i8** %7
%53 = getelementptr inbounds i8, i8* %52, i64 1
%54 = load i8, i8* %53
%55 = zext i8 %54 to i32
%56 = icmp eq i32 %55, 118
br i1 %56, label %57, label %61
57: ; preds = %51
%58 = load i32, i32* @stderr
%59 = call i32 @fprintf(i32 %58, i8* getelementptr inbounds ([123 x i8], [123 x i8]* @.str.2, i64 0, i64 0))
%60 = call i32 @exit(i32 0)
unreachable
61: ; preds = %51
br label %113
62: ; preds = %15
br label %63
63: ; preds = %111, %62
%64 = load i8*, i8** %7
%65 = load i8, i8* %64
%66 = icmp ne i8 %65, 0
br i1 %66, label %67, label %112
67: ; preds = %63
%68 = load i8*, i8** %7
%69 = load i8, i8* %68
%70 = call i64 @isxdigit(i8 zeroext %69)
%71 = icmp ne i64 %70, 0
br i1 %71, label %72, label %108
72: ; preds = %67
%73 = load i8*, i8** %7
%74 = getelementptr inbounds i8, i8* %73, i32 1
store i8* %74, i8** %7
%75 = load i8, i8* %73
store i8 %75, i8* %8
%76 = load i8*, i8** %7
%77 = getelementptr inbounds i8, i8* %76, i32 1
store i8* %77, i8** %7
%78 = load i8, i8* %76
store i8 %78, i8* %9
%79 = load i8, i8* %9
%80 = zext i8 %79 to i32
%81 = icmp eq i32 %80, 0
br i1 %81, label %82, label %86
82: ; preds = %72
%83 = load i32, i32* @stderr
%84 = call i32 @fprintf(i32 %83, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0))
%85 = call i32 (...) @abort()
unreachable
86: ; preds = %72
%87 = load i8, i8* %8
%88 = load i8, i8* %9
%89 = call zeroext i8 @unhex(i8 zeroext %87, i8 zeroext %88)
store i8 %89, i8* %8
%90 = load i32, i32* %10
%91 = icmp ne i32 %90, 0
br i1 %91, label %92, label %95
92: ; preds = %86
%93 = load i8, i8* %8
%94 = call i32 @putchar(i8 zeroext %93)
br label %107
95: ; preds = %86
%96 = load i8, i8* %8
%97 = call i64 @isprint(i8 zeroext %96)
%98 = icmp ne i64 %97, 0
br i1 %98, label %99, label %102
99: ; preds = %95
%100 = load i8, i8* %8
%101 = call i32 @putchar(i8 zeroext %100)
br label %106
102: ; preds = %95
%103 = load i8, i8* %8
%104 = zext i8 %103 to i32
%105 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %104)
br label %106
106: ; preds = %102, %99
br label %107
107: ; preds = %106, %92
br label %111
108: ; preds = %67
%109 = load i8*, i8** %7
%110 = getelementptr inbounds i8, i8* %109, i32 1
store i8* %110, i8** %7
br label %111
111: ; preds = %108, %107
br label %63
112: ; preds = %63
br label %113
113: ; preds = %112, %61
%114 = load i32, i32* %6
%115 = add nsw i32 %114, 1
store i32 %115, i32* %6
br label %11
116: ; preds = %11
%117 = load i32, i32* %10
%118 = icmp eq i32 %117, 0
br i1 %118, label %119, label %121
119: ; preds = %116
%120 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %121
121: ; preds = %119, %116
%122 = load i32, i32* @stdout
%123 = call i32 @fflush(i32 %122)
%124 = load i32, i32* %3
ret i32 %124
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [71 x i8] c"hexecho -r 01 02 03: produces raw binary output of hex bytes 01 02 03\0A\00"
@.str.1 = [90 x i8] c"hexecho 01 02 03: produces human readable binary output of hex bytes like '\\x01\\x02\\x03'\0A\00"
@.str.2 = [123 x i8] c"hexecho version 1.1. Copyright 2011 Andreas Fink (andreas@fink.org). Source on https://github.com/andreasfink/hexecho.git\0A\00"
@.str.3 = [54 x i8] c"expected a hex pair but only got a single hex number\0A\00"
@.str.4 = [7 x i8] c"\\x%02X\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %66
4: ; preds = %2
%5 = zext i32 %0 to i64
br label %6
6: ; preds = %4, %60
%7 = phi i64 [ 1, %4 ], [ %62, %60 ]
%8 = phi i32 [ 0, %4 ], [ %61, %60 ]
%9 = getelementptr inbounds i8*, i8** %1, i64 %7
%10 = load i8*, i8** %9
%11 = load i8, i8* %10
switch i8 %11, label %12 [
i8 45, label %14
i8 0, label %60
]
12: ; preds = %6
%13 = icmp eq i32 %8, 0
br label %29
14: ; preds = %6
%15 = getelementptr inbounds i8, i8* %10, i64 1
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 114
%18 = select i1 %17, i32 1, i32 %8
switch i8 %16, label %60 [
i8 104, label %19
i8 63, label %19
i8 118, label %25
]
19: ; preds = %14, %14
%20 = load i32, i32* @stderr
%21 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str, i64 0, i64 0))
%22 = load i32, i32* @stderr
%23 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([90 x i8], [90 x i8]* @.str.1, i64 0, i64 0))
%24 = tail call i32 @exit(i32 0)
unreachable
25: ; preds = %14
%26 = load i32, i32* @stderr
%27 = tail call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([123 x i8], [123 x i8]* @.str.2, i64 0, i64 0))
%28 = tail call i32 @exit(i32 0)
unreachable
29: ; preds = %12, %56
%30 = phi i8* [ %10, %12 ], [ %57, %56 ]
%31 = phi i8 [ %11, %12 ], [ %58, %56 ]
%32 = tail call i64 @isxdigit(i8 zeroext %31)
%33 = icmp eq i64 %32, 0
%34 = getelementptr inbounds i8, i8* %30, i64 1
br i1 %33, label %56, label %35
35: ; preds = %29
%36 = getelementptr inbounds i8, i8* %30, i64 2
%37 = load i8, i8* %34
%38 = icmp eq i8 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %35
%40 = load i32, i32* @stderr
%41 = tail call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0))
%42 = tail call i32 (...) @abort()
unreachable
43: ; preds = %35
%44 = load i8, i8* %30
%45 = tail call zeroext i8 @unhex(i8 zeroext %44, i8 zeroext %37)
br i1 %13, label %48, label %46
46: ; preds = %43
%47 = tail call i32 @putchar(i8 zeroext %45)
br label %56
48: ; preds = %43
%49 = tail call i64 @isprint(i8 zeroext %45)
%50 = icmp eq i64 %49, 0
br i1 %50, label %53, label %51
51: ; preds = %48
%52 = tail call i32 @putchar(i8 zeroext %45)
br label %56
53: ; preds = %48
%54 = zext i8 %45 to i32
%55 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %54)
br label %56
56: ; preds = %29, %46, %53, %51
%57 = phi i8* [ %36, %46 ], [ %36, %51 ], [ %36, %53 ], [ %34, %29 ]
%58 = load i8, i8* %57
%59 = icmp eq i8 %58, 0
br i1 %59, label %60, label %29
60: ; preds = %56, %6, %14
%61 = phi i32 [ %18, %14 ], [ %8, %6 ], [ %8, %56 ]
%62 = add nuw nsw i64 %7, 1
%63 = icmp eq i64 %62, %5
br i1 %63, label %64, label %6
64: ; preds = %60
%65 = icmp eq i32 %61, 0
br i1 %65, label %66, label %68
66: ; preds = %2, %64
%67 = tail call i32 bitcast (i32 (i8)* @putchar to i32 (i32)*)(i32 10)
br label %68
68: ; preds = %66, %64
%69 = load i32, i32* @stdout
%70 = tail call i32 @fflush(i32 %69)
ret i32 0
}