#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 */
scalar_t__ isxdigit(char);
char oneHexCharToHex(char);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char const *);
int ChangeTHEX2CPTR(const char *inHexString, char *outHex) {
  int success = -1;
  int len = 0;
  int i;
  char ch1, ch2;
  do {
    if (NULL == inHexString || NULL == outHex) {
      printf("error: inHexString or outHex is null!\n");
      break;
    }
    len = strlen(inHexString);
    if (len <= 1) {
      printf("error: strlen(inHexString) <= 1!\n");
      break;
    }
    len &= ~1;
    for (i = 0; i < len; i += 2) {
      ch1 = inHexString[i];
      ch2 = inHexString[i + 1];
      outHex[i / 2 + 1] = 0;
      if (isxdigit(ch1) && isxdigit(ch2)) {
        ch1 = oneHexCharToHex(ch1);
        ch2 = oneHexCharToHex(ch2);
        outHex[i / 2] = (ch1 << 4) | ch2;
      } else {
        printf("error: %c or %c is not hex digit!\n", ch1, ch2);
        goto exit;
      }
    }
    success = 0;
  } while (0);
exit:
  return success;
}


x86 assembly (clang, -O0):
<ChangeTHEX2CPTR>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x8(%rbp),%rax
je     1176 <ChangeTHEX2CPTR+0x36>
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jne    1189 <ChangeTHEX2CPTR+0x49>
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12bc <ChangeTHEX2CPTR+0x17c>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
jg     11b2 <ChangeTHEX2CPTR+0x72>
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12bc <ChangeTHEX2CPTR+0x17c>
mov    -0x18(%rbp),%eax
and    $0xfffffffe,%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    12b5 <ChangeTHEX2CPTR+0x175>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x1d(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x1e(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
movsbl -0x1d(%rbp),%edi
call   1060 <isxdigit@plt>
cmp    $0x0,%rax
je     1287 <ChangeTHEX2CPTR+0x147>
movsbl -0x1e(%rbp),%edi
call   1060 <isxdigit@plt>
cmp    $0x0,%rax
je     1287 <ChangeTHEX2CPTR+0x147>
movsbl -0x1d(%rbp),%edi
call   1050 <oneHexCharToHex@plt>
mov    %al,-0x1d(%rbp)
movsbl -0x1e(%rbp),%edi
call   1050 <oneHexCharToHex@plt>
mov    %al,-0x1e(%rbp)
movsbl -0x1d(%rbp),%eax
shl    $0x4,%eax
movsbl -0x1e(%rbp),%ecx
or     %ecx,%eax
mov    %al,-0x31(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x31(%rbp),%dl
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    12a2 <ChangeTHEX2CPTR+0x162>
movsbl -0x1d(%rbp),%esi
movsbl -0x1e(%rbp),%edx
lea    0xdb3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12c1 <ChangeTHEX2CPTR+0x181>
jmp    12a7 <ChangeTHEX2CPTR+0x167>
mov    -0x1c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c2 <ChangeTHEX2CPTR+0x82>
movl   $0x0,-0x14(%rbp)
jmp    12c1 <ChangeTHEX2CPTR+0x181>
mov    -0x14(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ChangeTHEX2CPTR>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     117e <ChangeTHEX2CPTR+0x2e>
mov    %rsi,%r15
test   %rsi,%rsi
je     117e <ChangeTHEX2CPTR+0x2e>
mov    %rdi,%r14
call   1040 <strlen@plt>
cmp    $0x1,%eax
jg     119e <ChangeTHEX2CPTR+0x4e>
lea    0xea7(%rip),%rdi
jmp    1185 <ChangeTHEX2CPTR+0x35>
lea    0xebf(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
and    $0xfffffffe,%eax
je     11ff <ChangeTHEX2CPTR+0xaf>
mov    %eax,%r12d
add    $0x1,%r15
xor    %ebp,%ebp
nopl   0x0(%rax)
movsbl (%r14,%rbp,1),%ebx
movsbl 0x1(%r14,%rbp,1),%r13d
movb   $0x0,(%r15)
mov    %ebx,%edi
call   1070 <isxdigit@plt>
test   %rax,%rax
je     1203 <ChangeTHEX2CPTR+0xb3>
mov    %r13d,%edi
call   1070 <isxdigit@plt>
test   %rax,%rax
je     1203 <ChangeTHEX2CPTR+0xb3>
mov    %ebx,%edi
call   1060 <oneHexCharToHex@plt>
mov    %eax,%ebx
mov    %r13d,%edi
call   1060 <oneHexCharToHex@plt>
shl    $0x4,%bl
or     %al,%bl
mov    %bl,-0x1(%r15)
add    $0x2,%rbp
add    $0x1,%r15
cmp    %r12,%rbp
jb     11b0 <ChangeTHEX2CPTR+0x60>
xor    %eax,%eax
jmp    118f <ChangeTHEX2CPTR+0x3f>
lea    0xdf6(%rip),%rdi
mov    %ebx,%esi
mov    %r13d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    118a <ChangeTHEX2CPTR+0x3a>

LLVM IR (-O0):
@.str = [39 x i8] c"error: inHexString or outHex is null!\0A\00"
@.str.1 = [34 x i8] c"error: strlen(inHexString) <= 1!\0A\00"
@.str.2 = [35 x i8] c"error: %c or %c is not hex digit!\0A\00"
define i32 @ChangeTHEX2CPTR(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8
%9 = alloca i8
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 -1, i32* %5
store i32 0, i32* %6
br label %10
10: ; preds = %2
%11 = load i8*, i8** %3
%12 = icmp eq i8* null, %11
br i1 %12, label %16, label %13
13: ; preds = %10
%14 = load i8*, i8** %4
%15 = icmp eq i8* null, %14
br i1 %15, label %16, label %18
16: ; preds = %13, %10
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %85
18: ; preds = %13
%19 = load i8*, i8** %3
%20 = call i32 @strlen(i8* %19)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = icmp sle i32 %21, 1
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
br label %85
25: ; preds = %18
%26 = load i32, i32* %6
%27 = and i32 %26, -2
store i32 %27, i32* %6
store i32 0, i32* %7
br label %28
28: ; preds = %81, %25
%29 = load i32, i32* %7
%30 = load i32, i32* %6
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %84
32: ; preds = %28
%33 = load i8*, i8** %3
%34 = load i32, i32* %7
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i8, i8* %36
store i8 %37, i8* %8
%38 = load i8*, i8** %3
%39 = load i32, i32* %7
%40 = add nsw i32 %39, 1
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %38, i64 %41
%43 = load i8, i8* %42
store i8 %43, i8* %9
%44 = load i8*, i8** %4
%45 = load i32, i32* %7
%46 = sdiv i32 %45, 2
%47 = add nsw i32 %46, 1
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %44, i64 %48
store i8 0, i8* %49
%50 = load i8, i8* %8
%51 = call i64 @isxdigit(i8 signext %50)
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %74
53: ; preds = %32
%54 = load i8, i8* %9
%55 = call i64 @isxdigit(i8 signext %54)
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %74
57: ; preds = %53
%58 = load i8, i8* %8
%59 = call signext i8 @oneHexCharToHex(i8 signext %58)
store i8 %59, i8* %8
%60 = load i8, i8* %9
%61 = call signext i8 @oneHexCharToHex(i8 signext %60)
store i8 %61, i8* %9
%62 = load i8, i8* %8
%63 = sext i8 %62 to i32
%64 = shl i32 %63, 4
%65 = load i8, i8* %9
%66 = sext i8 %65 to i32
%67 = or i32 %64, %66
%68 = trunc i32 %67 to i8
%69 = load i8*, i8** %4
%70 = load i32, i32* %7
%71 = sdiv i32 %70, 2
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i8, i8* %69, i64 %72
store i8 %68, i8* %73
br label %80
74: ; preds = %53, %32
%75 = load i8, i8* %8
%76 = sext i8 %75 to i32
%77 = load i8, i8* %9
%78 = sext i8 %77 to i32
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %76, i32 %78)
br label %86
80: ; preds = %57
br label %81
81: ; preds = %80
%82 = load i32, i32* %7
%83 = add nsw i32 %82, 2
store i32 %83, i32* %7
br label %28
84: ; preds = %28
store i32 0, i32* %5
br label %85
85: ; preds = %84, %23, %16
br label %86
86: ; preds = %85, %74
%87 = load i32, i32* %5
ret i32 %87
}

LLVM IR (-O2):
@.str.2 = [35 x i8] c"error: %c or %c is not hex digit!\0A\00"
@str = [33 x i8] c"error: strlen(inHexString) <= 1!\00"
@str.3 = [38 x i8] c"error: inHexString or outHex is null!\00"
define i32 @ChangeTHEX2CPTR(i8* %0, i8* writeonly %1) {
%3 = icmp eq i8* %0, null
%4 = icmp eq i8* %1, null
%5 = or i1 %3, %4
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.3, i64 0, i64 0))
br label %45
8: ; preds = %2
%9 = tail call i32 @strlen(i8* %0)
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
br label %45
13: ; preds = %8
%14 = and i32 %9, -2
%15 = icmp eq i32 %14, 0
br i1 %15, label %45, label %16
16: ; preds = %13
%17 = zext i32 %14 to i64
br label %18
18: ; preds = %16, %33
%19 = phi i64 [ 0, %16 ], [ %39, %33 ]
%20 = getelementptr inbounds i8, i8* %0, i64 %19
%21 = load i8, i8* %20
%22 = or i64 %19, 1
%23 = getelementptr inbounds i8, i8* %0, i64 %22
%24 = load i8, i8* %23
%25 = lshr exact i64 %19, 1
%26 = add nuw nsw i64 %25, 1
%27 = getelementptr inbounds i8, i8* %1, i64 %26
store i8 0, i8* %27
%28 = tail call i64 @isxdigit(i8 signext %21)
%29 = icmp eq i64 %28, 0
br i1 %29, label %41, label %30
30: ; preds = %18
%31 = tail call i64 @isxdigit(i8 signext %24)
%32 = icmp eq i64 %31, 0
br i1 %32, label %41, label %33
33: ; preds = %30
%34 = tail call signext i8 @oneHexCharToHex(i8 signext %21)
%35 = tail call signext i8 @oneHexCharToHex(i8 signext %24)
%36 = shl i8 %34, 4
%37 = or i8 %36, %35
%38 = getelementptr inbounds i8, i8* %1, i64 %25
store i8 %37, i8* %38
%39 = add nuw nsw i64 %19, 2
%40 = icmp ult i64 %39, %17
br i1 %40, label %18, label %45
41: ; preds = %30, %18
%42 = sext i8 %21 to i32
%43 = sext i8 %24 to i32
%44 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %42, i32 %43)
br label %45
45: ; preds = %33, %13, %6, %11, %41
%46 = phi i32 [ -1, %6 ], [ -1, %11 ], [ -1, %41 ], [ 0, %13 ], [ 0, %33 ]
ret i32 %46
}