#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 scalar_t__ uint8_t;
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ sscanf(char *, char *, unsigned int *);
int strlen(char const *);
void HexToBytes(char const *HexString, uint8_t *Data, uint32_t *pDataSize) {
  uint32_t i;
  char holdingBuffer[3] = {0};
  unsigned hexToNumber;
  uint32_t outputIndex = 0;
  for (i = 0; i < strlen(HexString) / 2; i++) {
    holdingBuffer[0] = HexString[i * 2 + 0];
    holdingBuffer[1] = HexString[i * 2 + 1];
    sscanf(holdingBuffer, "%x", &hexToNumber);
    Data[i] = (uint8_t)hexToNumber;
    outputIndex += 1;
  }
  if (NULL != pDataSize) {
    *pDataSize = outputIndex;
  }
}


x86 assembly (clang, -O0):
<HexToBytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x1f(%rbp),%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1040 <memset@plt>
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
cmp    %ecx,%eax
jge    11ee <HexToBytes+0xbe>
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
shl    $0x1,%ecx
add    $0x0,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x1f(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x1e(%rbp)
lea    -0x1f(%rbp),%rdi
lea    0xe43(%rip),%rsi
lea    -0x24(%rbp),%rdx
call   1050 <sscanf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,%edx
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1162 <HexToBytes+0x32>
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
je     1203 <HexToBytes+0xd3>
mov    -0x28(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HexToBytes>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%rbp
mov    %rsi,%r15
mov    %rdi,%rbx
movb   $0x0,0xb(%rsp)
call   1030 <strlen@plt>
xor    %r14d,%r14d
cmp    $0x2,%eax
jl     11bb <HexToBytes+0x9b>
mov    %rbp,0x10(%rsp)
xor    %r14d,%r14d
lea    0xea8(%rip),%r12
lea    0x9(%rsp),%r13
lea    0xc(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%rbx,%r14,2),%eax
mov    %al,0x9(%rsp)
movzbl 0x1(%rbx,%r14,2),%eax
mov    %al,0xa(%rsp)
mov    %r13,%rdi
mov    %r12,%rsi
mov    %rbp,%rdx
call   1040 <sscanf@plt>
mov    0xc(%rsp),%eax
mov    %rax,(%r15,%r14,8)
add    $0x1,%r14
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
movslq %ecx,%rax
cmp    %rax,%r14
jl     1170 <HexToBytes+0x50>
mov    0x10(%rsp),%rbp
test   %rbp,%rbp
je     11c4 <HexToBytes+0xa4>
mov    %r14d,0x0(%rbp)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%x\00"
define void @HexToBytes(i8* %0, i64* nocapture writeonly %1, i32* writeonly %2) {
%4 = alloca [3 x i8]
%5 = alloca i32
%6 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 2
store i8 0, i8* %7
%8 = bitcast i32* %5 to i8*
%9 = call i32 @strlen(i8* %0)
%10 = icmp sgt i32 %9, 1
br i1 %10, label %11, label %32
11: ; preds = %3
%12 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 1
br label %13
13: ; preds = %11, %13
%14 = phi i64 [ 0, %11 ], [ %25, %13 ]
%15 = shl nuw nsw i64 %14, 1
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = load i8, i8* %16
store i8 %17, i8* %6
%18 = or i64 %15, 1
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = load i8, i8* %19
store i8 %20, i8* %12
%21 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %5)
%22 = load i32, i32* %5
%23 = zext i32 %22 to i64
%24 = getelementptr inbounds i64, i64* %1, i64 %14
store i64 %23, i64* %24
%25 = add nuw nsw i64 %14, 1
%26 = call i32 @strlen(i8* %0)
%27 = sdiv i32 %26, 2
%28 = sext i32 %27 to i64
%29 = icmp slt i64 %25, %28
br i1 %29, label %13, label %30
30: ; preds = %13
%31 = trunc i64 %25 to i32
br label %32
32: ; preds = %30, %3
%33 = phi i32 [ 0, %3 ], [ %31, %30 ]
%34 = icmp eq i32* %2, null
br i1 %34, label %36, label %35
35: ; preds = %32
store i32 %33, i32* %2
br label %36
36: ; preds = %35, %32
ret void
}