#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 */
unsigned char hex(int /*<<< orphan*/);
char *hex2mem(unsigned char *buf, unsigned char *mem, int count) {
  int i;
  unsigned char ch;
  for (i = 0; i < count; i++) {
    ch = hex(*buf++) << 4;
    ch |= hex(*buf++);
    *mem++ = ch;
  }
  return mem;
}


x86 assembly (clang, -O0):
<hex2mem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    119b <hex2mem+0x8b>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movzbl (%rax),%edi
call   1030 <hex@plt>
movzbl %al,%eax
shl    $0x4,%eax
mov    %al,-0x19(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movzbl (%rax),%edi
call   1030 <hex@plt>
movzbl %al,%ecx
movzbl -0x19(%rbp),%eax
or     %ecx,%eax
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    112a <hex2mem+0x1a>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex2mem>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
test   %edx,%edx
jle    115e <hex2mem+0x4e>
mov    %rdi,%r15
mov    %edx,%r12d
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movzbl (%r15,%rbx,2),%edi
call   1030 <hex@plt>
mov    %eax,%ebp
shl    $0x4,%bpl
movzbl 0x1(%r15,%rbx,2),%edi
call   1030 <hex@plt>
or     %bpl,%al
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    %ebx,%r12d
jne    1130 <hex2mem+0x20>
add    %rbx,%r14
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @hex2mem(i8* nocapture %0, i8* writeonly %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %22
5: ; preds = %3, %5
%6 = phi i8* [ %14, %5 ], [ %0, %3 ]
%7 = phi i32 [ %20, %5 ], [ 0, %3 ]
%8 = phi i8* [ %19, %5 ], [ %1, %3 ]
%9 = getelementptr inbounds i8, i8* %6, i64 1
%10 = load i8, i8* %6
%11 = zext i8 %10 to i32
%12 = tail call zeroext i8 @hex(i32 %11)
%13 = shl i8 %12, 4
%14 = getelementptr inbounds i8, i8* %6, i64 2
%15 = load i8, i8* %9
%16 = zext i8 %15 to i32
%17 = tail call zeroext i8 @hex(i32 %16)
%18 = or i8 %17, %13
%19 = getelementptr inbounds i8, i8* %8, i64 1
store i8 %18, i8* %8
%20 = add nuw nsw i32 %7, 1
%21 = icmp eq i32 %20, %2
br i1 %21, label %22, label %5
22: ; preds = %5, %3
%23 = phi i8* [ %1, %3 ], [ %19, %5 ]
ret i8* %23
}