#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 MD5_DIGEST_LENGTH;
int /*<<< orphan*/ MD5_Final(unsigned char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ MD5_Init(int /*<<< orphan*/ *);
int /*<<< orphan*/ MD5_Update(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
scalar_t__ malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char);
int /*<<< orphan*/ strlen(char *);
char *md5sum_str(char *input) {
  if (input != NULL) {
    MD5_CTX md5_ctxt;
    MD5_Init(&md5_ctxt);
    MD5_Update(&md5_ctxt, input, strlen(input));
    unsigned char md5sum_bytes[MD5_DIGEST_LENGTH];
    MD5_Final(md5sum_bytes, &md5_ctxt);
    char *md5sum = (char *)malloc(33);
    for (int i = 0; i < MD5_DIGEST_LENGTH; i++) {
      sprintf(md5sum + (i * 2), "%02x", md5sum_bytes[i]);
    }
    return md5sum;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<md5sum_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1246 <md5sum_str+0xe6>
lea    -0x14(%rbp),%rdi
mov    %rdi,-0x50(%rbp)
call   1060 <MD5_Init@plt>
mov    -0x10(%rbp),%rdi
mov    %rdi,-0x48(%rbp)
call   1040 <strlen@plt>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
call   1080 <MD5_Update@plt>
mov    0x2e39(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x40(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
lea    -0x14(%rbp),%rsi
call   1030 <MD5_Final@plt>
mov    $0x21,%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    0x2dec(%rip),%rcx
cmp    (%rcx),%eax
jge    1232 <md5sum_str+0xd2>
mov    -0x40(%rbp),%rax
mov    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
add    %rcx,%rdi
movslq -0x34(%rbp),%rcx
lea    0xde5(%rip),%rsi
movzbl (%rax,%rcx,1),%edx
call   1070 <sprintf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11ea <md5sum_str+0x8a>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
jmp    124e <md5sum_str+0xee>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<md5sum_str>:
test   %rdi,%rdi
je     1228 <md5sum_str+0xc8>
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
lea    -0x3c(%rbp),%r14
mov    %r14,%rdi
call   1060 <MD5_Init@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1080 <MD5_Update@plt>
mov    %rsp,-0x38(%rbp)
mov    0x2e37(%rip),%r13
mov    0x0(%r13),%eax
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    %r12,%rdi
mov    %r14,%rsi
call   1030 <MD5_Final@plt>
mov    $0x21,%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpl   $0x0,0x0(%r13)
jle    1211 <md5sum_str+0xb1>
xor    %r14d,%r14d
lea    0xe18(%rip),%r15
mov    -0x30(%rbp),%rbx
nopl   0x0(%rax)
movzbl (%r12,%r14,1),%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <sprintf@plt>
add    $0x1,%r14
movslq 0x0(%r13),%rax
add    $0x2,%rbx
cmp    %rax,%r14
jl     11f0 <md5sum_str+0x90>
mov    -0x38(%rbp),%rsp
mov    -0x30(%rbp),%rax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
ret

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

LLVM IR (-O2):
@MD5_DIGEST_LENGTH = global i32 0
@.str = [5 x i8] c"%02x\00"
define i8* @md5sum_str(i8* %0) {
%2 = alloca i32
%3 = icmp eq i8* %0, null
br i1 %3, label %30, label %4
4: ; preds = %1
%5 = bitcast i32* %2 to i8*
%6 = call i32 @MD5_Init(i32* %2)
%7 = call i32 @strlen(i8* %0)
%8 = call i32 @MD5_Update(i32* %2, i8* %0, i32 %7)
%9 = load i32, i32* @MD5_DIGEST_LENGTH
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
%12 = alloca i8, i64 %10
%13 = call i32 @MD5_Final(i8* %12, i32* %2)
%14 = call i64 @malloc(i32 33)
%15 = inttoptr i64 %14 to i8*
%16 = load i32, i32* @MD5_DIGEST_LENGTH
%17 = icmp sgt i32 %16, 0
br i1 %17, label %19, label %18
18: ; preds = %19, %4
br label %30
19: ; preds = %4, %19
%20 = phi i64 [ %26, %19 ], [ 0, %4 ]
%21 = shl nuw nsw i64 %20, 1
%22 = getelementptr inbounds i8, i8* %15, i64 %21
%23 = getelementptr inbounds i8, i8* %12, i64 %20
%24 = load i8, i8* %23
%25 = call i32 @sprintf(i8* dereferenceable(1) %22, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %24)
%26 = add nuw nsw i64 %20, 1
%27 = load i32, i32* @MD5_DIGEST_LENGTH
%28 = sext i32 %27 to i64
%29 = icmp slt i64 %26, %28
br i1 %29, label %19, label %18
30: ; preds = %1, %18
%31 = phi i8* [ %15, %18 ], [ null, %1 ]
ret i8* %31
}