#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*/ md5_hash(char *, unsigned char *);
int /*<<< orphan*/ sprintf(unsigned char *, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
void md5_hash_hex_ex(char *in, char *out, int size) {
  int i = 0, count = 0;
  unsigned char digest[16], buf[3];
  md5_hash(in, digest);
  for (i = 0; i < 16; i++, count += 2) {
    if (count > size)
      break;
    sprintf(buf, "%.2x", (int)digest[i]);
    (i == 0) ? strcpy(out, (char *)buf) : strcat(out, (char *)buf);
  }
  out[size - 1] = '\0';
}


x86 assembly (clang, -O0):
<md5_hash_hex_ex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1040 <md5_hash@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x10,-0x18(%rbp)
jge    11e9 <md5_hash_hex_ex+0xa9>
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    1190 <md5_hash_hex_ex+0x50>
jmp    11e9 <md5_hash_hex_ex+0xa9>
lea    -0x33(%rbp),%rdi
movslq -0x18(%rbp),%rax
movzbl -0x30(%rbp,%rax,1),%edx
lea    0xe5c(%rip),%rsi
call   1060 <sprintf@plt>
cmpl   $0x0,-0x18(%rbp)
jne    11c5 <md5_hash_hex_ex+0x85>
mov    -0x10(%rbp),%rdi
lea    -0x33(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    11d2 <md5_hash_hex_ex+0x92>
mov    -0x10(%rbp),%rdi
lea    -0x33(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x1c(%rbp)
jmp    1175 <md5_hash_hex_ex+0x35>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<md5_hash_hex_ex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edx,%r12d
mov    %rsi,%r15
lea    0x10(%rsp),%rsi
call   1040 <md5_hash@plt>
test   %r12d,%r12d
js     11df <md5_hash_hex_ex+0x9f>
movzbl 0x10(%rsp),%edx
lea    0xe91(%rip),%rsi
lea    0xd(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <sprintf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
cmp    $0x2,%r12d
jb     11df <md5_hash_hex_ex+0x9f>
mov    $0x1,%ebp
mov    $0x4,%ebx
lea    0xe62(%rip),%r14
lea    0xd(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl 0x10(%rsp,%rbp,1),%edx
mov    %r13,%rdi
mov    %r14,%rsi
call   1060 <sprintf@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   1050 <strcat@plt>
cmp    $0xe,%rbp
ja     11df <md5_hash_hex_ex+0x9f>
add    $0x1,%rbp
lea    0x2(%rbx),%eax
cmp    %r12d,%ebx
mov    %eax,%ebx
jle    11b0 <md5_hash_hex_ex+0x70>
movslq %r12d,%rax
movb   $0x0,-0x1(%rax,%r15,1)
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%.2x\00"
define void @md5_hash_hex_ex(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [16 x i8]
%10 = alloca [3 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
%11 = load i8*, i8** %4
%12 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%13 = call i32 @md5_hash(i8* %11, i8* %12)
store i32 0, i32* %7
br label %14
14: ; preds = %42, %3
%15 = load i32, i32* %7
%16 = icmp slt i32 %15, 16
br i1 %16, label %17, label %47
17: ; preds = %14
%18 = load i32, i32* %8
%19 = load i32, i32* %6
%20 = icmp sgt i32 %18, %19
br i1 %20, label %21, label %22
21: ; preds = %17
br label %47
22: ; preds = %17
%23 = getelementptr inbounds [3 x i8], [3 x i8]* %10, i64 0, i64 0
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = zext i8 %27 to i32
%29 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %28)
%30 = load i32, i32* %7
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %22
%33 = load i8*, i8** %5
%34 = getelementptr inbounds [3 x i8], [3 x i8]* %10, i64 0, i64 0
%35 = call i32 @strcpy(i8* %33, i8* %34)
br label %40
36: ; preds = %22
%37 = load i8*, i8** %5
%38 = getelementptr inbounds [3 x i8], [3 x i8]* %10, i64 0, i64 0
%39 = call i32 @strcat(i8* %37, i8* %38)
br label %40
40: ; preds = %36, %32
%41 = phi i32 [ %35, %32 ], [ %39, %36 ]
br label %42
42: ; preds = %40
%43 = load i32, i32* %7
%44 = add nsw i32 %43, 1
store i32 %44, i32* %7
%45 = load i32, i32* %8
%46 = add nsw i32 %45, 2
store i32 %46, i32* %8
br label %14
47: ; preds = %21, %14
%48 = load i8*, i8** %5
%49 = load i32, i32* %6
%50 = sub nsw i32 %49, 1
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %48, i64 %51
store i8 0, i8* %52
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%.2x\00"
define void @md5_hash_hex_ex(i8* %0, i8* %1, i32 %2) {
%4 = alloca [16 x i8]
%5 = alloca [3 x i8]
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%8 = call i32 @md5_hash(i8* %0, i8* %6)
%9 = icmp slt i32 %2, 0
br i1 %9, label %29, label %10
10: ; preds = %3
%11 = load i8, i8* %6
%12 = zext i8 %11 to i32
%13 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = call i32 @strcpy(i8* %1, i8* %7)
%15 = icmp ult i32 %2, 2
br i1 %15, label %29, label %16
16: ; preds = %10, %16
%17 = phi i64 [ %24, %16 ], [ 1, %10 ]
%18 = phi i32 [ %25, %16 ], [ 2, %10 ]
%19 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 %17
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %21)
%23 = call i32 @strcat(i8* %1, i8* %7)
%24 = add nuw nsw i64 %17, 1
%25 = add nuw nsw i32 %18, 2
%26 = icmp ugt i64 %17, 14
%27 = icmp sgt i32 %25, %2
%28 = select i1 %26, i1 true, i1 %27
br i1 %28, label %29, label %16
29: ; preds = %16, %10, %3
%30 = add nsw i32 %2, -1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %1, i64 %31
store i8 0, i8* %32
ret void
}