#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 */
typedef int /*<<< orphan*/ MD5_CTX;

/* Variables and functions */
int /*<<< orphan*/ MD5_Final(unsigned char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ MD5_Init(int /*<<< orphan*/ *);
int /*<<< orphan*/ MD5_Update(int /*<<< orphan*/ *, char const *, size_t);
scalar_t__ malloc(int);
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned int);
char *md5(const char *str, size_t len) {
  MD5_CTX ctx;
  unsigned char digest[16];
  char *out = (char *)malloc(33);
  MD5_Init(&ctx);
  MD5_Update(&ctx, str, len);
  MD5_Final(digest, &ctx);
  for (int i = 0; i < 16; i++) {
    snprintf(&(out[i * 2]), 3, "%02x", (unsigned int)digest[i]);
  }
  return out;
}


x86 assembly (clang, -O0):
<md5>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x21,%edi
call   1050 <malloc@plt>
mov    %rax,-0x38(%rbp)
lea    -0x14(%rbp),%rdi
call   1060 <MD5_Init@plt>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    -0x14(%rbp),%rdi
call   1070 <MD5_Update@plt>
lea    -0x30(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1030 <MD5_Final@plt>
movl   $0x0,-0x3c(%rbp)
cmpl   $0x10,-0x3c(%rbp)
jge    11dd <md5+0x8d>
mov    -0x38(%rbp),%rdi
mov    -0x3c(%rbp),%eax
shl    $0x1,%eax
cltq
add    %rax,%rdi
movslq -0x3c(%rbp),%rax
movzbl -0x30(%rbp,%rax,1),%ecx
mov    $0x3,%esi
lea    0xe36(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    119c <md5+0x4c>
mov    -0x38(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<md5>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x21,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0x14(%rsp),%r12
mov    %r12,%rdi
call   1060 <MD5_Init@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1070 <MD5_Update@plt>
mov    %rsp,%rdi
mov    %r12,%rsi
call   1030 <MD5_Final@plt>
movzbl (%rsp),%ecx
lea    0xe61(%rip),%r14
mov    %rbx,%rdi
mov    $0x3,%esi
mov    %r14,%rdx
call   1040 <snprintf@plt>
lea    0x2(%rbx),%rdi
movzbl 0x1(%rsp),%ecx
mov    $0x3,%esi
mov    %r14,%rdx
call   1040 <snprintf@plt>
lea    0x4(%rbx),%rdi
movzbl 0x2(%rsp),%ecx
mov    $0x3,%esi
mov    %r14,%rdx
call   1040 <snprintf@plt>
lea    0x6(%rbx),%rdi
movzbl 0x3(%rsp),%ecx
mov    $0x3,%esi
mov    %r14,%rdx
call   1040 <snprintf@plt>
lea    0x8(%rbx),%rdi
movzbl 0x4(%rsp),%ecx
mov    $0x3,%esi
mov    %r14,%rdx
call   1040 <snprintf@plt>
lea    0xa(%rbx),%rdi
movzbl 0x5(%rsp),%ecx
mov    $0x3,%esi
mov    %r14,%rdx
call   1040 <snprintf@plt>
lea    0xc(%rbx),%rdi
movzbl 0x6(%rsp),%ecx
mov    $0x3,%esi
mov    %r14,%rdx
call   1040 <snprintf@plt>
lea    0xe(%rbx),%rdi
movzbl 0x7(%rsp),%ecx
mov    $0x3,%esi
mov    %r14,%rdx
call   1040 <snprintf@plt>
lea    0x10(%rbx),%rdi
movzbl 0x8(%rsp),%ecx
mov    $0x3,%esi
mov    %r14,%rdx
call   1040 <snprintf@plt>
lea    0x12(%rbx),%rdi
movzbl 0x9(%rsp),%ecx
mov    $0x3,%esi
mov    %r14,%rdx
call   1040 <snprintf@plt>
lea    0x14(%rbx),%rdi
movzbl 0xa(%rsp),%ecx
mov    $0x3,%esi
mov    %r14,%rdx
call   1040 <snprintf@plt>
lea    0x16(%rbx),%rdi
movzbl 0xb(%rsp),%ecx
mov    $0x3,%esi
mov    %r14,%rdx
call   1040 <snprintf@plt>
lea    0x18(%rbx),%rdi
movzbl 0xc(%rsp),%ecx
mov    $0x3,%esi
mov    %r14,%rdx
call   1040 <snprintf@plt>
lea    0x1a(%rbx),%rdi
movzbl 0xd(%rsp),%ecx
mov    $0x3,%esi
mov    %r14,%rdx
call   1040 <snprintf@plt>
lea    0x1c(%rbx),%rdi
movzbl 0xe(%rsp),%ecx
mov    $0x3,%esi
mov    %r14,%rdx
call   1040 <snprintf@plt>
lea    0x1e(%rbx),%rdi
movzbl 0xf(%rsp),%ecx
mov    $0x3,%esi
mov    %r14,%rdx
call   1040 <snprintf@plt>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%02x\00"
define i8* @md5(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca [16 x i8]
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %3
store i64 %1, i64* %4
%9 = call i64 @malloc(i32 33)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %7
%11 = call i32 @MD5_Init(i32* %5)
%12 = load i8*, i8** %3
%13 = load i64, i64* %4
%14 = call i32 @MD5_Update(i32* %5, i8* %12, i64 %13)
%15 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%16 = call i32 @MD5_Final(i8* %15, i32* %5)
store i32 0, i32* %8
br label %17
17: ; preds = %32, %2
%18 = load i32, i32* %8
%19 = icmp slt i32 %18, 16
br i1 %19, label %20, label %35
20: ; preds = %17
%21 = load i8*, i8** %7
%22 = load i32, i32* %8
%23 = mul nsw i32 %22, 2
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %21, i64 %24
%26 = load i32, i32* %8
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = zext i8 %29 to i32
%31 = call i32 @snprintf(i8* %25, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %20
%33 = load i32, i32* %8
%34 = add nsw i32 %33, 1
store i32 %34, i32* %8
br label %17
35: ; preds = %17
%36 = load i8*, i8** %7
ret i8* %36
}

LLVM IR (-O2):
@.str = [5 x i8] c"%02x\00"
define i8* @md5(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca [16 x i8]
%5 = bitcast i32* %3 to i8*
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%7 = tail call i64 @malloc(i32 33)
%8 = inttoptr i64 %7 to i8*
%9 = call i32 @MD5_Init(i32* %3)
%10 = call i32 @MD5_Update(i32* %3, i8* %0, i64 %1)
%11 = call i32 @MD5_Final(i8* %6, i32* %3)
%12 = load i8, i8* %6
%13 = zext i8 %12 to i32
%14 = call i32 @snprintf(i8* %8, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = getelementptr inbounds i8, i8* %8, i64 2
%16 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 1
%17 = load i8, i8* %16
%18 = zext i8 %17 to i32
%19 = call i32 @snprintf(i8* %15, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = getelementptr inbounds i8, i8* %8, i64 4
%21 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 2
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
%24 = call i32 @snprintf(i8* %20, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %23)
%25 = getelementptr inbounds i8, i8* %8, i64 6
%26 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 3
%27 = load i8, i8* %26
%28 = zext i8 %27 to i32
%29 = call i32 @snprintf(i8* %25, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %28)
%30 = getelementptr inbounds i8, i8* %8, i64 8
%31 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 4
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
%34 = call i32 @snprintf(i8* %30, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %33)
%35 = getelementptr inbounds i8, i8* %8, i64 10
%36 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 5
%37 = load i8, i8* %36
%38 = zext i8 %37 to i32
%39 = call i32 @snprintf(i8* %35, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %38)
%40 = getelementptr inbounds i8, i8* %8, i64 12
%41 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 6
%42 = load i8, i8* %41
%43 = zext i8 %42 to i32
%44 = call i32 @snprintf(i8* %40, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %43)
%45 = getelementptr inbounds i8, i8* %8, i64 14
%46 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 7
%47 = load i8, i8* %46
%48 = zext i8 %47 to i32
%49 = call i32 @snprintf(i8* %45, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %48)
%50 = getelementptr inbounds i8, i8* %8, i64 16
%51 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 8
%52 = load i8, i8* %51
%53 = zext i8 %52 to i32
%54 = call i32 @snprintf(i8* %50, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %53)
%55 = getelementptr inbounds i8, i8* %8, i64 18
%56 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 9
%57 = load i8, i8* %56
%58 = zext i8 %57 to i32
%59 = call i32 @snprintf(i8* %55, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %58)
%60 = getelementptr inbounds i8, i8* %8, i64 20
%61 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 10
%62 = load i8, i8* %61
%63 = zext i8 %62 to i32
%64 = call i32 @snprintf(i8* %60, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %63)
%65 = getelementptr inbounds i8, i8* %8, i64 22
%66 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 11
%67 = load i8, i8* %66
%68 = zext i8 %67 to i32
%69 = call i32 @snprintf(i8* %65, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %68)
%70 = getelementptr inbounds i8, i8* %8, i64 24
%71 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 12
%72 = load i8, i8* %71
%73 = zext i8 %72 to i32
%74 = call i32 @snprintf(i8* %70, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %73)
%75 = getelementptr inbounds i8, i8* %8, i64 26
%76 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 13
%77 = load i8, i8* %76
%78 = zext i8 %77 to i32
%79 = call i32 @snprintf(i8* %75, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %78)
%80 = getelementptr inbounds i8, i8* %8, i64 28
%81 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 14
%82 = load i8, i8* %81
%83 = zext i8 %82 to i32
%84 = call i32 @snprintf(i8* %80, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %83)
%85 = getelementptr inbounds i8, i8* %8, i64 30
%86 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 15
%87 = load i8, i8* %86
%88 = zext i8 %87 to i32
%89 = call i32 @snprintf(i8* %85, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %88)
ret i8* %8
}