#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 unsigned char uint64_t;

/* Variables and functions */
scalar_t__ malloc(size_t);
int strlen(char const *);
unsigned char strtoul(char *, char **, int);
unsigned char *Hex_To_Var(const char *incoming, size_t *num_bytes) {
  unsigned char *retVal = NULL;
  int incoming_size = strlen(incoming);
  *num_bytes = incoming_size / 2;
  retVal = (unsigned char *)malloc(*num_bytes);
  char code[3];
  code[3] = '\0';
  int i = 0;
  for (i = 0; i < incoming_size; i += 2) {
    code[0] = incoming[i];
    code[1] = incoming[i + 1];
    char *ck = NULL;
    uint64_t lu = 0;
    lu = strtoul(code, &ck, 16);
    retVal[i] = lu;
    i++;
  }
  return retVal;
}


x86 assembly (clang, -O0):
<Hex_To_Var>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
movslq %eax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
movb   $0x0,-0x1c(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11fe <Hex_To_Var+0xce>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x1f(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x1e(%rbp)
movq   $0x0,-0x30(%rbp)
movb   $0x0,-0x31(%rbp)
lea    -0x1f(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    $0x10,%edx
call   1050 <strtoul@plt>
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%dl
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x24(%rbp)
jmp    118b <Hex_To_Var+0x5b>
mov    -0x18(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Hex_To_Var>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%ebp
shr    $0x1f,%eax
add    %ebp,%eax
sar    %eax
movslq %eax,%rdi
mov    %rdi,(%r14)
call   1040 <malloc@plt>
mov    %rax,%r14
movb   $0x0,0x10(%rsp)
test   %ebp,%ebp
jle    11b7 <Hex_To_Var+0x87>
mov    %ebp,%r13d
xor    %ebp,%ebp
lea    0xd(%rsp),%r15
lea    0x10(%rsp),%r12
nopl   0x0(%rax,%rax,1)
movzbl (%rbx,%rbp,1),%eax
mov    %al,0xd(%rsp)
movzbl 0x1(%rbx,%rbp,1),%eax
mov    %al,0xe(%rsp)
movq   $0x0,0x10(%rsp)
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x10,%edx
call   1050 <strtoul@plt>
mov    %al,(%r14,%rbp,1)
add    $0x3,%rbp
cmp    %r13,%rbp
jb     1180 <Hex_To_Var+0x50>
mov    %r14,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @Hex_To_Var(i8* %0, i64* %1) {
%3 = alloca i8*
%4 = alloca i64*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [3 x i8]
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8
store i8* %0, i8** %3
store i64* %1, i64** %4
store i8* null, i8** %5
%11 = load i8*, i8** %3
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = sdiv i32 %13, 2
%15 = sext i32 %14 to i64
%16 = load i64*, i64** %4
store i64 %15, i64* %16
%17 = load i64*, i64** %4
%18 = load i64, i64* %17
%19 = call i64 @malloc(i64 %18)
%20 = inttoptr i64 %19 to i8*
store i8* %20, i8** %5
%21 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 3
store i8 0, i8* %21
store i32 0, i32* %8
store i32 0, i32* %8
br label %22
22: ; preds = %49, %2
%23 = load i32, i32* %8
%24 = load i32, i32* %6
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %52
26: ; preds = %22
%27 = load i8*, i8** %3
%28 = load i32, i32* %8
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 0
store i8 %31, i8* %32
%33 = load i8*, i8** %3
%34 = load i32, i32* %8
%35 = add nsw i32 %34, 1
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %33, i64 %36
%38 = load i8, i8* %37
%39 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 1
store i8 %38, i8* %39
store i8* null, i8** %9
store i8 0, i8* %10
%40 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 0
%41 = call zeroext i8 @strtoul(i8* %40, i8** %9, i32 16)
store i8 %41, i8* %10
%42 = load i8, i8* %10
%43 = load i8*, i8** %5
%44 = load i32, i32* %8
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
store i8 %42, i8* %46
%47 = load i32, i32* %8
%48 = add nsw i32 %47, 1
store i32 %48, i32* %8
br label %49
49: ; preds = %26
%50 = load i32, i32* %8
%51 = add nsw i32 %50, 2
store i32 %51, i32* %8
br label %22
52: ; preds = %22
%53 = load i8*, i8** %5
ret i8* %53
}

LLVM IR (-O2):
define i8* @Hex_To_Var(i8* %0, i64* nocapture writeonly %1) {
%3 = alloca [3 x i8]
%4 = alloca i8*
%5 = tail call i32 @strlen(i8* %0)
%6 = sdiv i32 %5, 2
%7 = sext i32 %6 to i64
store i64 %7, i64* %1
%8 = tail call i64 @malloc(i64 %7)
%9 = inttoptr i64 %8 to i8*
%10 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%11 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 3
store i8 0, i8* %11
%12 = icmp sgt i32 %5, 0
br i1 %12, label %13, label %28
13: ; preds = %2
%14 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 1
%15 = bitcast i8** %4 to i8*
%16 = zext i32 %5 to i64
br label %17
17: ; preds = %13, %17
%18 = phi i64 [ 0, %13 ], [ %26, %17 ]
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = load i8, i8* %19
store i8 %20, i8* %10
%21 = add nuw nsw i64 %18, 1
%22 = getelementptr inbounds i8, i8* %0, i64 %21
%23 = load i8, i8* %22
store i8 %23, i8* %14
store i8* null, i8** %4
%24 = call zeroext i8 @strtoul(i8* %10, i8** %4, i32 16)
%25 = getelementptr inbounds i8, i8* %9, i64 %18
store i8 %24, i8* %25
%26 = add nuw nsw i64 %18, 3
%27 = icmp ult i64 %26, %16
br i1 %27, label %17, label %28
28: ; preds = %17, %2
ret i8* %9
}