#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 *calloc(unsigned int, int);
int snprintf(char *, int, char *, unsigned char);
int /*<<< orphan*/ warnx(char *);
int md5toa(unsigned char *md_value, unsigned int md_len, char **md5_string) {
  unsigned int i, j;
  int rc;
  int hex_len = 3;
  unsigned int length = 32;
  *md5_string = calloc(length + 1, sizeof(char));
  if (*md5_string == NULL) {
    warnx("Can not allocate memory for md5 ascii hex string.");
    return -1;
  }
  for (i = 0, j = 0; i < md_len && j < length; i++, j += 2) {
    rc = snprintf((*md5_string) + j, hex_len, "%02x", md_value[i]);
    if (!(rc > -1 && rc < hex_len)) {
      warnx("Construction of md5 ascii hex string failed.");
      return -1;
    }
  }
  (*md5_string)[length] = '\0';
  return 0;
}


x86 assembly (clang, -O0):
<md5toa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x3,-0x30(%rbp)
movl   $0x20,-0x34(%rbp)
mov    -0x34(%rbp),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1191 <md5toa+0x61>
lea    0xe80(%rip),%rdi
call   1030 <warnx@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1255 <md5toa+0x125>
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x24(%rbp),%ecx
xor    %eax,%eax
cmp    -0x14(%rbp),%ecx
mov    %al,-0x35(%rbp)
jae    11bc <md5toa+0x8c>
mov    -0x28(%rbp),%eax
cmp    -0x34(%rbp),%eax
setb   %al
mov    %al,-0x35(%rbp)
mov    -0x35(%rbp),%al
test   $0x1,%al
jne    11cc <md5toa+0x9c>
jmp    1240 <md5toa+0x110>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
mov    -0x28(%rbp),%eax
add    %rax,%rdi
mov    -0x30(%rbp),%esi
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
lea    0xe48(%rip),%rdx
movzbl (%rax,%rcx,1),%ecx
call   1040 <snprintf@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jle    120c <md5toa+0xdc>
mov    -0x2c(%rbp),%eax
cmp    -0x30(%rbp),%eax
jl     1224 <md5toa+0xf4>
lea    0xe24(%rip),%rdi
call   1030 <warnx@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1255 <md5toa+0x125>
jmp    1229 <md5toa+0xf9>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x28(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x28(%rbp)
jmp    119f <md5toa+0x6f>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    -0x34(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<md5toa>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %esi,%ebp
mov    %rdi,%r14
mov    $0x21,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,(%r12)
test   %rax,%rax
je     11e5 <md5toa+0xb5>
test   %ebp,%ebp
je     11fc <md5toa+0xcc>
add    $0xffffffff,%ebp
cmp    $0xf,%ebp
mov    $0xf,%r13d
cmovb  %ebp,%r13d
movzbl (%r14),%ecx
lea    0xeb0(%rip),%rdx
mov    %rax,%rdi
mov    $0x3,%esi
call   1040 <snprintf@plt>
cmp    $0x2,%eax
ja     11dc <md5toa+0xac>
add    $0x1,%r13d
add    $0xffffffffffffffff,%r13
mov    $0x2,%ebp
xor    %ebx,%ebx
lea    0xe88(%rip),%r15
nopw   0x0(%rax,%rax,1)
cmp    %rbx,%r13
je     11f8 <md5toa+0xc8>
mov    (%r12),%rdi
add    %rbp,%rdi
movzbl 0x1(%r14,%rbx,1),%ecx
mov    $0x3,%esi
mov    %r15,%rdx
call   1040 <snprintf@plt>
add    $0x2,%rbp
add    $0x1,%rbx
cmp    $0x3,%eax
jb     11b0 <md5toa+0x80>
lea    0xe54(%rip),%rdi
jmp    11ec <md5toa+0xbc>
lea    0xe14(%rip),%rdi
call   1030 <warnx@plt>
mov    $0xffffffff,%eax
jmp    1202 <md5toa+0xd2>
mov    (%r12),%rax
movb   $0x0,0x20(%rax)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [50 x i8] c"Can not allocate memory for md5 ascii hex string.\00"
@.str.1 = [5 x i8] c"%02x\00"
@.str.2 = [45 x i8] c"Construction of md5 ascii hex string failed.\00"
define i32 @md5toa(i8* %0, i32 %1, i8** %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8** %2, i8*** %7
store i32 3, i32* %11
store i32 32, i32* %12
%13 = load i32, i32* %12
%14 = add i32 %13, 1
%15 = call i8* @calloc(i32 %14, i32 1)
%16 = load i8**, i8*** %7
store i8* %15, i8** %16
%17 = load i8**, i8*** %7
%18 = load i8*, i8** %17
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %22
20: ; preds = %3
%21 = call i32 @warnx(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %66
22: ; preds = %3
store i32 0, i32* %8
store i32 0, i32* %9
br label %23
23: ; preds = %55, %22
%24 = load i32, i32* %8
%25 = load i32, i32* %6
%26 = icmp ult i32 %24, %25
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = load i32, i32* %9
%29 = load i32, i32* %12
%30 = icmp ult i32 %28, %29
br label %31
31: ; preds = %27, %23
%32 = phi i1 [ false, %23 ], [ %30, %27 ]
br i1 %32, label %33, label %60
33: ; preds = %31
%34 = load i8**, i8*** %7
%35 = load i8*, i8** %34
%36 = load i32, i32* %9
%37 = zext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = load i32, i32* %11
%40 = load i8*, i8** %5
%41 = load i32, i32* %8
%42 = zext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
%44 = load i8, i8* %43
%45 = call i32 @snprintf(i8* %38, i32 %39, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %44)
store i32 %45, i32* %10
%46 = load i32, i32* %10
%47 = icmp sgt i32 %46, -1
br i1 %47, label %48, label %52
48: ; preds = %33
%49 = load i32, i32* %10
%50 = load i32, i32* %11
%51 = icmp slt i32 %49, %50
br i1 %51, label %54, label %52
52: ; preds = %48, %33
%53 = call i32 @warnx(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %4
br label %66
54: ; preds = %48
br label %55
55: ; preds = %54
%56 = load i32, i32* %8
%57 = add i32 %56, 1
store i32 %57, i32* %8
%58 = load i32, i32* %9
%59 = add i32 %58, 2
store i32 %59, i32* %9
br label %23
60: ; preds = %31
%61 = load i8**, i8*** %7
%62 = load i8*, i8** %61
%63 = load i32, i32* %12
%64 = zext i32 %63 to i64
%65 = getelementptr inbounds i8, i8* %62, i64 %64
store i8 0, i8* %65
store i32 0, i32* %4
br label %66
66: ; preds = %60, %52, %20
%67 = load i32, i32* %4
ret i32 %67
}

LLVM IR (-O2):
@.str = [50 x i8] c"Can not allocate memory for md5 ascii hex string.\00"
@.str.1 = [5 x i8] c"%02x\00"
@.str.2 = [45 x i8] c"Construction of md5 ascii hex string failed.\00"
define i32 @md5toa(i8* nocapture %0, i32 %1, i8** nocapture %2) {
%4 = tail call dereferenceable_or_null(33) i8* @calloc(i32 33, i32 1)
store i8* %4, i8** %2
%5 = icmp eq i8* %4, null
br i1 %5, label %16, label %6
6: ; preds = %3
%7 = icmp eq i32 %1, 0
br i1 %7, label %35, label %8
8: ; preds = %6
%9 = add i32 %1, -1
%10 = call i32 @llvm.umin.i32(i32 %9, i32 15)
%11 = add nuw nsw i32 %10, 1
%12 = zext i32 %11 to i64
%13 = load i8, i8* %0
%14 = tail call i32 @snprintf(i8* %4, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %13)
%15 = icmp ult i32 %14, 3
br i1 %15, label %20, label %18
16: ; preds = %3
%17 = tail call i32 @warnx(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
br label %38
18: ; preds = %25, %8
%19 = tail call i32 @warnx(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0))
br label %38
20: ; preds = %8, %25
%21 = phi i64 [ %23, %25 ], [ 0, %8 ]
%22 = phi i64 [ %26, %25 ], [ 0, %8 ]
%23 = add nuw nsw i64 %21, 1
%24 = icmp eq i64 %23, %12
br i1 %24, label %33, label %25
25: ; preds = %20
%26 = add nuw nsw i64 %22, 2
%27 = load i8*, i8** %2
%28 = getelementptr inbounds i8, i8* %27, i64 %26
%29 = getelementptr inbounds i8, i8* %0, i64 %23
%30 = load i8, i8* %29
%31 = tail call i32 @snprintf(i8* %28, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %30)
%32 = icmp ult i32 %31, 3
br i1 %32, label %20, label %18
33: ; preds = %20
%34 = load i8*, i8** %2
br label %35
35: ; preds = %33, %6
%36 = phi i8* [ %34, %33 ], [ %4, %6 ]
%37 = getelementptr inbounds i8, i8* %36, i64 32
store i8 0, i8* %37
br label %38
38: ; preds = %35, %18, %16
%39 = phi i32 [ -1, %16 ], [ -1, %18 ], [ 0, %35 ]
ret i32 %39
}