#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 *, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned int);
char *str2md5(const char *str, int length) {
  int n;
  MD5_CTX c;
  unsigned char digest[16];
  char *out = (char *)malloc(33);
  MD5_Init(&c);
  while (length > 0) {
    if (length > 512) {
      MD5_Update(&c, str, 512);
    } else {
      MD5_Update(&c, str, length);
    }
    length -= 512;
    str += 512;
  }
  MD5_Final(digest, &c);
  for (n = 0; n < 16; ++n) {
    snprintf(&(out[n * 2]), 16 * 2, "%02x", (unsigned int)digest[n]);
  }
  return out;
}


x86 assembly (clang, -O0):
<str2md5>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x21,%edi
call   1050 <malloc@plt>
mov    %rax,-0x38(%rbp)
lea    -0x14(%rbp),%rdi
call   1060 <MD5_Init@plt>
cmpl   $0x0,-0xc(%rbp)
jle    11d2 <str2md5+0x82>
cmpl   $0x200,-0xc(%rbp)
jle    11a4 <str2md5+0x54>
mov    -0x8(%rbp),%rsi
lea    -0x14(%rbp),%rdi
mov    $0x200,%edx
call   1070 <MD5_Update@plt>
jmp    11b4 <str2md5+0x64>
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    -0x14(%rbp),%rdi
call   1070 <MD5_Update@plt>
mov    -0xc(%rbp),%eax
sub    $0x200,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
add    $0x200,%rax
mov    %rax,-0x8(%rbp)
jmp    1176 <str2md5+0x26>
lea    -0x30(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1030 <MD5_Final@plt>
movl   $0x0,-0x10(%rbp)
cmpl   $0x10,-0x10(%rbp)
jge    1227 <str2md5+0xd7>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%eax
shl    $0x1,%eax
cltq
add    %rax,%rdi
movslq -0x10(%rbp),%rax
movzbl -0x30(%rbp,%rax,1),%ecx
mov    $0x20,%esi
lea    0xdec(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11e6 <str2md5+0x96>
mov    -0x38(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str2md5>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebp
mov    %rdi,%rbx
mov    $0x21,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
lea    0x14(%rsp),%rdi
call   1060 <MD5_Init@plt>
test   %ebp,%ebp
jle    11c4 <str2md5+0x74>
cmp    $0x201,%ebp
jb     11b5 <str2md5+0x65>
lea    0x14(%rsp),%r14
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x200,%edx
call   1070 <MD5_Update@plt>
add    $0xfffffe00,%ebp
add    $0x200,%rbx
cmp    $0x200,%ebp
ja     1190 <str2md5+0x40>
lea    0x14(%rsp),%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1070 <MD5_Update@plt>
mov    %rsp,%rdi
lea    0x14(%rsp),%rsi
call   1030 <MD5_Final@plt>
movzbl (%rsp),%ecx
lea    0xe24(%rip),%r14
mov    %r15,%rdi
mov    $0x20,%esi
mov    %r14,%rdx
call   1040 <snprintf@plt>
lea    0x2(%r15),%rdi
movzbl 0x1(%rsp),%ecx
mov    $0x20,%esi
mov    %r14,%rdx
call   1040 <snprintf@plt>
lea    0x4(%r15),%rdi
movzbl 0x2(%rsp),%ecx
mov    $0x20,%esi
mov    %r14,%rdx
call   1040 <snprintf@plt>
lea    0x6(%r15),%rdi
movzbl 0x3(%rsp),%ecx
mov    $0x20,%esi
mov    %r14,%rdx
call   1040 <snprintf@plt>
lea    0x8(%r15),%rdi
movzbl 0x4(%rsp),%ecx
mov    $0x20,%esi
mov    %r14,%rdx
call   1040 <snprintf@plt>
lea    0xa(%r15),%rdi
movzbl 0x5(%rsp),%ecx
mov    $0x20,%esi
mov    %r14,%rdx
call   1040 <snprintf@plt>
lea    0xc(%r15),%rdi
movzbl 0x6(%rsp),%ecx
mov    $0x20,%esi
mov    %r14,%rdx
call   1040 <snprintf@plt>
lea    0xe(%r15),%rdi
movzbl 0x7(%rsp),%ecx
mov    $0x20,%esi
mov    %r14,%rdx
call   1040 <snprintf@plt>
lea    0x10(%r15),%rdi
movzbl 0x8(%rsp),%ecx
mov    $0x20,%esi
mov    %r14,%rdx
call   1040 <snprintf@plt>
lea    0x12(%r15),%rdi
movzbl 0x9(%rsp),%ecx
mov    $0x20,%esi
mov    %r14,%rdx
call   1040 <snprintf@plt>
lea    0x14(%r15),%rdi
movzbl 0xa(%rsp),%ecx
mov    $0x20,%esi
mov    %r14,%rdx
call   1040 <snprintf@plt>
lea    0x16(%r15),%rdi
movzbl 0xb(%rsp),%ecx
mov    $0x20,%esi
mov    %r14,%rdx
call   1040 <snprintf@plt>
lea    0x18(%r15),%rdi
movzbl 0xc(%rsp),%ecx
mov    $0x20,%esi
mov    %r14,%rdx
call   1040 <snprintf@plt>
lea    0x1a(%r15),%rdi
movzbl 0xd(%rsp),%ecx
mov    $0x20,%esi
mov    %r14,%rdx
call   1040 <snprintf@plt>
lea    0x1c(%r15),%rdi
movzbl 0xe(%rsp),%ecx
mov    $0x20,%esi
mov    %r14,%rdx
call   1040 <snprintf@plt>
mov    %r15,%rdi
add    $0x1e,%rdi
movzbl 0xf(%rsp),%ecx
mov    $0x20,%esi
mov    %r14,%rdx
call   1040 <snprintf@plt>
mov    %r15,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c"%02x\00"
define i8* @str2md5(i8* %0, i32 %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 = icmp sgt i32 %1, 0
br i1 %10, label %11, label %24
11: ; preds = %2
%12 = icmp ugt i32 %1, 512
br i1 %12, label %13, label %20
13: ; preds = %11, %13
%14 = phi i32 [ %17, %13 ], [ %1, %11 ]
%15 = phi i8* [ %18, %13 ], [ %0, %11 ]
%16 = call i32 @MD5_Update(i32* %3, i8* %15, i32 512)
%17 = add nsw i32 %14, -512
%18 = getelementptr inbounds i8, i8* %15, i64 512
%19 = icmp ugt i32 %17, 512
br i1 %19, label %13, label %20
20: ; preds = %13, %11
%21 = phi i8* [ %0, %11 ], [ %18, %13 ]
%22 = phi i32 [ %1, %11 ], [ %17, %13 ]
%23 = call i32 @MD5_Update(i32* %3, i8* %21, i32 %22)
br label %24
24: ; preds = %20, %2
%25 = call i32 @MD5_Final(i8* %6, i32* %3)
%26 = load i8, i8* %6
%27 = zext i8 %26 to i32
%28 = call i32 @snprintf(i8* %8, i32 32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %27)
%29 = getelementptr inbounds i8, i8* %8, i64 2
%30 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 1
%31 = load i8, i8* %30
%32 = zext i8 %31 to i32
%33 = call i32 @snprintf(i8* %29, i32 32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %32)
%34 = getelementptr inbounds i8, i8* %8, i64 4
%35 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 2
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = call i32 @snprintf(i8* %34, i32 32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %37)
%39 = getelementptr inbounds i8, i8* %8, i64 6
%40 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 3
%41 = load i8, i8* %40
%42 = zext i8 %41 to i32
%43 = call i32 @snprintf(i8* %39, i32 32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %42)
%44 = getelementptr inbounds i8, i8* %8, i64 8
%45 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 4
%46 = load i8, i8* %45
%47 = zext i8 %46 to i32
%48 = call i32 @snprintf(i8* %44, i32 32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %47)
%49 = getelementptr inbounds i8, i8* %8, i64 10
%50 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 5
%51 = load i8, i8* %50
%52 = zext i8 %51 to i32
%53 = call i32 @snprintf(i8* %49, i32 32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %52)
%54 = getelementptr inbounds i8, i8* %8, i64 12
%55 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 6
%56 = load i8, i8* %55
%57 = zext i8 %56 to i32
%58 = call i32 @snprintf(i8* %54, i32 32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %57)
%59 = getelementptr inbounds i8, i8* %8, i64 14
%60 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 7
%61 = load i8, i8* %60
%62 = zext i8 %61 to i32
%63 = call i32 @snprintf(i8* %59, i32 32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %62)
%64 = getelementptr inbounds i8, i8* %8, i64 16
%65 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 8
%66 = load i8, i8* %65
%67 = zext i8 %66 to i32
%68 = call i32 @snprintf(i8* %64, i32 32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %67)
%69 = getelementptr inbounds i8, i8* %8, i64 18
%70 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 9
%71 = load i8, i8* %70
%72 = zext i8 %71 to i32
%73 = call i32 @snprintf(i8* %69, i32 32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %72)
%74 = getelementptr inbounds i8, i8* %8, i64 20
%75 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 10
%76 = load i8, i8* %75
%77 = zext i8 %76 to i32
%78 = call i32 @snprintf(i8* %74, i32 32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %77)
%79 = getelementptr inbounds i8, i8* %8, i64 22
%80 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 11
%81 = load i8, i8* %80
%82 = zext i8 %81 to i32
%83 = call i32 @snprintf(i8* %79, i32 32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %82)
%84 = getelementptr inbounds i8, i8* %8, i64 24
%85 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 12
%86 = load i8, i8* %85
%87 = zext i8 %86 to i32
%88 = call i32 @snprintf(i8* %84, i32 32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %87)
%89 = getelementptr inbounds i8, i8* %8, i64 26
%90 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 13
%91 = load i8, i8* %90
%92 = zext i8 %91 to i32
%93 = call i32 @snprintf(i8* %89, i32 32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %92)
%94 = getelementptr inbounds i8, i8* %8, i64 28
%95 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 14
%96 = load i8, i8* %95
%97 = zext i8 %96 to i32
%98 = call i32 @snprintf(i8* %94, i32 32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %97)
%99 = getelementptr inbounds i8, i8* %8, i64 30
%100 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 15
%101 = load i8, i8* %100
%102 = zext i8 %101 to i32
%103 = call i32 @snprintf(i8* %99, i32 32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %102)
ret i8* %8
}