#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(unsigned char *);
scalar_t__ strtol(char *, int /*<<< orphan*/ *, int);
void hex2bin(unsigned char *dest, unsigned char *src) {
  unsigned char bin;
  int c, pos;
  char buf[3];
  pos = 0;
  c = 0;
  buf[2] = 0;
  while (c < strlen(src)) {
    buf[0] = src[c++];
    buf[1] = src[c++];
    dest[pos++] = (unsigned char)strtol(buf, NULL, 16);
  }
}


x86 assembly (clang, -O0):
<hex2bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
movb   $0x0,-0x1d(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jge    11bc <hex2bin+0x9c>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x18(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x1f(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x18(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x1e(%rbp)
lea    -0x1f(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x1c(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1142 <hex2bin+0x22>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex2bin>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
movb   $0x0,0x7(%rsp)
mov    %rsi,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    118a <hex2bin+0x6a>
xor    %ebx,%ebx
lea    0x5(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
movzbl (%r14,%rbx,1),%eax
mov    %al,0x5(%rsp)
movzbl 0x1(%r14,%rbx,1),%eax
add    $0x2,%rbx
mov    %al,0x6(%rsp)
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %al,(%r12)
mov    %r14,%rdi
call   1030 <strlen@plt>
add    $0x1,%r12
cmp    %ebx,%eax
jg     1150 <hex2bin+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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