#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 */
scalar_t__ hex_encode_ch(char const);
void hex_encode(char *symstr, const char *hexstr, size_t hsize) {
  size_t i;
  for (i = 0; 2 * i < hsize; i++) {
    symstr[2 * i] = (char)hex_encode_ch(hexstr[i] >> 4);
    symstr[2 * i + 1] = (char)hex_encode_ch(hexstr[i]);
  }
}


x86 assembly (clang, -O0):
<hex_encode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
shl    $0x1,%rax
cmp    -0x18(%rbp),%rax
jae    119a <hex_encode+0x8a>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
sar    $0x4,%eax
movsbl %al,%edi
call   1030 <hex_encode_ch@plt>
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
shl    $0x1,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <hex_encode_ch@plt>
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
shl    $0x1,%rcx
mov    %dl,0x1(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    112c <hex_encode+0x1c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex_encode>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rdx,%rdx
je     1160 <hex_encode+0x50>
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movzbl (%r12),%eax
sar    $0x4,%al
movsbl %al,%edi
call   1030 <hex_encode_ch@plt>
mov    %al,(%r15,%rbx,1)
movsbl (%r12),%edi
call   1030 <hex_encode_ch@plt>
mov    %al,0x1(%r15,%rbx,1)
add    $0x2,%rbx
add    $0x1,%r12
cmp    %r14,%rbx
jb     1130 <hex_encode+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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