#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 htoa(int /*<<< orphan*/);
void gethex(char *result, char *cp, int cnt) {
  while (cnt-- != 0) {
    *result = htoa(*cp++) << 4;
    *result++ |= htoa(*cp++);
  }
}


x86 assembly (clang, -O0):
<gethex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
je     118d <gethex+0x7d>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%edi
call   1030 <htoa@plt>
shl    $0x4,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%edi
call   1030 <htoa@plt>
mov    %eax,%edx
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%ecx
or     %edx,%ecx
mov    %cl,(%rax)
jmp    1123 <gethex+0x13>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gethex>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
je     1159 <gethex+0x49>
mov    %rsi,%r14
mov    %rdi,%r12
mov    %edx,%r15d
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movsbl (%r14,%rbx,2),%edi
call   1030 <htoa@plt>
shl    $0x4,%al
mov    %al,(%r12,%rbx,1)
movsbl 0x1(%r14,%rbx,2),%edi
call   1030 <htoa@plt>
or     %al,(%r12,%rbx,1)
add    $0x1,%rbx
cmp    %ebx,%r15d
jne    1130 <gethex+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @gethex(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
br label %7
7: ; preds = %11, %3
%8 = load i32, i32* %6
%9 = add nsw i32 %8, -1
store i32 %9, i32* %6
%10 = icmp ne i32 %8, 0
br i1 %10, label %11, label %31
11: ; preds = %7
%12 = load i8*, i8** %5
%13 = getelementptr inbounds i8, i8* %12, i32 1
store i8* %13, i8** %5
%14 = load i8, i8* %12
%15 = sext i8 %14 to i32
%16 = call i32 @htoa(i32 %15)
%17 = shl i32 %16, 4
%18 = trunc i32 %17 to i8
%19 = load i8*, i8** %4
store i8 %18, i8* %19
%20 = load i8*, i8** %5
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %5
%22 = load i8, i8* %20
%23 = sext i8 %22 to i32
%24 = call i32 @htoa(i32 %23)
%25 = load i8*, i8** %4
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %4
%27 = load i8, i8* %25
%28 = sext i8 %27 to i32
%29 = or i32 %28, %24
%30 = trunc i32 %29 to i8
store i8 %30, i8* %25
br label %7
31: ; preds = %7
ret void
}

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