#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 *malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, char const);
char *fingerprintToHex(const void *ptr, int len) {
  int i;
  char *hex = malloc(len * 3 + 1);
  const char *mem = ptr;
  for (i = 0; i < len; ++i) {
    sprintf(hex + (i * 3), "%02X:", mem[i] & 0xFF);
  }
  hex[len * 3 - 1] = '\0';
  return hex;
}


x86 assembly (clang, -O0):
<fingerprintToHex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
imul   $0x3,-0xc(%rbp),%edi
add    $0x1,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1195 <fingerprintToHex+0x75>
mov    -0x18(%rbp),%rdi
imul   $0x3,-0x10(%rbp),%eax
cltq
add    %rax,%rdi
mov    -0x20(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
and    $0xff,%eax
lea    0xe81(%rip),%rsi
movsbl %al,%edx
call   1040 <sprintf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    114e <fingerprintToHex+0x2e>
mov    -0x18(%rbp),%rax
imul   $0x3,-0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fingerprintToHex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r12
movslq %esi,%rbp
lea    0x0(,%rbp,2),%rax
add    %rbp,%rax
mov    %rax,(%rsp)
lea    0x1(%rax),%edi
call   1030 <malloc@plt>
mov    %rax,%r14
test   %ebp,%ebp
jle    117d <fingerprintToHex+0x5d>
mov    %ebx,%ebp
xor    %r13d,%r13d
lea    0xea3(%rip),%r15
mov    %r14,%rbx
movsbl (%r12,%r13,1),%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <sprintf@plt>
add    $0x1,%r13
add    $0x3,%rbx
cmp    %r13,%rbp
jne    1160 <fingerprintToHex+0x40>
mov    (%rsp),%rax
movb   $0x0,-0x1(%rax,%r14,1)
mov    %r14,%rax
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 i8* @fingerprintToHex(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = load i32, i32* %4
%9 = mul nsw i32 %8, 3
%10 = add nsw i32 %9, 1
%11 = call i8* @malloc(i32 %10)
store i8* %11, i8** %6
%12 = load i8*, i8** %3
store i8* %12, i8** %7
store i32 0, i32* %5
br label %13
13: ; preds = %32, %2
%14 = load i32, i32* %5
%15 = load i32, i32* %4
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %35
17: ; preds = %13
%18 = load i8*, i8** %6
%19 = load i32, i32* %5
%20 = mul nsw i32 %19, 3
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %18, i64 %21
%23 = load i8*, i8** %7
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = and i32 %28, 255
%30 = trunc i32 %29 to i8
%31 = call i32 @sprintf(i8* %22, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8 signext %30)
br label %32
32: ; preds = %17
%33 = load i32, i32* %5
%34 = add nsw i32 %33, 1
store i32 %34, i32* %5
br label %13
35: ; preds = %13
%36 = load i8*, i8** %6
%37 = load i32, i32* %4
%38 = mul nsw i32 %37, 3
%39 = sub nsw i32 %38, 1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %36, i64 %40
store i8 0, i8* %41
%42 = load i8*, i8** %6
ret i8* %42
}

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