#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 */
void *num2nibble(char);
void hex2nibblestr(char *dst, char *src, int srclen) {
  int i;
  for (i = 0; i < srclen; i++) {
    *(dst++) = num2nibble((*src >> 4) & 0x0F);
    *(dst++) = num2nibble(*src & 0x0F);
    src++;
  }
  *(dst) = '\0';
}


x86 assembly (clang, -O0):
<hex2nibblestr>:
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    119d <hex2nibblestr+0x8d>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
sar    $0x4,%eax
and    $0xf,%eax
movsbl %al,%edi
call   1030 <num2nibble@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
and    $0xf,%eax
movsbl %al,%edi
call   1030 <num2nibble@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    112a <hex2nibblestr+0x1a>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex2nibblestr>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
test   %edx,%edx
jle    1166 <hex2nibblestr+0x56>
mov    %rsi,%r15
mov    %edx,%r12d
xor    %r13d,%r13d
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movzbl (%r15,%rbx,1),%eax
shr    $0x4,%al
movzbl %al,%edi
call   1030 <num2nibble@plt>
mov    %al,(%r14,%rbx,2)
movzbl (%r15,%rbx,1),%edi
and    $0xf,%edi
call   1030 <num2nibble@plt>
mov    %al,0x1(%r14,%rbx,2)
add    $0x1,%rbx
add    $0xfffffffffffffffe,%r13
cmp    %ebx,%r12d
jne    1130 <hex2nibblestr+0x20>
sub    %r13,%r14
movb   $0x0,(%r14)
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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