#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);
const char *MD5ToString(const unsigned char *hash, char *dst) {
  char hexchar[3];
  short i = 0, n = 0;
  for (i = 0; i < 16; i++) {
    sprintf(hexchar, "%02X", hash[i]);
    dst[n++] = hexchar[0];
    dst[n++] = hexchar[1];
  }
  dst[n] = 0x00;
  return dst;
}


x86 assembly (clang, -O0):
<MD5ToString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movw   $0x0,-0x16(%rbp)
movw   $0x0,-0x18(%rbp)
movw   $0x0,-0x16(%rbp)
movswl -0x16(%rbp),%eax
cmp    $0x10,%eax
jge    11a7 <MD5ToString+0x97>
lea    -0x13(%rbp),%rdi
mov    -0x8(%rbp),%rax
movswq -0x16(%rbp),%rcx
lea    0xead(%rip),%rsi
movzbl (%rax,%rcx,1),%edx
call   1030 <sprintf@plt>
mov    -0x13(%rbp),%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%cx
mov    %cx,%si
add    $0x1,%si
mov    %si,-0x18(%rbp)
movswq %cx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x12(%rbp),%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%cx
mov    %cx,%si
add    $0x1,%si
mov    %si,-0x18(%rbp)
movswq %cx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x16(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x16(%rbp)
jmp    1132 <MD5ToString+0x22>
mov    -0x10(%rbp),%rax
movswq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MD5ToString>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r13
mov    %rdi,%r14
xor    %ebx,%ebx
lea    0xed4(%rip),%r15
lea    0xd(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%r14,%rbx,1),%edx
mov    %r12,%rdi
mov    %r15,%rsi
call   1030 <sprintf@plt>
movzbl 0xd(%rsp),%eax
mov    %al,0x0(%r13,%rbx,2)
movzbl 0xe(%rsp),%eax
mov    %al,0x1(%r13,%rbx,2)
add    $0x1,%rbx
cmp    $0x10,%rbx
jne    1140 <MD5ToString+0x30>
movb   $0x0,0x20(%r13)
mov    %r13,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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