#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 /*<<< orphan*/ sprintf(char *, char *, unsigned char const);
void string2hexString(const unsigned char *input, char *output, int len) {
  int loop;
  int i;
  i = 0;
  loop = 0;
  while (input[loop] != '\0' && loop < len) {
    sprintf((char *)(output + i), "%02X", input[loop]);
    loop += 1;
    i += 2;
  }
}


x86 assembly (clang, -O0):
<string2hexString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1d(%rbp)
je     1157 <string2hexString+0x47>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
setl   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1167 <string2hexString+0x57>
jmp    11a1 <string2hexString+0x91>
mov    -0x10(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
lea    0xe7f(%rip),%rsi
movzbl (%rax,%rcx,1),%edx
call   1030 <sprintf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x1c(%rbp)
jmp    1131 <string2hexString+0x21>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string2hexString>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    (%rdi),%al
test   %al,%al
je     1167 <string2hexString+0x57>
test   %edx,%edx
jle    1167 <string2hexString+0x57>
mov    %rsi,%r13
mov    %rdi,%r14
mov    %edx,%r12d
mov    $0x1,%ebx
lea    0xec8(%rip),%r15
nopl   0x0(%rax,%rax,1)
movzbl %al,%edx
mov    %r13,%rdi
mov    %r15,%rsi
call   1030 <sprintf@plt>
movzbl (%r14,%rbx,1),%eax
test   %al,%al
je     1167 <string2hexString+0x57>
lea    0x1(%rbx),%rcx
add    $0x2,%r13
cmp    %r12,%rbx
mov    %rcx,%rbx
jb     1140 <string2hexString+0x30>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%02X\00"
define void @string2hexString(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %8
store i32 0, i32* %7
br label %9
9: ; preds = %23, %3
%10 = load i8*, i8** %4
%11 = load i32, i32* %7
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = load i8, i8* %13
%15 = zext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %9
%18 = load i32, i32* %7
%19 = load i32, i32* %6
%20 = icmp slt i32 %18, %19
br label %21
21: ; preds = %17, %9
%22 = phi i1 [ false, %9 ], [ %20, %17 ]
br i1 %22, label %23, label %38
23: ; preds = %21
%24 = load i8*, i8** %5
%25 = load i32, i32* %8
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8*, i8** %4
%29 = load i32, i32* %7
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i8, i8* %31
%33 = call i32 @sprintf(i8* %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %32)
%34 = load i32, i32* %7
%35 = add nsw i32 %34, 1
store i32 %35, i32* %7
%36 = load i32, i32* %8
%37 = add nsw i32 %36, 2
store i32 %37, i32* %8
br label %9
38: ; preds = %21
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%02X\00"
define void @string2hexString(i8* nocapture %0, i8* nocapture writeonly %1, i32 %2) {
%4 = load i8, i8* %0
%5 = icmp ne i8 %4, 0
%6 = icmp sgt i32 %2, 0
%7 = and i1 %5, %6
br i1 %7, label %8, label %23
8: ; preds = %3
%9 = zext i32 %2 to i64
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ 0, %8 ], [ %16, %10 ]
%12 = phi i64 [ 0, %8 ], [ %17, %10 ]
%13 = phi i8 [ %4, %8 ], [ %19, %10 ]
%14 = getelementptr inbounds i8, i8* %1, i64 %12
%15 = tail call i32 @sprintf(i8* dereferenceable(1) %14, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %13)
%16 = add nuw nsw i64 %11, 1
%17 = add nuw nsw i64 %12, 2
%18 = getelementptr inbounds i8, i8* %0, i64 %16
%19 = load i8, i8* %18
%20 = icmp ne i8 %19, 0
%21 = icmp ult i64 %16, %9
%22 = select i1 %20, i1 %21, i1 false
br i1 %22, label %10, label %23
23: ; preds = %10, %3
ret void
}