#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(unsigned char const *, int, unsigned char *);
int MD5_DIGEST_LENGTH;
scalar_t__ malloc(int);
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned int);
char *strmd5(const unsigned char *str, int len) {
  size_t output_len = MD5_DIGEST_LENGTH * 2;
  unsigned char output[output_len];
  char *res = (char *)malloc(sizeof(char) * (output_len + 1));
  MD5(str, len, output);
  for (int i = 0; i < MD5_DIGEST_LENGTH; ++i) {
    snprintf(&(res[i * 2]), MD5_DIGEST_LENGTH + 1, "%02x",
             (unsigned int)output[i]);
  }
  return res;
}


x86 assembly (clang, -O0):
<strmd5>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0x2e9a(%rip),%rax
mov    (%rax),%eax
add    %eax,%eax
cltq
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    -0x40(%rbp),%rdx
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <MD5@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    0x2e31(%rip),%rcx
cmp    (%rcx),%eax
jge    11f9 <strmd5+0xc9>
mov    -0x40(%rbp),%rax
mov    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
add    %rcx,%rdi
mov    0x2e0e(%rip),%rcx
mov    (%rcx),%esi
add    $0x1,%esi
movslq -0x34(%rbp),%rcx
movzbl (%rax,%rcx,1),%ecx
lea    0xe1a(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11a5 <strmd5+0x75>
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strmd5>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%rbx
mov    0x2e95(%rip),%r13
movslq 0x0(%r13),%rax
lea    (%rax,%rax,1),%rdi
mov    %rsp,%r12
add    %rax,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
or     $0x1,%edi
call   1040 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %r12,%rdx
call   1050 <MD5@plt>
mov    0x0(%r13),%esi
test   %esi,%esi
jle    11c4 <strmd5+0x94>
xor    %r14d,%r14d
lea    0xe6d(%rip),%r15
mov    -0x30(%rbp),%rbx
nopw   0x0(%rax,%rax,1)
add    $0x1,%esi
movzbl (%r12,%r14,1),%ecx
mov    %rbx,%rdi
mov    %r15,%rdx
call   1030 <snprintf@plt>
add    $0x1,%r14
movslq 0x0(%r13),%rsi
add    $0x2,%rbx
cmp    %rsi,%r14
jl     11a0 <strmd5+0x70>
mov    -0x30(%rbp),%rax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@MD5_DIGEST_LENGTH = global i32 0
@.str = [5 x i8] c"%02x\00"
define i8* @strmd5(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%10 = load i32, i32* @MD5_DIGEST_LENGTH
%11 = mul nsw i32 %10, 2
%12 = sext i32 %11 to i64
store i64 %12, i64* %5
%13 = load i64, i64* %5
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %6
%15 = alloca i8, i64 %13
store i64 %13, i64* %7
%16 = load i64, i64* %5
%17 = add i64 %16, 1
%18 = mul i64 1, %17
%19 = trunc i64 %18 to i32
%20 = call i64 @malloc(i32 %19)
%21 = inttoptr i64 %20 to i8*
store i8* %21, i8** %8
%22 = load i8*, i8** %3
%23 = load i32, i32* %4
%24 = call i32 @MD5(i8* %22, i32 %23, i8* %15)
store i32 0, i32* %9
br label %25
25: ; preds = %43, %2
%26 = load i32, i32* %9
%27 = load i32, i32* @MD5_DIGEST_LENGTH
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %46
29: ; preds = %25
%30 = load i8*, i8** %8
%31 = load i32, i32* %9
%32 = mul nsw i32 %31, 2
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %30, i64 %33
%35 = load i32, i32* @MD5_DIGEST_LENGTH
%36 = add nsw i32 %35, 1
%37 = load i32, i32* %9
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %15, i64 %38
%40 = load i8, i8* %39
%41 = zext i8 %40 to i32
%42 = call i32 @snprintf(i8* %34, i32 %36, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %41)
br label %43
43: ; preds = %29
%44 = load i32, i32* %9
%45 = add nsw i32 %44, 1
store i32 %45, i32* %9
br label %25
46: ; preds = %25
%47 = load i8*, i8** %8
%48 = load i8*, i8** %6
ret i8* %47
}

LLVM IR (-O2):
@MD5_DIGEST_LENGTH = global i32 0
@.str = [5 x i8] c"%02x\00"
define i8* @strmd5(i8* %0, i32 %1) {
%3 = load i32, i32* @MD5_DIGEST_LENGTH
%4 = shl nsw i32 %3, 1
%5 = sext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = or i32 %4, 1
%8 = tail call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to i8*
%10 = call i32 @MD5(i8* %0, i32 %1, i8* %6)
%11 = load i32, i32* @MD5_DIGEST_LENGTH
%12 = icmp sgt i32 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %14, %2
ret i8* %9
14: ; preds = %2, %14
%15 = phi i64 [ %24, %14 ], [ 0, %2 ]
%16 = phi i32 [ %25, %14 ], [ %11, %2 ]
%17 = shl nuw nsw i64 %15, 1
%18 = getelementptr inbounds i8, i8* %9, i64 %17
%19 = add nsw i32 %16, 1
%20 = getelementptr inbounds i8, i8* %6, i64 %15
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = call i32 @snprintf(i8* %18, i32 %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %22)
%24 = add nuw nsw i64 %15, 1
%25 = load i32, i32* @MD5_DIGEST_LENGTH
%26 = sext i32 %25 to i64
%27 = icmp slt i64 %24, %26
br i1 %27, label %14, label %13
}