#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 *, char *, unsigned int);
void RSA_hexEncode(char *data, int len, char *des) {
  des[0] = 0;
  for (int i = 0; i < len; i++) {
    char c = data[i];
    unsigned int hi = ((c & 0xF0) >> 4) & 0x0F;
    unsigned int low = c & 0x0F;
    sprintf(des, "%s%X", des, hi);
    sprintf(des, "%s%X", des, low);
  }
}


x86 assembly (clang, -O0):
<RSA_hexEncode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a3 <RSA_hexEncode+0x93>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x1d(%rbp)
movsbl -0x1d(%rbp),%eax
and    $0xf0,%eax
sar    $0x4,%eax
and    $0xf,%eax
mov    %eax,-0x24(%rbp)
movsbl -0x1d(%rbp),%eax
and    $0xf,%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x24(%rbp),%ecx
lea    0xe87(%rip),%rsi
call   1030 <sprintf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%ecx
lea    0xe70(%rip),%rsi
call   1030 <sprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1131 <RSA_hexEncode+0x21>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RSA_hexEncode>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movb   $0x0,(%rdx)
test   %esi,%esi
jle    1174 <RSA_hexEncode+0x64>
mov    %rdx,%r13
mov    %rdi,%r14
mov    %esi,%r12d
xor    %ebx,%ebx
lea    0xecc(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl (%r14,%rbx,1),%ebp
mov    %ebp,%ecx
shr    $0x4,%ecx
and    $0xf,%ebp
mov    %r13,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   1030 <sprintf@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
mov    %ebp,%ecx
call   1030 <sprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1140 <RSA_hexEncode+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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