#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 strlen(char const *);
scalar_t__ strtol(char *, int /*<<< orphan*/ *, int);
char *hex2bin(const char *s, char *szBinBuff, int *nDestLen) {
  char buff[3];
  char *pSrc;
  int nSrcLen;
  char *pDest;
  char *pDestEnd;
  nSrcLen = strlen(s);
  if (nSrcLen == 0) {
    *nDestLen = 0;
    szBinBuff[0] = '\0';
    return szBinBuff;
  }
  *nDestLen = nSrcLen / 2;
  pSrc = (char *)s;
  buff[2] = '\0';
  pDestEnd = szBinBuff + (*nDestLen);
  for (pDest = szBinBuff; pDest < pDestEnd; pDest++) {
    buff[0] = *pSrc++;
    buff[1] = *pSrc++;
    *pDest = (char)strtol(buff, NULL, 16);
  }
  *pDest = '\0';
  return szBinBuff;
}


x86 assembly (clang, -O0):
<hex2bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jne    1168 <hex2bin+0x48>
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1211 <hex2bin+0xf1>
mov    -0x34(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
movb   $0x0,-0x21(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
movslq (%rcx),%rcx
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x48(%rbp),%rax
jae    1202 <hex2bin+0xe2>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
mov    (%rax),%al
mov    %al,-0x23(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
mov    (%rax),%al
mov    %al,-0x22(%rbp)
lea    -0x23(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %al,%cl
mov    -0x40(%rbp),%rax
mov    %cl,(%rax)
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    11a1 <hex2bin+0x81>
mov    -0x40(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex2bin>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r13
call   1030 <strlen@plt>
test   %eax,%eax
je     11a2 <hex2bin+0x82>
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
mov    %ecx,(%r15)
movb   $0x0,0xf(%rsp)
mov    %r14,%rbx
cmp    $0x2,%eax
jl     11ac <hex2bin+0x8c>
movslq %ecx,%r12
add    %r14,%r12
lea    0xd(%rsp),%r15
mov    %r14,%rbx
cs nopw 0x0(%rax,%rax,1)
movzbl 0x0(%r13),%eax
mov    %al,0xd(%rsp)
movzbl 0x1(%r13),%eax
mov    %al,0xe(%rsp)
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %al,(%rbx)
add    $0x1,%rbx
add    $0x2,%r13
cmp    %r12,%rbx
jb     1170 <hex2bin+0x50>
jmp    11ac <hex2bin+0x8c>
movl   $0x0,(%r15)
mov    %r14,%rbx
movb   $0x0,(%rbx)
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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