#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 sscanf(char *, char *, int *);
int hex_to_bytes(char *from, char *to, int *pTo_length) {
  char *pHex;
  char *pByte;
  int byte_length = 0;
  int value;
  pByte = to;
  for (pHex = from; *pHex != 0; pHex += 2) {
    if (1 != sscanf(pHex, "%02x", &value))
      return (0);
    *pByte++ = ((char)(value & 0xFF));
    byte_length++;
  }
  *pTo_length = byte_length;
  return (1);
}


x86 assembly (clang, -O0):
<hex_to_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11af <hex_to_bytes+0x9f>
mov    -0x28(%rbp),%rdi
lea    0xeaa(%rip),%rsi
lea    -0x38(%rbp),%rdx
call   1030 <sscanf@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
je     117a <hex_to_bytes+0x6a>
movl   $0x0,-0x4(%rbp)
jmp    11bf <hex_to_bytes+0xaf>
mov    -0x38(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x30(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x30(%rbp)
mov    %cl,(%rax)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x28(%rbp)
jmp    113b <hex_to_bytes+0x2b>
mov    -0x34(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex_to_bytes>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmpb   $0x0,(%rdi)
je     1171 <hex_to_bytes+0x61>
mov    %rsi,%r12
mov    %rdi,%rbx
mov    %rdx,0x10(%rsp)
xor    %r15d,%r15d
lea    0xec8(%rip),%r13
lea    0xc(%rsp),%rbp
xor    %r14d,%r14d
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
call   1030 <sscanf@plt>
cmp    $0x1,%eax
jne    117d <hex_to_bytes+0x6d>
movzbl 0xc(%rsp),%eax
mov    %al,(%r12,%r14,1)
add    $0x1,%r14
cmpb   $0x0,0x2(%rbx)
lea    0x2(%rbx),%rbx
jne    1140 <hex_to_bytes+0x30>
mov    0x10(%rsp),%rdx
jmp    1174 <hex_to_bytes+0x64>
xor    %r14d,%r14d
mov    %r14d,(%rdx)
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%02x\00"
define i32 @hex_to_bytes(i8* %0, i8* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32* %2, i32** %7
store i32 0, i32* %10
%12 = load i8*, i8** %6
store i8* %12, i8** %9
%13 = load i8*, i8** %5
store i8* %13, i8** %8
br label %14
14: ; preds = %32, %3
%15 = load i8*, i8** %8
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %35
19: ; preds = %14
%20 = load i8*, i8** %8
%21 = call i32 @sscanf(i8* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %11)
%22 = icmp ne i32 1, %21
br i1 %22, label %23, label %24
23: ; preds = %19
store i32 0, i32* %4
br label %38
24: ; preds = %19
%25 = load i32, i32* %11
%26 = and i32 %25, 255
%27 = trunc i32 %26 to i8
%28 = load i8*, i8** %9
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %9
store i8 %27, i8* %28
%30 = load i32, i32* %10
%31 = add nsw i32 %30, 1
store i32 %31, i32* %10
br label %32
32: ; preds = %24
%33 = load i8*, i8** %8
%34 = getelementptr inbounds i8, i8* %33, i64 2
store i8* %34, i8** %8
br label %14
35: ; preds = %14
%36 = load i32, i32* %10
%37 = load i32*, i32** %7
store i32 %36, i32* %37
store i32 1, i32* %4
br label %38
38: ; preds = %35, %23
%39 = load i32, i32* %4
ret i32 %39
}

LLVM IR (-O2):
@.str = [5 x i8] c"%02x\00"
define i32 @hex_to_bytes(i8* nocapture %0, i8* nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %22, label %8
8: ; preds = %3, %14
%9 = phi i32 [ %18, %14 ], [ 0, %3 ]
%10 = phi i8* [ %17, %14 ], [ %1, %3 ]
%11 = phi i8* [ %19, %14 ], [ %0, %3 ]
%12 = call i32 @sscanf(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %4)
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %24
14: ; preds = %8
%15 = load i32, i32* %4
%16 = trunc i32 %15 to i8
%17 = getelementptr inbounds i8, i8* %10, i64 1
store i8 %16, i8* %10
%18 = add nuw nsw i32 %9, 1
%19 = getelementptr inbounds i8, i8* %11, i64 2
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %8
22: ; preds = %14, %3
%23 = phi i32 [ 0, %3 ], [ %18, %14 ]
store i32 %23, i32* %2
br label %24
24: ; preds = %8, %22
%25 = phi i32 [ 1, %22 ], [ 0, %8 ]
ret i32 %25
}