#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 */
char char2Hex(char);
void string2hex(char *Output, unsigned char *Input, int Length) {
  char *Out;
  char First;
  char Second;
  Out = Output;
  while (Length > 0) {
    First = *Input / 0x10;
    Second = *Input % 0x10;
    *Out = char2Hex(First);
    Out++;
    *Out = char2Hex(Second);
    Out++;
    Length--;
    Input++;
  }
  *Out = '\0';
  return;
}


x86 assembly (clang, -O0):
<string2hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    11af <string2hex+0x9f>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %al,-0x21(%rbp)
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %dl,%al
mov    %al,-0x22(%rbp)
movsbl -0x21(%rbp),%edi
call   1030 <char2Hex@plt>
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
movsbl -0x22(%rbp),%edi
call   1030 <char2Hex@plt>
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    112b <string2hex+0x1b>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string2hex>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
test   %edx,%edx
jle    1162 <string2hex+0x52>
mov    %edx,%r15d
mov    %rsi,%r14
add    $0x1,%r15d
nopl   0x0(%rax,%rax,1)
movsbl (%r14),%ebp
mov    %ebp,%eax
shr    $0x4,%al
movzbl %al,%edi
call   1030 <char2Hex@plt>
mov    %al,(%rbx)
and    $0xf,%ebp
mov    %ebp,%edi
call   1030 <char2Hex@plt>
mov    %al,0x1(%rbx)
add    $0x2,%rbx
add    $0x1,%r14
add    $0xffffffff,%r15d
cmp    $0x1,%r15d
ja     1130 <string2hex+0x20>
movb   $0x0,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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