#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*/ assert(char *);
int /*<<< orphan*/ sprintf(char *, char *, char);
void string_to_hex(char *input, char *destination, size_t len) {
  assert(input);
  assert(destination);
  size_t i = 0;
  size_t j = 0;
  for (i = 0; i < len; i++) {
    sprintf(destination + j, "%02X ", input[i]);
    j += 3;
  }
  destination[j - 1] = '\0';
}


x86 assembly (clang, -O0):
<string_to_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1030 <assert@plt>
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11a9 <string_to_hex+0x89>
mov    -0x10(%rbp),%rdi
add    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
lea    0xe7d(%rip),%rsi
movsbl (%rax,%rcx,1),%edx
call   1040 <sprintf@plt>
mov    -0x28(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    115e <string_to_hex+0x3e>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_to_hex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r13
call   1030 <assert@plt>
mov    %rbx,%rdi
call   1030 <assert@plt>
test   %r15,%r15
je     118b <string_to_hex+0x6b>
mov    $0x1,%ebp
xor    %r14d,%r14d
lea    0xeab(%rip),%r12
mov    %rbx,(%rsp)
nopl   0x0(%rax)
movsbl 0x0(%r13,%r14,1),%edx
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <sprintf@plt>
add    $0x1,%r14
add    $0xfffffffffffffffd,%rbp
add    $0x3,%rbx
cmp    %r14,%r15
jne    1160 <string_to_hex+0x40>
neg    %rbp
mov    (%rsp),%rbx
jmp    1192 <string_to_hex+0x72>
mov    $0xffffffffffffffff,%rbp
movb   $0x0,(%rbx,%rbp,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c"%02X \00"
define void @string_to_hex(i8* %0, i8* %1, i64 %2) {
%4 = tail call i32 @assert(i8* %0)
%5 = tail call i32 @assert(i8* %1)
%6 = icmp eq i64 %2, 0
br i1 %6, label %19, label %7
7: ; preds = %3, %7
%8 = phi i64 [ %14, %7 ], [ 0, %3 ]
%9 = phi i64 [ %15, %7 ], [ 0, %3 ]
%10 = getelementptr inbounds i8, i8* %1, i64 %8
%11 = getelementptr inbounds i8, i8* %0, i64 %9
%12 = load i8, i8* %11
%13 = tail call i32 @sprintf(i8* dereferenceable(1) %10, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8 signext %12)
%14 = add i64 %8, 3
%15 = add nuw i64 %9, 1
%16 = icmp eq i64 %15, %2
br i1 %16, label %17, label %7
17: ; preds = %7
%18 = add i64 %8, 2
br label %19
19: ; preds = %17, %3
%20 = phi i64 [ -1, %3 ], [ %18, %17 ]
%21 = getelementptr inbounds i8, i8* %1, i64 %20
store i8 0, i8* %21
ret void
}